Move old_client() outside classes
This commit is contained in:
parent
a7e29c56f4
commit
cb18fcb04a
@ -45,6 +45,34 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from StringIO import StringIO
|
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):
|
class SyncCollectionHandler(Syncer):
|
||||||
operations = ['meta', 'applyChanges', 'start', 'chunk', 'applyChunk', 'sanityCheck2', 'finish']
|
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
|
# So that 'server' (the 3rd argument) can't get set
|
||||||
Syncer.__init__(self, col)
|
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):
|
def meta(self):
|
||||||
# Make sure the media database is open!
|
# Make sure the media database is open!
|
||||||
if self.col.media.db is None:
|
if self.col.media.db is None:
|
||||||
@ -527,7 +528,7 @@ class SyncApp(object):
|
|||||||
session.client_version = data['cv']
|
session.client_version = data['cv']
|
||||||
del 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
|
return Response(status="501") # client needs upgrade
|
||||||
|
|
||||||
self.session_manager.save(hkey, session)
|
self.session_manager.save(hkey, session)
|
||||||
|
|||||||
@ -8,6 +8,7 @@ from ankisyncd.sync_app import SyncCollectionHandler
|
|||||||
from ankisyncd.sync_app import SyncUserSession
|
from ankisyncd.sync_app import SyncUserSession
|
||||||
from ankisyncd.sync_app import SimpleSessionManager
|
from ankisyncd.sync_app import SimpleSessionManager
|
||||||
from ankisyncd.sync_app import SqliteSessionManager
|
from ankisyncd.sync_app import SqliteSessionManager
|
||||||
|
from ankisyncd.sync_app import old_client
|
||||||
|
|
||||||
from collection_test_base import CollectionTestBase
|
from collection_test_base import CollectionTestBase
|
||||||
|
|
||||||
@ -45,12 +46,12 @@ class SyncCollectionHandlerTest(CollectionTestBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for cv in old:
|
for cv in old:
|
||||||
if not self.syncCollectionHandler._old_client(cv):
|
if not old_client(cv):
|
||||||
raise AssertionError("_old_client(\"%s\") is False" % cv)
|
raise AssertionError("old_client(\"%s\") is False" % cv)
|
||||||
|
|
||||||
for cv in current:
|
for cv in current:
|
||||||
if self.syncCollectionHandler._old_client(cv):
|
if old_client(cv):
|
||||||
raise AssertionError("_old_client(\"%s\") is True" % cv)
|
raise AssertionError("old_client(\"%s\") is True" % cv)
|
||||||
|
|
||||||
def test_meta(self):
|
def test_meta(self):
|
||||||
meta = self.syncCollectionHandler.meta()
|
meta = self.syncCollectionHandler.meta()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user