mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 07:07:13 -05:00
compress zip, add media sanity check
This commit is contained in:
parent
fabec6e920
commit
9b76a4669c
2 changed files with 23 additions and 1 deletions
|
|
@ -259,7 +259,7 @@ If the same name exists, compare checksums."""
|
|||
def zipAdded(self):
|
||||
"Add files to a zip until over SYNC_ZIP_SIZE. Return zip data."
|
||||
f = StringIO()
|
||||
z = zipfile.ZipFile(f, "w")
|
||||
z = zipfile.ZipFile(f, "w", compression=zipfile.ZIP_DEFLATED)
|
||||
sz = 0
|
||||
cnt = 0
|
||||
files = {}
|
||||
|
|
@ -382,3 +382,8 @@ create table log (fname text primary key, type int);
|
|||
if not v[2]:
|
||||
removed.append(k)
|
||||
return added, removed
|
||||
|
||||
def sanityCheck(self):
|
||||
assert not self.db.scalar("select count() from log")
|
||||
cnt = self.db.scalar("select count() from media")
|
||||
return cnt
|
||||
|
|
|
|||
17
anki/sync.py
17
anki/sync.py
|
|
@ -577,6 +577,15 @@ class MediaSyncer(object):
|
|||
# after server has replied, safe to remove from log
|
||||
self.col.media.forgetAdded(fnames)
|
||||
self.col.media.setUsn(usn)
|
||||
# step 5: sanity check during beta testing
|
||||
# NOTE: when removing this, need to move server tidyup
|
||||
# back from sanity check to addFiles
|
||||
s = self.server.mediaSanity()
|
||||
c = self.mediaSanity()
|
||||
if c != s:
|
||||
raise Exception("""\
|
||||
Sanity check failed. Please copy and paste the text below:\n%s\n%s""" %
|
||||
(c, s))
|
||||
return "success"
|
||||
|
||||
def removed(self):
|
||||
|
|
@ -595,6 +604,9 @@ class MediaSyncer(object):
|
|||
"True if zip is the last in set. Server returns new usn instead."
|
||||
return self.col.media.syncAdd(zip)
|
||||
|
||||
def mediaSanity(self):
|
||||
return self.col.media.sanityCheck()
|
||||
|
||||
# Remote media syncing
|
||||
##########################################################################
|
||||
|
||||
|
|
@ -615,10 +627,15 @@ class RemoteMediaServer(MediaSyncer, HttpSyncer):
|
|||
self.con, "files", StringIO(simplejson.dumps(kw)), self._vars())
|
||||
|
||||
def addFiles(self, zip):
|
||||
# no compression, as we compress the zip file instead
|
||||
return simplejson.loads(
|
||||
self.postData(self.con, "addFiles", StringIO(zip),
|
||||
self._vars(), comp=0))
|
||||
|
||||
def mediaSanity(self):
|
||||
return simplejson.loads(
|
||||
self.postData(self.con, "mediaSanity", None, self._vars()))
|
||||
|
||||
# only for unit tests
|
||||
def mediatest(self, n):
|
||||
return simplejson.loads(
|
||||
|
|
|
|||
Loading…
Reference in a new issue