mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
remove superfluous error checks, use simplejson to write sources
This commit is contained in:
parent
472eb4581a
commit
fd212883b6
1 changed files with 5 additions and 9 deletions
14
anki/sync.py
14
anki/sync.py
|
@ -708,14 +708,7 @@ where media.id in %s""" % sids, now=time.time())
|
||||||
srcID = self.server.deckName
|
srcID = self.server.deckName
|
||||||
(lastSync, syncPeriod) = self.deck.s.first(
|
(lastSync, syncPeriod) = self.deck.s.first(
|
||||||
"select lastSync, syncPeriod from sources where id = :id", id=srcID)
|
"select lastSync, syncPeriod from sources where id = :id", id=srcID)
|
||||||
if syncPeriod == -1:
|
|
||||||
print "syncing disabled"
|
|
||||||
return
|
|
||||||
if syncPeriod != 0 and lastSync + syncPeriod > time.time():
|
|
||||||
print "no need to check - period not expired"
|
|
||||||
return
|
|
||||||
if self.server.modified() <= lastSync:
|
if self.server.modified() <= lastSync:
|
||||||
print "no need to check - server not modified"
|
|
||||||
return
|
return
|
||||||
self.lastSync = lastSync
|
self.lastSync = lastSync
|
||||||
return True
|
return True
|
||||||
|
@ -723,7 +716,6 @@ where media.id in %s""" % sids, now=time.time())
|
||||||
def genOneWayPayload(self, lastSync):
|
def genOneWayPayload(self, lastSync):
|
||||||
"Bundle all added or changed objects since the last sync."
|
"Bundle all added or changed objects since the last sync."
|
||||||
p = {}
|
p = {}
|
||||||
print "l", `lastSync`
|
|
||||||
# facts
|
# facts
|
||||||
factIds = self.deck.s.column0(
|
factIds = self.deck.s.column0(
|
||||||
"select id from facts where modified > :l", l=lastSync)
|
"select id from facts where modified > :l", l=lastSync)
|
||||||
|
@ -750,6 +742,10 @@ where media.id in %s""" % sids, now=time.time())
|
||||||
self.updateObjsFromKey(payload[key], key)
|
self.updateObjsFromKey(payload[key], key)
|
||||||
# cards last, handled differently
|
# cards last, handled differently
|
||||||
self.updateOneWayCards(payload['cards'])
|
self.updateOneWayCards(payload['cards'])
|
||||||
|
# update sync time
|
||||||
|
self.deck.s.statement(
|
||||||
|
"update sources set lastSync = :t where id = :id",
|
||||||
|
id=self.server.deckName, t=time.time())
|
||||||
|
|
||||||
def getOneWayCards(self, ids):
|
def getOneWayCards(self, ids):
|
||||||
"The minimum information necessary to generate one way cards."
|
"The minimum information necessary to generate one way cards."
|
||||||
|
@ -870,7 +866,7 @@ class HttpSyncServerProxy(SyncServer):
|
||||||
d = self.runCmd("getDecks",
|
d = self.runCmd("getDecks",
|
||||||
libanki=anki.version,
|
libanki=anki.version,
|
||||||
client=clientVersion,
|
client=clientVersion,
|
||||||
sources=self.sourcesToCheck)
|
sources=simplejson.dumps(self.sourcesToCheck))
|
||||||
if d['status'] != "OK":
|
if d['status'] != "OK":
|
||||||
raise SyncError(type="authFailed", status=d['status'])
|
raise SyncError(type="authFailed", status=d['status'])
|
||||||
self._mediaSupported = d['mediaSupported']
|
self._mediaSupported = d['mediaSupported']
|
||||||
|
|
Loading…
Reference in a new issue