mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -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 gc
|
||||||
import time
|
import time
|
||||||
import faulthandler
|
import faulthandler
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
from send2trash import send2trash
|
from send2trash import send2trash
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
@ -323,12 +324,23 @@ the manual for information on how to restore from an automatic backup."))
|
||||||
# Backup and auto-optimize
|
# 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):
|
def backup(self):
|
||||||
nbacks = self.pm.profile['numBackups']
|
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):
|
if not nbacks or os.getenv("ANKIDEV", 0):
|
||||||
return
|
return
|
||||||
dir = self.pm.backupFolder()
|
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
|
n = backups[-1][0] + 1
|
||||||
# do backup
|
# do backup
|
||||||
newpath = os.path.join(dir, "backup-%d.apkg" % n)
|
newpath = os.path.join(dir, "backup-%d.apkg" % n)
|
||||||
z = zipfile.ZipFile(newpath, "w", zipStorage)
|
data = open(path, "rb").read()
|
||||||
z.write(path, "collection.anki2")
|
b = self.BackupThread(newpath, data)
|
||||||
z.writestr("media", "{}")
|
b.start()
|
||||||
z.close()
|
|
||||||
# remove if over
|
# remove if over
|
||||||
if len(backups) + 1 > nbacks:
|
if len(backups) + 1 > nbacks:
|
||||||
delete = 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):
|
def setupBackup(self):
|
||||||
self.form.numBackups.setValue(self.prof['numBackups'])
|
self.form.numBackups.setValue(self.prof['numBackups'])
|
||||||
self.form.compressBackups.setChecked(self.prof.get("compressBackups", True))
|
|
||||||
self.form.openBackupFolder.linkActivated.connect(self.onOpenBackup)
|
self.form.openBackupFolder.linkActivated.connect(self.onOpenBackup)
|
||||||
|
|
||||||
def onOpenBackup(self):
|
def onOpenBackup(self):
|
||||||
|
@ -145,18 +144,15 @@ Not currently enabled; click the sync button in the main window to enable."""))
|
||||||
|
|
||||||
def updateBackup(self):
|
def updateBackup(self):
|
||||||
self.prof['numBackups'] = self.form.numBackups.value()
|
self.prof['numBackups'] = self.form.numBackups.value()
|
||||||
self.prof['compressBackups'] = self.form.compressBackups.isChecked()
|
|
||||||
|
|
||||||
# Basic & Advanced Options
|
# Basic & Advanced Options
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def setupOptions(self):
|
def setupOptions(self):
|
||||||
self.form.stripHTML.setChecked(self.prof['stripHTML'])
|
|
||||||
self.form.pastePNG.setChecked(self.prof.get("pastePNG", False))
|
self.form.pastePNG.setChecked(self.prof.get("pastePNG", False))
|
||||||
self.form.profilePass.clicked.connect(self.onProfilePass)
|
self.form.profilePass.clicked.connect(self.onProfilePass)
|
||||||
|
|
||||||
def updateOptions(self):
|
def updateOptions(self):
|
||||||
self.prof['stripHTML'] = self.form.stripHTML.isChecked()
|
|
||||||
self.prof['pastePNG'] = self.form.pastePNG.isChecked()
|
self.prof['pastePNG'] = self.form.pastePNG.isChecked()
|
||||||
|
|
||||||
def onProfilePass(self):
|
def onProfilePass(self):
|
||||||
|
|
|
@ -65,13 +65,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="stripHTML">
|
|
||||||
<property name="text">
|
|
||||||
<string>Strip HTML when pasting text</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="pastePNG">
|
<widget class="QCheckBox" name="pastePNG">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -370,13 +363,6 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="compressBackups">
|
|
||||||
<property name="text">
|
|
||||||
<string>Compress backups (slower)</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="openBackupFolder">
|
<widget class="QLabel" name="openBackupFolder">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -437,7 +423,6 @@
|
||||||
<tabstop>lang</tabstop>
|
<tabstop>lang</tabstop>
|
||||||
<tabstop>showEstimates</tabstop>
|
<tabstop>showEstimates</tabstop>
|
||||||
<tabstop>showProgress</tabstop>
|
<tabstop>showProgress</tabstop>
|
||||||
<tabstop>stripHTML</tabstop>
|
|
||||||
<tabstop>pastePNG</tabstop>
|
<tabstop>pastePNG</tabstop>
|
||||||
<tabstop>useCurrent</tabstop>
|
<tabstop>useCurrent</tabstop>
|
||||||
<tabstop>newSpread</tabstop>
|
<tabstop>newSpread</tabstop>
|
||||||
|
@ -452,7 +437,6 @@
|
||||||
<tabstop>buttonBox</tabstop>
|
<tabstop>buttonBox</tabstop>
|
||||||
<tabstop>tabWidget</tabstop>
|
<tabstop>tabWidget</tabstop>
|
||||||
<tabstop>fullSync</tabstop>
|
<tabstop>fullSync</tabstop>
|
||||||
<tabstop>compressBackups</tabstop>
|
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
|
|
Loading…
Reference in a new issue