From f131021c7e3a5de3fae82cebdadf923597ecfcf7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 1 Oct 2011 14:23:41 +0900 Subject: [PATCH] remote partial syncing working; fixed mod time on finish() --- anki/sync.py | 21 ++++++++++++++++++--- tests/test_sync.py | 10 +++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/anki/sync.py b/anki/sync.py index 08557a329..7d6637028 100644 --- a/anki/sync.py +++ b/anki/sync.py @@ -169,7 +169,7 @@ select count() from facts where id not in (select distinct fid from cards)""") def finish(self, mod=None): if not mod: # server side; we decide new mod time - mod = intTime() + mod = intTime(1000) self.deck.ls = mod self.deck._usn = self.maxUsn + 1 self.deck.save(mod=mod) @@ -420,9 +420,21 @@ class RemoteServer(Syncer): self.hkey = cont return cont - def applyChanges(self, **kwargs): + def applyChanges(self, **kw): self.con = httplib2.Http(timeout=60) - return self._run("applyChanges", kwargs) + return self._run("applyChanges", kw) + + def chunk(self, **kw): + return self._run("chunk", kw) + + def applyChunk(self, **kw): + return self._run("applyChunk", kw) + + def sanityCheck(self, **kw): + return self._run("sanityCheck", kw) + + def finish(self, **kw): + return self._run("finish", kw) def _vars(self): return dict(k=self.hkey) @@ -466,9 +478,12 @@ class FullSyncer(object): assert postData(self._con(), "upload", open(self.deck.path, "rb"), self._vars(), comp=6) == "OK" +# Posting data as a file +###################################################################### # We don't want to post the payload as a form var, as the percent-encoding is # costly. We could send it as a raw post, but more HTTP clients seem to # support file uploading, so this is the more compatible choice. + def postData(http, method, fobj, vars, comp=1): bdry = "--"+MIME_BOUNDARY # write out post vars, including session key and compression flag diff --git a/tests/test_sync.py b/tests/test_sync.py index b9bcafbf3..429b8363d 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -299,4 +299,12 @@ def test_remoteSync(): assert client.sync() == "noChanges" # bump local deck client.deck.save() - print client.sync() + assert client.sync() == "success" + # again, no changes + assert client.sync() == "noChanges" + # downloading the remote deck should give us the same mod + lmod = client.deck.mod + f = FullSyncer(client.deck, TEST_HKEY) + f.download() + d = Deck(client.deck.path) + assert d.mod == lmod