diff --git a/ankisyncd/sync_app.py b/ankisyncd/sync_app.py index 0cab094..3920ed2 100644 --- a/ankisyncd/sync_app.py +++ b/ankisyncd/sync_app.py @@ -45,6 +45,34 @@ try: except ImportError: from StringIO import StringIO +def old_client(cv): + if not cv: + return False + + note = {"alpha": 0, "beta": 0} + client, version, platform = cv.split(',') + + for name in note.keys(): + if name in version: + vs = version.split(name) + version = vs[0] + note[name] = int(vs[-1]) + + version_int = [int(x) for x in version.split('.')] + + if client == 'ankidesktop': + return version_int < [2, 0, 27] + elif client == 'ankidroid': + if version_int == [2, 3]: + if note["alpha"]: + return note["alpha"] < 4 + else: + return version_int < [2, 2, 3] + else: # unknown client, assume current version + return False + + + class SyncCollectionHandler(Syncer): operations = ['meta', 'applyChanges', 'start', 'chunk', 'applyChunk', 'sanityCheck2', 'finish'] @@ -52,33 +80,6 @@ class SyncCollectionHandler(Syncer): # So that 'server' (the 3rd argument) can't get set Syncer.__init__(self, col) - @staticmethod - def _old_client(cv): - if not cv: - return False - - note = {"alpha": 0, "beta": 0} - client, version, platform = cv.split(',') - - for name in note.keys(): - if name in version: - vs = version.split(name) - version = vs[0] - note[name] = int(vs[-1]) - - version_int = [int(x) for x in version.split('.')] - - if client == 'ankidesktop': - return version_int < [2, 0, 27] - elif client == 'ankidroid': - if version_int == [2, 3]: - if note["alpha"]: - return note["alpha"] < 4 - else: - return version_int < [2, 2, 3] - else: # unknown client, assume current version - return False - def meta(self): # Make sure the media database is open! if self.col.media.db is None: @@ -527,7 +528,7 @@ class SyncApp(object): session.client_version = data['cv'] del data['cv'] - if self.session.collection_handler._old_client(session.client_version): + if old_client(session.client_version): return Response(status="501") # client needs upgrade self.session_manager.save(hkey, session) diff --git a/tests/test_sync_app.py b/tests/test_sync_app.py index c2257aa..bcb5e8d 100644 --- a/tests/test_sync_app.py +++ b/tests/test_sync_app.py @@ -8,6 +8,7 @@ from ankisyncd.sync_app import SyncCollectionHandler from ankisyncd.sync_app import SyncUserSession from ankisyncd.sync_app import SimpleSessionManager from ankisyncd.sync_app import SqliteSessionManager +from ankisyncd.sync_app import old_client from collection_test_base import CollectionTestBase @@ -45,12 +46,12 @@ class SyncCollectionHandlerTest(CollectionTestBase): ) for cv in old: - if not self.syncCollectionHandler._old_client(cv): - raise AssertionError("_old_client(\"%s\") is False" % cv) + if not old_client(cv): + raise AssertionError("old_client(\"%s\") is False" % cv) for cv in current: - if self.syncCollectionHandler._old_client(cv): - raise AssertionError("_old_client(\"%s\") is True" % cv) + if old_client(cv): + raise AssertionError("old_client(\"%s\") is True" % cv) def test_meta(self): meta = self.syncCollectionHandler.meta()