当前位置: 首页>>代码示例>>Python>>正文


Python SyncClient.prepareSync方法代码示例

本文整理汇总了Python中anki.sync.SyncClient.prepareSync方法的典型用法代码示例。如果您正苦于以下问题:Python SyncClient.prepareSync方法的具体用法?Python SyncClient.prepareSync怎么用?Python SyncClient.prepareSync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在anki.sync.SyncClient的用法示例。


在下文中一共展示了SyncClient.prepareSync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SyncClient

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import prepareSync [as 别名]
         self.emit(SIGNAL("syncFinished"))
         return -1
 # reopen
 self.setStatus(_("Syncing <b>%s</b>...") % syncName, 0)
 self.deck = None
 try:
     self.deck = DeckStorage.Deck(path)
     disable = False
     if deck and not self.deck.syncName:
         # multi-mode sync and syncing has been disabled by upgrade
         disable = True
     client = SyncClient(self.deck)
     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
开发者ID:TianYuanChu,项目名称:AnkiCPRP,代码行数:33,代码来源:sync.py

示例2: SyncClient

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import prepareSync [as 别名]
         time.sleep(0.2)
     if self.conflictResolution == "cancel":
         if not deck:
             # alert we're finished early
             self.emit(SIGNAL("syncFinished"))
         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
         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":
开发者ID:zw,项目名称:ankiqt,代码行数:33,代码来源:sync.py

示例3: do_sync

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import prepareSync [as 别名]
    def do_sync(self):
        if self.SYNC_USERNAME == "" or self.SYNC_PASSWORD == "" and \
            self.yesno_dlg(gtk.MESSAGE_QUESTION, "Do you want to set sync account?"):
            self.run_settings(None, None)
                    
        self.deck_save()
        page = "<br/><br/>"
        self.deck.lastLoaded = time.time()
        #syncing
        while 1:
            proxy = HttpSyncServerProxy(self.SYNC_USERNAME, self.SYNC_PASSWORD)
            try:
                proxy.connect("ankimini")
            except:
                self.err_dlg("Cant connect - check connection and username/password")
                return

            if not proxy.hasDeck(self.deck.syncName):
                self.err_dlg("Cant sync, no deck on server")
                return

            if abs(proxy.timestamp - time.time()) > 60:
                self.err_dlg("Your clock is off by more than 60 seconds. Syncing will not work until you fix this.")
                return

            client = SyncClient(self.deck)
            client.setServer(proxy)
                # need to do anything?
            proxy.deckName = self.deck.syncName
            if not client.prepareSync():
                return
                # summary
            page+="""
<html><head>
<meta name="viewport" content="user-scalable=yes, width=device-width,
    maximum-scale=0.6667" />
</head><body>\n
Fetching summary from server..<br>
"""
            self.print_html_doc(page)
            sums = client.summaries()
                # diff
            page+="Determining differences.."
            self.print_html_doc(page)
            payload = client.genPayload(sums)
                # send payload
            pr = client.payloadChangeReport(payload)
            page+="<br>" + pr + "<br>"
            page+="Sending payload...<br>"
            self.print_html_doc(page)
            res = client.server.applyPayload(payload)
                # apply reply
            page+="Applying reply..<br>"
            self.print_html_doc(page)
            client.applyPayloadReply(res)
                # finished. save deck, preserving mod time
            page+="Sync complete."
            self.print_html_doc(page)
            self.deck.rebuildQueue()
            self.deck.lastLoaded = self.deck.modified
            self.deck.s.flush()
            self.deck.s.commit()
开发者ID:jamesjrg,项目名称:ankimaemi,代码行数:64,代码来源:ankimaemi.py

示例4: syncDeck

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import prepareSync [as 别名]
    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
开发者ID:lahorichargha,项目名称:ankimini,代码行数:82,代码来源:main.py


注:本文中的anki.sync.SyncClient.prepareSync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。