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


Python SyncClient.localTime方法代码示例

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


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

示例1: doImport

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

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import localTime [as 别名]
 def exportInto(self, path):
     n = 3
     if not self.includeSchedulingInfo:
         n += 1
     try:
         os.unlink(path)
     except (IOError, OSError):
         pass
     self.newCol = DeckStorage.Deck(path)
     client = SyncClient(self.deck)
     server = SyncServer(self.newDeck)
     client.setServer(server)
     client.localTime = self.deck.modified
     client.remoteTime = 0
     self.deck.db.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)
     if not self.includeSchedulingInfo:
         self.newDeck.resetCards()
     # media
     if self.includeMedia:
         server.deck.mediaPrefix = ""
         copyLocalMedia(client.deck, server.deck)
     # need to save manually
     self.newDeck.rebuildCounts()
     # FIXME
     #self.exportedCards = self.newDeck.cardCount
     self.newDeck.crt = 0
     self.newDeck.db.commit()
     self.newDeck.close()
开发者ID:aaronharsh,项目名称:libanki,代码行数:35,代码来源:exporting.py

示例3: doImport

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

示例4: exportInto

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

示例5:

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import localTime [as 别名]
     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":
                     # disable syncing on this deck
                     c = sqlite.connect(sqlpath)
                     c.execute(
                         "update decks set syncName = null, "
                         "lastSync = 0")
开发者ID:TianYuanChu,项目名称:AnkiCPRP,代码行数:33,代码来源:sync.py

示例6: exportInto

# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import localTime [as 别名]
    def exportInto(self, path):
        n = 3
        if not self.includeSchedulingInfo:
            n += 1
        self.deck.startProgress(n)
        self.deck.updateProgress(_("Exporting..."))
        self.newDeck = DeckStorage.Deck(path)
        client = SyncClient(self.deck)
        server = SyncServer(self.newDeck)
        server._mediaSupported = self.includeMedia
        client.setServer(server)
        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)
        self.deck.updateProgress()
        payload = client.genPayload((lsum, rsum))
        self.deck.updateProgress()
        res = server.applyPayload(payload)
        if not self.includeSchedulingInfo:
            self.deck.updateProgress()
            self.newDeck.s.statement("""
delete from reviewHistory""")
            self.newDeck.s.statement("""
update cards set
interval = 0,
lastInterval = 0,
due = created,
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,
spaceUntil = 0,
isDue = 1,
type = 2,
combinedDue = created,
modified = :now
""", now=time.time())
            self.newDeck.s.statement("""
delete from stats""")
        # media
        if client.mediaSyncPending:
            bulkClient = BulkMediaSyncer(client.deck)
            bulkServer = BulkMediaSyncer(server.deck)
            bulkClient.server = bulkServer
            bulkClient.sync()
        # need to save manually
        self.newDeck.rebuildCounts()
        self.newDeck.updateAllPriorities()
        self.exportedCards = self.newDeck.cardCount
        self.newDeck.utcOffset = -1
        self.newDeck.s.commit()
        self.newDeck.close()
        self.deck.finishProgress()
开发者ID:scout-zz,项目名称:libanki,代码行数:73,代码来源:exporting.py


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