mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
preserve user_files folder in add-ons
This commit is contained in:
parent
0bc4a1a220
commit
5deb75f5c4
1 changed files with 31 additions and 2 deletions
|
@ -108,15 +108,22 @@ When loading '%(name)s':
|
||||||
meta = self.addonMeta(sid)
|
meta = self.addonMeta(sid)
|
||||||
base = self.addonsFolder(sid)
|
base = self.addonsFolder(sid)
|
||||||
if os.path.exists(base):
|
if os.path.exists(base):
|
||||||
|
self.backupUserFiles(sid)
|
||||||
self.deleteAddon(sid)
|
self.deleteAddon(sid)
|
||||||
|
|
||||||
# extract
|
|
||||||
os.mkdir(base)
|
os.mkdir(base)
|
||||||
|
self.restoreUserFiles(sid)
|
||||||
|
|
||||||
|
# extract
|
||||||
for n in z.namelist():
|
for n in z.namelist():
|
||||||
if n.endswith("/"):
|
if n.endswith("/"):
|
||||||
# folder; ignore
|
# folder; ignore
|
||||||
continue
|
continue
|
||||||
# write
|
|
||||||
|
path = os.path.join(base, n)
|
||||||
|
# skip existing user files
|
||||||
|
if os.path.exists(path) and n.startswith("user_files/"):
|
||||||
|
continue
|
||||||
z.extract(n, base)
|
z.extract(n, base)
|
||||||
|
|
||||||
# update metadata
|
# update metadata
|
||||||
|
@ -238,6 +245,28 @@ When loading '%(name)s':
|
||||||
meta['config'] = conf
|
meta['config'] = conf
|
||||||
self.writeAddonMeta(addon, meta)
|
self.writeAddonMeta(addon, meta)
|
||||||
|
|
||||||
|
# user_files
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
def _userFilesPath(self, sid):
|
||||||
|
return os.path.join(self.addonsFolder(sid), "user_files")
|
||||||
|
|
||||||
|
def _userFilesBackupPath(self):
|
||||||
|
return os.path.join(self.addonsFolder(), "files_backup")
|
||||||
|
|
||||||
|
def backupUserFiles(self, sid):
|
||||||
|
p = self._userFilesPath(sid)
|
||||||
|
if os.path.exists(p):
|
||||||
|
os.rename(p, self._userFilesBackupPath())
|
||||||
|
|
||||||
|
def restoreUserFiles(self, sid):
|
||||||
|
p = self._userFilesPath(sid)
|
||||||
|
bp = self._userFilesBackupPath()
|
||||||
|
# did we back up userFiles?
|
||||||
|
if not os.path.exists(bp):
|
||||||
|
return
|
||||||
|
os.rename(bp, p)
|
||||||
|
|
||||||
# Add-ons Dialog
|
# Add-ons Dialog
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue