mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -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)
|
||||
base = self.addonsFolder(sid)
|
||||
if os.path.exists(base):
|
||||
self.backupUserFiles(sid)
|
||||
self.deleteAddon(sid)
|
||||
|
||||
# extract
|
||||
os.mkdir(base)
|
||||
self.restoreUserFiles(sid)
|
||||
|
||||
# extract
|
||||
for n in z.namelist():
|
||||
if n.endswith("/"):
|
||||
# folder; ignore
|
||||
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)
|
||||
|
||||
# update metadata
|
||||
|
@ -238,6 +245,28 @@ When loading '%(name)s':
|
|||
meta['config'] = conf
|
||||
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
|
||||
######################################################################
|
||||
|
||||
|
|
Loading…
Reference in a new issue