mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
write backups in thread; remove strip html & compress options
we do the backup compression/writing in a separate thread so it doesn't slow down profile switching/syncing, and remove the option to write uncompressed backups the strip html option is no longer used, so remove it from preferences
This commit is contained in:
parent
f6245cdfd1
commit
259023f369
3 changed files with 19 additions and 28 deletions
27
aqt/main.py
27
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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -65,13 +65,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="stripHTML">
|
||||
<property name="text">
|
||||
<string>Strip HTML when pasting text</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="pastePNG">
|
||||
<property name="text">
|
||||
|
@ -370,13 +363,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="compressBackups">
|
||||
<property name="text">
|
||||
<string>Compress backups (slower)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="openBackupFolder">
|
||||
<property name="text">
|
||||
|
@ -437,7 +423,6 @@
|
|||
<tabstop>lang</tabstop>
|
||||
<tabstop>showEstimates</tabstop>
|
||||
<tabstop>showProgress</tabstop>
|
||||
<tabstop>stripHTML</tabstop>
|
||||
<tabstop>pastePNG</tabstop>
|
||||
<tabstop>useCurrent</tabstop>
|
||||
<tabstop>newSpread</tabstop>
|
||||
|
@ -452,7 +437,6 @@
|
|||
<tabstop>buttonBox</tabstop>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>fullSync</tabstop>
|
||||
<tabstop>compressBackups</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
|
Loading…
Reference in a new issue