예제 #1
0
파일: sync.py 프로젝트: scout-zz/ankiqt
 def doBulkDownload(self, deckname):
     self.emit(SIGNAL("openSyncProgress"))
     client = BulkMediaSyncer(self.deck)
     client.server = BulkMediaSyncerProxy(self.user, self.pwd)
     client.server.deckName = deckname
     client.progressCallback = self.bulkCallback
     try:
         client.sync()
     except:
         self.emit(SIGNAL("bulkSyncFailed"))
     time.sleep(0.1)
     self.emit(SIGNAL("closeSyncProgress"))
예제 #2
0
    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()
예제 #3
0
파일: anki10.py 프로젝트: scout-zz/libanki
 def doImport(self):
     "Import."
     random = self.deck.newCardOrder == NEW_CARDS_RANDOM
     num = 4
     if random:
         num += 1
     self.deck.startProgress(num)
     self.deck.updateProgress(_("Importing..."))
     src = DeckStorage.Deck(self.file)
     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.s.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'] == []
     self.deck.updateProgress()
     res = server.applyPayload(payload)
     self.deck.updateProgress()
     client.applyPayloadReply(res)
     if client.mediaSyncPending:
         bulkClient = BulkMediaSyncer(client.deck)
         bulkServer = BulkMediaSyncer(server.deck)
         bulkClient.server = bulkServer
         bulkClient.sync()
     # add tags
     self.deck.updateProgress()
     fids = [f[0] for f in res['added-facts']['facts']]
     self.deck.addTags(fids, self.tagsToAdd)
     # mark import material as newly added
     self.deck.s.statement(
         "update cards set modified = :t where id in %s" %
         ids2str([x[0] for x in res['added-cards']]), t=time.time())
     self.deck.s.statement(
         "update facts set modified = :t where id in %s" %
         ids2str([x[0] for x in res['added-facts']['facts']]), t=time.time())
     self.deck.s.statement(
         "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.updateProgress()
         self.deck.randomizeNewCards([x[0] for x in res['added-cards']])
     self.deck.flushMod()
     self.deck.finishProgress()