diff --git a/aqt/main.py b/aqt/main.py index 67e231280..384f7fa3e 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -8,6 +8,7 @@ import zipfile import gc import time import faulthandler +from threading import Thread from send2trash import send2trash from aqt.qt import * @@ -323,12 +324,23 @@ the manual for information on how to restore from an automatic backup.")) # Backup and auto-optimize ########################################################################## + class BackupThread(Thread): + def __init__(self, path, data): + Thread.__init__(self) + self.path = path + self.data = data + # create the file in calling thread to ensure the same + # file is not created twice + open(self.path, "wb").close() + + def run(self): + z = zipfile.ZipFile(self.path, "w", zipfile.ZIP_DEFLATED) + z.writestr("collection.anki2", self.data) + z.writestr("media", "{}") + z.close() + def backup(self): nbacks = self.pm.profile['numBackups'] - if self.pm.profile.get('compressBackups', True): - zipStorage = zipfile.ZIP_DEFLATED - else: - zipStorage = zipfile.ZIP_STORED if not nbacks or os.getenv("ANKIDEV", 0): return dir = self.pm.backupFolder() @@ -349,10 +361,9 @@ the manual for information on how to restore from an automatic backup.")) n = backups[-1][0] + 1 # do backup newpath = os.path.join(dir, "backup-%d.apkg" % n) - z = zipfile.ZipFile(newpath, "w", zipStorage) - z.write(path, "collection.anki2") - z.writestr("media", "{}") - z.close() + data = open(path, "rb").read() + b = self.BackupThread(newpath, data) + b.start() # remove if over if len(backups) + 1 > nbacks: delete = len(backups) + 1 - nbacks diff --git a/aqt/preferences.py b/aqt/preferences.py index 90d11a5ec..b79af4a8b 100644 --- a/aqt/preferences.py +++ b/aqt/preferences.py @@ -137,7 +137,6 @@ Not currently enabled; click the sync button in the main window to enable.""")) def setupBackup(self): self.form.numBackups.setValue(self.prof['numBackups']) - self.form.compressBackups.setChecked(self.prof.get("compressBackups", True)) self.form.openBackupFolder.linkActivated.connect(self.onOpenBackup) def onOpenBackup(self): @@ -145,18 +144,15 @@ Not currently enabled; click the sync button in the main window to enable.""")) def updateBackup(self): self.prof['numBackups'] = self.form.numBackups.value() - self.prof['compressBackups'] = self.form.compressBackups.isChecked() # Basic & Advanced Options ###################################################################### def setupOptions(self): - self.form.stripHTML.setChecked(self.prof['stripHTML']) self.form.pastePNG.setChecked(self.prof.get("pastePNG", False)) self.form.profilePass.clicked.connect(self.onProfilePass) def updateOptions(self): - self.prof['stripHTML'] = self.form.stripHTML.isChecked() self.prof['pastePNG'] = self.form.pastePNG.isChecked() def onProfilePass(self): diff --git a/designer/preferences.ui b/designer/preferences.ui index 2fac561b4..682cab961 100644 --- a/designer/preferences.ui +++ b/designer/preferences.ui @@ -65,13 +65,6 @@ - - - - Strip HTML when pasting text - - - @@ -370,13 +363,6 @@ - - - - Compress backups (slower) - - - @@ -437,7 +423,6 @@ lang showEstimates showProgress - stripHTML pastePNG useCurrent newSpread @@ -452,7 +437,6 @@ buttonBox tabWidget fullSync - compressBackups