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


Python SyncClient.needFullSync方法代码示例

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


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

示例1:

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

示例2: SyncClient

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

示例3: syncDeck

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import needFullSync [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

示例4: SyncClient

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import needFullSync [as 别名]
     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)
开发者ID:scout-zz,项目名称:ankiqt,代码行数:33,代码来源:sync.py


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