Пример #1
0
 def _fullSync(self):
     # tell the calling thread we need a decision on sync direction, and
     # wait for a reply
     self.fullSyncChoice = False
     self.localIsEmpty = self.col.isEmpty()
     self.fireEvent("fullSync")
     while not self.fullSyncChoice:
         time.sleep(0.1)
     f = self.fullSyncChoice
     if f == "cancel":
         return
     self.client = FullSyncer(self.col,
                              self.hkey,
                              self.server.client,
                              hostNum=self.hostNum)
     try:
         if f == "upload":
             if not self.client.upload():
                 self.fireEvent("upbad")
         else:
             self.client.download()
     except Exception as e:
         if "sync cancelled" in str(e):
             return
         raise
     # reopen db and move on to media sync
     self.col.reopen()
     self._syncMedia()
Пример #2
0
def test_download():
    if not TEST_REMOTE:
        return
    f = FullSyncer(ts.client.col, "abc", ts.server.con)
    assertException(Exception, f.download)
    f.hkey = TEST_HKEY
    f.download()
Пример #3
0
def sync_collection(username, password, full_sync="upload"):
    from anki.sync import Syncer, RemoteServer, FullSyncer, MediaSyncer, RemoteMediaServer

    collection = open_or_create_collection(username)

    server = RemoteServer(None)
    app.logger.info("u: %s,pass: %s" % (username, password))
    hkey = server.hostKey(username, password)
    syncer = Syncer(collection, server)
    ret = syncer.sync()
    app.logger.info("syncer return: %s" % ret)

    if (ret == "fullSync"):
        # app.logger.info("trying to do fullSync - upload - Not tested")
        client = FullSyncer(collection, hkey, server.client)
        if full_sync == "download":
            client.download()
        else:
            client.upload()

    if ret not in ("noChanges", "fullSync", "success"):
        collection.close()
        return False

    mediaserver = RemoteMediaServer(collection, hkey, server.client)
    mediaclient = MediaSyncer(collection, mediaserver)
    mediaret = mediaclient.sync()
    app.logger.info("mediasync returned: %s" % mediaret)
    collection.save()
    collection.close()

    return True
Пример #4
0
 def sync_server(self):
     server = RemoteServer(self.profile['syncKey'], self.profile['hostNum'])
     client = Syncer(self.col, server)
     res = client.sync()
     if res in ['success', 'noChanges']:
         pass
     elif res == 'fullSync':
         print('FULL SYNC')
         client = FullSyncer(self.col, self.profile['syncKey'],
                             server.client, self.profile['hostNum'])
         client.download()
         self.col.reopen()
Пример #5
0
def test_remoteSync():
    if not TEST_REMOTE:
        return
    # not yet associated, so will require a full sync
    assert ts.client.sync() == "fullSync"
    # upload
    f = FullSyncer(ts.client.col, TEST_HKEY, ts.server.con)
    f.upload()
    ts.client.col.reopen()
    # should report no changes
    assert ts.client.sync() == "noChanges"
    # bump local col
    ts.client.col.setMod()
    ts.client.col.save()
    assert ts.client.sync() == "success"
    # again, no changes
    assert ts.client.sync() == "noChanges"
    # downloading the remote col should give us the same mod
    lmod = ts.client.col.mod
    f = FullSyncer(ts.client.col, TEST_HKEY, ts.server.con)
    f.download()
    d = aopen(ts.client.col.path)
    assert d.mod == lmod
Пример #6
0
def _sync_anki(col_path, anki_hkey):
    try:
        col = Collection(col_path)

        server = RemoteServer(anki_hkey)
        client = FullSyncer(col, anki_hkey, server.client)
        client.download()
        col = Collection(col_path) # reload collection

        media_server = RemoteMediaServer(col, anki_hkey, server.client)
        media_client = MediaSyncer(col, media_server)
        media_client.sync()
        col.close(save=True)
    except:
        return traceback.format_exc()
Пример #7
0
def test_remoteSync():
    if not TEST_REMOTE:
        return
    # not yet associated, so will require a full sync
    assert ts.client.sync() == "fullSync"
    # upload
    f = FullSyncer(ts.client.col, TEST_HKEY, ts.server.con)
    assert f.upload()
    ts.client.col.reopen()
    # should report no changes
    assert ts.client.sync() == "noChanges"
    # bump local col
    ts.client.col.setMod()
    ts.client.col.save()
    assert ts.client.sync() == "success"
    # again, no changes
    assert ts.client.sync() == "noChanges"
Пример #8
0
 def _fullSync(self):
     # tell the calling thread we need a decision on sync direction, and
     # wait for a reply
     self.fullSyncChoice = False
     self.fireEvent("fullSync")
     while not self.fullSyncChoice:
         time.sleep(0.1)
     f = self.fullSyncChoice
     if f == "cancel":
         return
     self.client = FullSyncer(self.col, self.hkey, self.server.con)
     if f == "upload":
         self.client.upload()
     else:
         self.client.download()
     # reopen db and move on to media sync
     self.col.reopen()
     self._syncMedia()
Пример #9
0
    def _fullSync(self, server):
        # if the local deck is empty, assume user is trying to download
        if self.collection.isEmpty():        
            f = "download"
        else:
            # tell the calling thread we need a decision on sync direction, and
            # wait for a reply
            f = "cancel"
            print "decision needed"

        print f
        if f == "cancel":
            return
        client = FullSyncer(self.collection, self.pm.profile['syncKey'], server.con)
        if f == "upload":
            client.upload()
        else:
            client.download()
Пример #10
0
 def _fullSync(self):
     # if the local deck is empty, assume user is trying to download
     if self.col.isEmpty():
         f = "download"
     else:
         # tell the calling thread we need a decision on sync direction, and
         # wait for a reply
         self.fullSyncChoice = False
         self.fireEvent("fullSync")
         while not self.fullSyncChoice:
             time.sleep(0.1)
         f = self.fullSyncChoice
     if f == "cancel":
         return
     self.client = FullSyncer(self.col, self.hkey, self.server.con)
     if f == "upload":
         if not self.client.upload():
             self.fireEvent("upbad")
     else:
         self.client.download()
     # reopen db and move on to media sync
     self.col.reopen()
     self._syncMedia()