mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
force backups to be treated as a replace
This commit is contained in:
parent
c64f5130e2
commit
418acb3365
2 changed files with 17 additions and 12 deletions
|
@ -316,16 +316,20 @@ Unable to import from a read-only file."""))
|
||||||
|
|
||||||
def setupApkgImport(mw, importer):
|
def setupApkgImport(mw, importer):
|
||||||
meta = None
|
meta = None
|
||||||
|
forceFull = False
|
||||||
try:
|
try:
|
||||||
z = zipfile.ZipFile(importer.file)
|
z = zipfile.ZipFile(importer.file)
|
||||||
meta = json.load(z.open("meta"))
|
meta = json.load(z.open("meta"))
|
||||||
if not meta['full']:
|
if not meta['full']:
|
||||||
# add
|
# add
|
||||||
return True
|
return True
|
||||||
|
elif meta['full'] == "force":
|
||||||
|
forceFull = True
|
||||||
except:
|
except:
|
||||||
# no meta attribute on broken file
|
# no meta attribute on broken file
|
||||||
pass
|
pass
|
||||||
# if old file or full collection, we have to prompt user
|
# if old file or full collection, we have to prompt user
|
||||||
|
if not forceFull:
|
||||||
diag = askUserDialog(_("""\
|
diag = askUserDialog(_("""\
|
||||||
Would you like to add to your collection, or replace it?"""),
|
Would you like to add to your collection, or replace it?"""),
|
||||||
[_("Add"),
|
[_("Add"),
|
||||||
|
|
|
@ -10,7 +10,7 @@ from aqt.qt import *
|
||||||
QtConfig = pyqtconfig.Configuration()
|
QtConfig = pyqtconfig.Configuration()
|
||||||
|
|
||||||
from anki import Collection
|
from anki import Collection
|
||||||
from anki.utils import stripHTML, checksum, isWin, isMac, intTime
|
from anki.utils import stripHTML, checksum, isWin, isMac, intTime, json
|
||||||
from anki.hooks import runHook, addHook, remHook
|
from anki.hooks import runHook, addHook, remHook
|
||||||
import anki.consts
|
import anki.consts
|
||||||
|
|
||||||
|
@ -296,6 +296,7 @@ how to restore from a backup.""")
|
||||||
z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED)
|
z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED)
|
||||||
z.write(path, "collection.anki2")
|
z.write(path, "collection.anki2")
|
||||||
z.writestr("media", "{}")
|
z.writestr("media", "{}")
|
||||||
|
z.writestr("meta", json.dumps(dict(full="force")))
|
||||||
z.close()
|
z.close()
|
||||||
# remove if over
|
# remove if over
|
||||||
if len(backups) + 1 > nbacks:
|
if len(backups) + 1 > nbacks:
|
||||||
|
|
Loading…
Reference in a new issue