Remove media patch, put usnLim in server code

Since dae/anki@d6874de8, usnLim always returns -1 regardless of the
`server` attribute.

Reference: d6874de8c8
This commit is contained in:
flan 2018-08-20 15:44:10 +02:00
parent c4fad436c1
commit a83e68412d
3 changed files with 5 additions and 31 deletions

View File

@ -1,34 +1,5 @@
import functools
import os
import sys
def __mediapatch():
"""
Monkey-patch Anki's MediaManager to ignore the "server" attribute.
It's needed because MediaManager's __init__(), connect() and close() are
close to no-ops when self.col.server is True. If self.col.server is False,
Syncer.usnLim() doesn't match entities that are supposed to be sent to the
client, thus breaking serverclient deck sync.
"""
def noserver(f):
@functools.wraps(f)
def wrapped(self, *args, **kwargs):
orig = self.col.server
self.col.server = False
ret = f(self, *args, **kwargs)
self.col.server = orig
return ret
return wrapped
from anki.media import MediaManager
orig_init = MediaManager.__init__
MediaManager.__init__ = functools.wraps(MediaManager.__init__)(lambda self, col, _: orig_init(self, col, False))
MediaManager.connect = noserver(MediaManager.connect)
MediaManager.close = noserver(MediaManager.close)
sys.path.insert(0, "/usr/share/anki")
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), "anki-bundled"))
__mediapatch()

View File

@ -49,7 +49,7 @@ class CollectionWrapper:
# mkdir -p the path, because it might not exist
os.makedirs(os.path.dirname(self.path), exist_ok=True)
col = anki.storage.Collection(self.path, server=True)
col = anki.storage.Collection(self.path)
# Do any special setup
if self.setup_new_collection is not None:
@ -61,7 +61,7 @@ class CollectionWrapper:
"""Open the collection, or create it if it doesn't exist."""
if self.__col is None:
if os.path.exists(self.path):
self.__col = anki.storage.Collection(self.path, server=True)
self.__col = anki.storage.Collection(self.path)
else:
self.__col = self.__create_collection()

View File

@ -91,6 +91,9 @@ class SyncCollectionHandler(anki.sync.Syncer):
'cont': True,
}
def usnLim(self):
return "usn >= %d" % self.minUsn
class SyncMediaHandler(anki.sync.MediaSyncer):
operations = ['begin', 'mediaChanges', 'mediaSanity', 'uploadChanges', 'downloadFiles']