Exemplo n.º 1
0
 client.setServer(proxy)
 # need to do anything?
 start = time.time()
 if client.prepareSync(proxy.timediff) and not disable:
     if self.deck.lastSync <= 0:
         if client.remoteTime > client.localTime:
             self.conflictResolution = "keepRemote"
         else:
             self.conflictResolution = "keepLocal"
     changes = True
     # summary
     if not self.conflictResolution and not self.onlyMerge:
         self.setStatus(_("Fetching summary from server..."), 0)
         sums = client.summaries()
     if (self.conflictResolution or
         self.onlyMerge or client.needFullSync(sums)):
         self.setStatus(_("Preparing full sync..."), 0)
         if self.conflictResolution == "keepLocal":
             client.remoteTime = 0
         elif self.conflictResolution == "keepRemote" or self.onlyMerge:
             client.localTime = 0
         lastSync = self.deck.lastSync
         ret = client.prepareFullSync()
         if ret[0] == "fromLocal":
             if not self.conflictResolution:
                 if lastSync <= 0 and not deckCreated:
                     self.clobberChoice = None
                     self.emit(SIGNAL("syncClobber"), syncName)
                     while not self.clobberChoice:
                         time.sleep(0.2)
                     if self.clobberChoice == "cancel":
Exemplo n.º 2
0
    def syncDeck(self, deck):
        try:
            proxy = HttpSyncServerProxy(config.get('SYNC_USERNAME'),
                                        config.get('SYNC_PASSWORD'))
            proxy.connect("ankimini")
        except:
            raise Exception("Can't sync - check username/password")
        if not proxy.hasDeck(deck.syncName):
            raise Exception("Can't sync, no deck on server")
        if abs(proxy.timestamp - time.time()) > 60:
            raise Exception("Your clock is off by more than 60 seconds.<br>" \
                            "Syncing will not work until you fix this.")

        client = SyncClient(deck)
        client.setServer(proxy)
        # need to do anything?
        proxy.deckName = deck.syncName
        if not client.prepareSync():
            raise Exception("Nothing to do")

        self.flushWrite("""<h1>Syncing deck</h1>
        <h2>%s</h2>
	<em>This could take a while with a big deck ... please be patient!</em>
	""" % (deck.path, ))

        # hack to get safari to render immediately!
        self.flushWrite("<!--" + " " * 1024 + "-->")

        # this can take a long time ... ensure the client doesn't timeout before we finish
        from threading import Event, Thread
        ping_event = Event()

        def ping_client(s=self.wfile, ev=ping_event):
            while 1:
                ev.wait(3)
                if ev.isSet():
                    return
                s.write(".<!--\n-->")
                s.flush()

        ping_thread = Thread(target=ping_client)
        ping_thread.start()

        # summary
        self.lineWrite("Fetching summary from server..")
        sums = client.summaries()
        needFull = client.needFullSync(sums)
        if needFull:
            self.lineWrite("Doing full sync..")
            client.fullSync()
        else:
            # diff
            self.lineWrite("Determining differences..")
            payload = client.genPayload(sums)
            # send payload
            pr = client.payloadChangeReport(payload)
            self.lineWrite("<br>" + pr + "<br>")
            self.lineWrite("Sending payload...")

        if needFull:
            deck = ds.Deck(deck.path, backup=False)
            # why is deck.syncName getting lost on a full sync???
            if deck.syncName is None:
                deck.syncName = proxy.deckName
                print "syncName was lost on full sync, restored to", deck.syncName
        else:
            res = client.server.applyPayload(payload)
            # apply reply
            self.lineWrite("Applying reply..")
            client.applyPayloadReply(res)
        # finished. save deck, preserving mod time
        self.lineWrite("Sync complete.")
        deck.rebuildQueue()
        deck.lastLoaded = deck.modified
        deck.s.flush()
        deck.s.commit()

        # turn off client ping
        ping_event.set()
        ping_thread.join(5)

        return deck
Exemplo n.º 3
0
 self.setStatus(_("Syncing <b>%s</b>...") % syncName, 0)
 self.deck = None
 try:
     self.deck = DeckStorage.Deck(path)
     client = SyncClient(self.deck)
     client.setServer(proxy)
     # need to do anything?
     start = time.time()
     if client.prepareSync():
         changes = True
         # summary
         if not self.conflictResolution and not self.onlyMerge:
             self.setStatus(_("Fetching summary from server..."), 0)
             sums = client.summaries()
         if (self.conflictResolution or self.onlyMerge
                 or client.needFullSync(sums)):
             self.setStatus(_("Preparing full sync..."), 0)
             if self.conflictResolution == "keepLocal":
                 client.remoteTime = 0
             elif self.conflictResolution == "keepRemote" or self.onlyMerge:
                 client.localTime = 0
             lastSync = self.deck.lastSync
             ret = client.prepareFullSync()
             if ret[0] == "fromLocal":
                 if not self.conflictResolution:
                     if lastSync <= 0 and not deckCreated:
                         self.clobberChoice = None
                         self.emit(SIGNAL("syncClobber"), syncName)
                         while not self.clobberChoice:
                             time.sleep(0.2)
                         if self.clobberChoice == "cancel":
