diff --git a/ankisyncd/__init__.py b/ankisyncd/__init__.py index 12987ec..0e9c2be 100644 --- a/ankisyncd/__init__.py +++ b/ankisyncd/__init__.py @@ -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 server→client 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() diff --git a/ankisyncd/collection.py b/ankisyncd/collection.py index 8ea3957..19b8a8e 100644 --- a/ankisyncd/collection.py +++ b/ankisyncd/collection.py @@ -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() diff --git a/ankisyncd/sync_app.py b/ankisyncd/sync_app.py index 4e8d53e..66ada43 100644 --- a/ankisyncd/sync_app.py +++ b/ankisyncd/sync_app.py @@ -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']