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


Python SyncClient.applyPayloadReply方法代码示例

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


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

示例1: doImport

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import applyPayloadReply [as 别名]
 def doImport(self):
     "Import."
     src = DeckStorage.Deck(self.file)
     client = SyncClient(self.deck)
     server = SyncServer(src)
     # if there is a conflict, sync local -> src
     client.localTime = self.deck.modified
     client.remoteTime = 0
     src.s.execute("update facts set modified = 1")
     src.s.execute("update models set modified = 1")
     src.s.execute("update cards set modified = 1")
     self.deck.s.flush()
     # set up a custom change list and sync
     lsum = client.summary(0)
     rsum = server.summary(0)
     payload = client.genPayload(lsum, rsum)
     # no need to add anything to src
     payload["added-models"] = []
     payload["added-cards"] = []
     payload["added-facts"] = {"facts": [], "fields": []}
     payload["deleted-facts"] = []
     payload["deleted-cards"] = []
     payload["deleted-models"] = []
     res = server.applyPayload(payload)
     client.applyPayloadReply(res)
     # add tags
     fids = [f[0] for f in res["added-facts"]["facts"]]
     self.deck.addFactTags(fids, self.tagsToAdd)
     self.total = len(res["added-facts"]["facts"])
     src.s.rollback()
     self.deck.flushMod()
开发者ID:typerlc,项目名称:ankice-deps,代码行数:33,代码来源:anki10.py

示例2: doImport

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import applyPayloadReply [as 别名]
 def doImport(self):
     "Import."
     random = self.deck.newCardOrder == NEW_CARDS_RANDOM
     num = 4
     if random:
         num += 1
     src = DeckStorage.Deck(self.file, backup=False)
     client = SyncClient(self.deck)
     server = SyncServer(src)
     client.setServer(server)
     # if there is a conflict, sync local -> src
     client.localTime = self.deck.modified
     client.remoteTime = 0
     src.s.execute("update facts set modified = 1")
     src.s.execute("update models set modified = 1")
     src.s.execute("update cards set modified = 1")
     src.s.execute("update media set created = 1")
     self.deck.db.flush()
     # set up a custom change list and sync
     lsum = client.summary(0)
     self._clearDeleted(lsum)
     rsum = server.summary(0)
     self._clearDeleted(rsum)
     payload = client.genPayload((lsum, rsum))
     # no need to add anything to src
     payload['added-models'] = []
     payload['added-cards'] = []
     payload['added-facts'] = {'facts': [], 'fields': []}
     assert payload['deleted-facts'] == []
     assert payload['deleted-cards'] == []
     assert payload['deleted-models'] == []
     res = server.applyPayload(payload)
     client.applyPayloadReply(res)
     copyLocalMedia(server.deck, client.deck)
     # add tags
     fids = [f[0] for f in res['added-facts']['facts']]
     self.deck.addTags(fids, self.tagsToAdd)
     # mark import material as newly added
     self.deck.db.execute(
         "update cards set modified = :t where id in %s" %
         ids2str([x[0] for x in res['added-cards']]), t=time.time())
     self.deck.db.execute(
         "update facts set modified = :t where id in %s" %
         ids2str([x[0] for x in res['added-facts']['facts']]), t=time.time())
     self.deck.db.execute(
         "update models set modified = :t where id in %s" %
         ids2str([x['id'] for x in res['added-models']]), t=time.time())
     # update total and refresh
     self.total = len(res['added-facts']['facts'])
     src.s.rollback()
     src.engine.dispose()
     # randomize?
     if random:
         self.deck.randomizeNewCards([x[0] for x in res['added-cards']])
     self.deck.flushMod()
开发者ID:ChYi,项目名称:libanki,代码行数:57,代码来源:anki10.py

示例3: exportInto

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import applyPayloadReply [as 别名]
    def exportInto(self, path):
        self.newDeck = DeckStorage.Deck(path)
        client = SyncClient(self.deck)
        server = SyncServer(self.newDeck)
        client.localTime = self.deck.modified
        client.remoteTime = 0
        self.deck.s.flush()
        # set up a custom change list and sync
        lsum = self.localSummary()
        rsum = server.summary(0)
        payload = client.genPayload(lsum, rsum)
        res = server.applyPayload(payload)
        client.applyPayloadReply(res)
        if not self.includeSchedulingInfo:
            self.newDeck.s.statement("""
update cards set
interval = 0,
lastInterval = 0,
due = 0,
lastDue = 0,
factor = 2.5,
firstAnswered = 0,
reps = 0,
successive = 0,
averageTime = 0,
reviewTime = 0,
youngEase0 = 0,
youngEase1 = 0,
youngEase2 = 0,
youngEase3 = 0,
youngEase4 = 0,
matureEase0 = 0,
matureEase1 = 0,
matureEase2 = 0,
matureEase3 = 0,
matureEase4 = 0,
yesCount = 0,
noCount = 0,
modified = :now
""", now=time.time())
            # update spacing
            self.newDeck.s.statement("""
update facts set
lastCardId = null,
spaceUntil = 0,
modified = :now""", now=time.time())
        # need to save manually
        self.newDeck.s.commit()
        self.newDeck.close()
开发者ID:typerlc,项目名称:ankice-deps,代码行数:51,代码来源:exporting.py

示例4:

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import applyPayloadReply [as 别名]
             self.setStatus(_("Downloading..."), 0)
             client.fullSyncFromServer(ret[1], ret[2])
         self.setStatus(_("Sync complete."), 0)
     else:
         # diff
         self.setStatus(_("Determining differences..."), 0)
         payload = client.genPayload(sums)
         # send payload
         if not deck:
             pr = client.payloadChangeReport(payload)
             self.setStatus("<br>" + pr + "<br>", 0)
         self.setStatus(_("Transferring payload..."), 0)
         res = client.server.applyPayload(payload)
         # apply reply
         self.setStatus(_("Applying reply..."), 0)
         client.applyPayloadReply(res)
         # now that both sides have successfully applied, tell
         # server to save, then save local
         client.server.finish()
         self.deck.lastLoaded = self.deck.modified
         self.deck.s.commit()
         self.setStatus(_("Sync complete."))
 else:
     changes = False
     if disable:
         self.setStatus(_("Disabled by upgrade."))
     elif not deck:
         self.setStatus(_("No changes found."))
 # close and send signal to main thread
 self.deck.close()
 if not deck:
开发者ID:TianYuanChu,项目名称:AnkiCPRP,代码行数:33,代码来源:sync.py

示例5: do_sync

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

示例6: syncDeck

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import applyPayloadReply [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.applyPayloadReply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。