Exemplo n.º 4
0
    def syncDeck(self, deck):
        try:
            proxy = HttpSyncServerProxy(config.get('SYNC_USERNAME'), config.get('SYNC_PASSWORD'))
            proxy.connect("ankimini")
        except:
            raise Exception("Can't sync: " + traceback.format_exc())
        if not proxy.hasDeck(deck.name()):
            raise Exception("Can't sync, no deck on server")
        if abs(proxy.timestamp - time.time()) > 60:
            raise Exception("Your clock is off by more than 60 seconds.<br>" \
                            "Syncing will not work until you fix this.")

        client = SyncClient(deck)
        client.setServer(proxy)
        # need to do anything?
        proxy.deckName = deck.name()
        print proxy.deckName
        if not client.prepareSync(0):
            raise Exception("Nothing to do")

	self.flushWrite("""<h1>Syncing deck</h1>
        <h2>%s</h2>
	<em>This could take a while with a big deck ... please be patient!</em>
	""" % (deck.path,) )

        # hack to get safari to render immediately!
        self.flushWrite("<!--" + " "*1024 + "-->")

	# this can take a long time ... ensure the client doesn't timeout before we finish
	from threading import Event, Thread
	ping_event = Event()
        def ping_client( s = self.wfile, ev=ping_event ):
            while 1:
                ev.wait(3)
                if ev.isSet():
                    return
                s.write(".<!--\n-->")
                s.flush()
	ping_thread = Thread(target=ping_client)
	ping_thread.start()

        # summary
        self.lineWrite("Fetching summary from server..")
        sums = client.summaries()
        needFull = client.needFullSync(sums)
        if needFull:
            self.lineWrite("Doing full sync..")
            client.fullSync()
        else:
            # diff
            self.lineWrite("Determining differences..")
            payload = client.genPayload(sums)
            # send payload
            pr = client.payloadChangeReport(payload)
            self.lineWrite("<br>" + pr + "<br>")
            self.lineWrite("Sending payload...")

        if needFull:
            deck = ds.Deck(deck.path, backup=False)
        else:
            res = client.server.applyPayload(payload)
            # apply reply
            self.lineWrite("Applying reply..")
            client.applyPayloadReply(res)
            try:
                client.server.finish()
            except:
                deck.s.rollback()
        # finished. save deck, preserving mod time
        self.lineWrite("Sync complete.")
        deck.reset()
        deck.lastLoaded = deck.modified
        deck.s.flush()
        deck.s.commit()

	# turn off client ping
	ping_event.set()
        ping_thread.join(5)

        return deck
Exemplo n.º 5
0
         return
 # reopen
 self.setStatus(_("Syncing <b>%s</b>...") % syncName, 0)
 self.deck = None
 try:
     self.deck = DeckStorage.Deck(path)
     client = SyncClient(self.deck)
     client.setServer(proxy)
     # need to do anything?
     start = time.time()
     if client.prepareSync():
         changes = True
         # summary
         self.setStatus(_("Fetching summary from server..."), 0)
         sums = client.summaries()
         if self.conflictResolution or client.needFullSync(sums):
             self.setStatus(_("Preparing full sync..."), 0)
             if self.conflictResolution == "keepLocal":
                 client.remoteTime = 0
             elif self.conflictResolution == "keepRemote":
                 client.localTime = 0
             lastSync = self.deck.lastSync
             ret = client.prepareFullSync()
             if ret[0] == "fromLocal":
                 if not self.conflictResolution:
                     if lastSync <= 0:
                         self.clobberChoice = None
                         self.emit(SIGNAL("syncClobber"), syncName)
                         while not self.clobberChoice:
                             time.sleep(0.2)
                         if self.clobberChoice == "cancel":
Exemplo n.º 6
0
     return
 # reconnect
 self.deck = None
 try:
     self.deck = DeckStorage.Deck(self.parent.deckPath, backup=False)
     client = SyncClient(self.deck)
     client.setServer(proxy)
     proxy.deckName = self.parent.syncName
     # need to do anything?
     start = time.time()
     if client.prepareSync():
         changes = True
         # summary
         self.setStatus(_("Fetching summary from server..."), 0)
         sums = client.summaries()
         if client.needFullSync(sums):
             self.setStatus(_("Preparing full sync..."), 0)
             ret = client.prepareFullSync()
             if ret[0] == "fromLocal":
                 self.setStatus(_("Uploading..."), 0)
                 client.fullSyncFromLocal(ret[1], ret[2])
             else:
                 self.setStatus(_("Downloading..."), 0)
                 client.fullSyncFromServer(ret[1], ret[2])
             if client.mediaSupported():
                 self.doBulkDownload(proxy.deckName)
             self.setStatus(_("Sync complete."), 0)
         else:
             # diff
             self.setStatus(_("Determining differences..."), 0)
             payload = client.genPayload(sums)