コード例 #1
0
def setup_remote():
    setup_local()
    global client, server
    proxy = HttpSyncServerProxy("test", "foo")
    client = SyncClient(deck1)
    client.setServer(proxy)
    proxy.deckName = "test"
    proxy.runCmd = runCmd
    server = HttpSyncServer()
    server.deck = deck2
    server.decks = {"test": (deck2.modified, 0)}
コード例 #2
0
 def connect(self, *args):
     # connect, check auth
     if not self.proxy:
         self.setStatus(_("Connecting..."), 0)
         proxy = HttpSyncServerProxy(self.user, self.pwd)
         proxy.connect("ankiqt-" + ankiqt.appVersion)
         self.proxy = proxy
         # check clock
         if proxy.timediff > 300:
             self.emit(SIGNAL("syncClockOff"), proxy.timediff)
             raise SyncError(type="clockOff")
     return self.proxy
コード例 #3
0
ファイル: main.py プロジェクト: fenildf/ankimini
    def render_get_personal(self):
        global config
        buffer = """
		<html>
		<head><title>List personal decks</title>
		<style>
		.page-header { background-color: #8FA1B9; border-bottom-style: solid; border-bottom-width: 1.5px; border-bottom-color: #2D3642; border-top-style: solid; border-top-width: 1.5px; border-top-color: #CDD5DF; color: #FFFFFF;
			font-family: Arial, Helvetica, sans-serif; height: 51px; font-size: 30px; font-weight: bold; text-align: center; padding-top: 15px; text-shadow: 0 -1.5px 1.2px #5D6773, 0 1.5px 1.2px #A4B2C4; background: -webkit-gradient(linear, left top, left bottom, from(#B0BCCD), to(#6D84A2), color-stop(0.5, #889BB3), color-stop(0.5, #8195AF)); }
		</style>
		</head>
		<body style="font-family: arial, helvetica; margin-left: 0px; margin-right: -10px; margin-top: 0px">
		<div class="page-header">Online Personal Decks</div>
		<div style="margin-left: 15; margin-right: 15; margin-top: 15">
		Please select one to download it...
		"""
        try:
            proxy = HttpSyncServerProxy(config.get('SYNC_USERNAME'),
                                        config.get('SYNC_PASSWORD'))
            deckList = proxy.availableDecks()
            if deckList is None or len(deckList) == 0:
                buffer += "<br /><em>You have no online decks!</em>"
            else:
                buffer += '<table width="100%%" cellspacing="10">'
                for d in deckList:
                    buffer += '<tr height><td><a href="/download?deck=%s">%s</a></td></tr>' % (
                        d, d)
                buffer += "</table>"
        except:
            buffer += "<br /><em>Can't connect - check username/password</em>"

        buffer += """
		<br /><a href="/question#inner_top">return</a>
		</div>
		</body>
		</html>
	        """

        return buffer
コード例 #4
0
ファイル: main.py プロジェクト: fenildf/ankimini
    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