From c398ccdb891163014f99b1adb0e7c5e6c2643f66 Mon Sep 17 00:00:00 2001 From: jdoe0 Date: Thu, 3 Nov 2016 21:44:40 +0700 Subject: [PATCH] Apply @ndl's patches The patches fix the issue where syncing across different profiles will always trigger a full sync if there's any change in either of the profiles. --- .gitmodules | 3 +++ README.md | 15 ++------------ anki-bundled | 1 + ankisyncd/collection.py | 4 ++-- ankisyncd/sync_app.py | 2 ++ libanki.patch | 46 +++++++++++++++++++++++++++++++++++++++++ patch_libanki.sh | 3 +++ 7 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 .gitmodules create mode 160000 anki-bundled create mode 100644 libanki.patch create mode 100755 patch_libanki.sh diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cc57eb1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "anki-bundled"] + path = anki-bundled + url = https://github.com/dae/anki.git diff --git a/README.md b/README.md index bfd1122..560cba5 100644 --- a/README.md +++ b/README.md @@ -23,20 +23,9 @@ install some of the dependencies we need there: $ virtualenv ankisyncd.env $ ankisyncd.env/bin/easy_install webob simplejson eventlet -3. Download and install libanki. You can find the latest release of Anki here: +3. Patch the bundled libanki: - http://code.google.com/p/anki/downloads/list - - Look for a *.tgz file with a Summary of "Anki Source". At the time of this - writing that is anki-2.0.11.tgz. - - Download this file and extract. - - Then either: - - a. Run ```make install```, or - - b. Copy the entire directory to /usr/share/anki + $ ./patch_libanki.sh 4. Copy the example.ini to production.ini and edit for your needs. Warning: If you disable SSL, login credentials will be transported in plain text! diff --git a/anki-bundled b/anki-bundled new file mode 160000 index 0000000..499b022 --- /dev/null +++ b/anki-bundled @@ -0,0 +1 @@ +Subproject commit 499b02281b4ab2bea3c4167128f02cc3d9cf973b diff --git a/ankisyncd/collection.py b/ankisyncd/collection.py index c8d2a29..d73c2a1 100644 --- a/ankisyncd/collection.py +++ b/ankisyncd/collection.py @@ -59,7 +59,7 @@ class CollectionWrapper(object): else: raise - col = anki.storage.Collection(self.path) + col = anki.storage.Collection(self.path, server=True) # Do any special setup if self.setup_new_collection is not None: @@ -71,7 +71,7 @@ class CollectionWrapper(object): """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) + self.__col = anki.storage.Collection(self.path, server=True) else: self.__col = self.__create_collection() diff --git a/ankisyncd/sync_app.py b/ankisyncd/sync_app.py index 0440fb9..e27ae71 100644 --- a/ankisyncd/sync_app.py +++ b/ankisyncd/sync_app.py @@ -425,6 +425,7 @@ class SyncApp(object): fd.write(data) finally: col.reopen() + col.load() # run hook_upload if one is defined if self.hook_upload is not None: @@ -442,6 +443,7 @@ class SyncApp(object): data = open(session.get_collection_path(), 'rb').read() finally: col.reopen() + col.load() return data @wsgify diff --git a/libanki.patch b/libanki.patch new file mode 100644 index 0000000..30aad6d --- /dev/null +++ b/libanki.patch @@ -0,0 +1,46 @@ +diff -urN anki/collection.py anki/collection.py +--- anki/collection.py 2016-10-22 00:04:43.365953912 +0200 ++++ anki/collection.py 2016-10-23 10:46:26.171300370 +0200 +@@ -60,7 +60,7 @@ + self.server = server + self._lastSave = time.time() + self.clearUndo() +- self.media = MediaManager(self, server) ++ self.media = MediaManager(self) + self.models = ModelManager(self) + self.decks = DeckManager(self) + self.tags = TagManager(self) +diff -urN anki/media.py anki/media.py +--- anki/media.py 2016-10-22 00:04:43.367953863 +0200 ++++ anki/media.py 2016-10-23 10:46:16.947524341 +0200 +@@ -26,11 +26,8 @@ + ] + regexps = soundRegexps + imgRegexps + +- def __init__(self, col, server): ++ def __init__(self, col): + self.col = col +- if server: +- self._dir = None +- return + # media directory + self._dir = re.sub("(?i)\.(anki2)$", ".media", self.col.path) + # convert dir to unicode if it's not already +@@ -51,8 +48,6 @@ + self.connect() + + def connect(self): +- if self.col.server: +- return + path = self.dir()+".db2" + create = not os.path.exists(path) + os.chdir(self._dir) +@@ -103,8 +98,6 @@ + os.rename("../collection.media.db", npath) + + def close(self): +- if self.col.server: +- return + self.db.close() + self.db = None + # change cwd back to old location diff --git a/patch_libanki.sh b/patch_libanki.sh new file mode 100755 index 0000000..c42db38 --- /dev/null +++ b/patch_libanki.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd "$(dirname ${BASH_SOURCE[0]})/anki-bundled" +patch -p0 < ../libanki.patch