mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
implement full sync uploading
This commit is contained in:
parent
7a4855233b
commit
619d2bcbaf
2 changed files with 57 additions and 19 deletions
|
@ -1787,6 +1787,9 @@ it to your friends.
|
||||||
self.connect(self.syncThread, SIGNAL("closeSyncProgress"), self.closeSyncProgress)
|
self.connect(self.syncThread, SIGNAL("closeSyncProgress"), self.closeSyncProgress)
|
||||||
self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress)
|
self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress)
|
||||||
self.connect(self.syncThread, SIGNAL("bulkSyncFailed"), self.bulkSyncFailed)
|
self.connect(self.syncThread, SIGNAL("bulkSyncFailed"), self.bulkSyncFailed)
|
||||||
|
self.connect(self.syncThread, SIGNAL("fullSyncStarted"), self.fullSyncStarted)
|
||||||
|
self.connect(self.syncThread, SIGNAL("fullSyncFinished"), self.fullSyncFinished)
|
||||||
|
self.connect(self.syncThread, SIGNAL("fullSyncProgress"), self.fullSyncProgress)
|
||||||
self.syncThread.start()
|
self.syncThread.start()
|
||||||
self.switchToWelcomeScreen()
|
self.switchToWelcomeScreen()
|
||||||
self.setEnabled(False)
|
self.setEnabled(False)
|
||||||
|
@ -1887,6 +1890,20 @@ Couldn't contact Anki Online. Please check your internet connection.""")
|
||||||
ui.utils.showWarning(_(
|
ui.utils.showWarning(_(
|
||||||
"Failed to upload media. Please run 'check media db'."), self)
|
"Failed to upload media. Please run 'check media db'."), self)
|
||||||
|
|
||||||
|
def fullSyncStarted(self, ret):
|
||||||
|
self.startProgress(max=ret[2])
|
||||||
|
if ret[0] == "fromLocal":
|
||||||
|
s = _("Uploading to server...")
|
||||||
|
else:
|
||||||
|
s = _("Downloading from server...")
|
||||||
|
self.updateProgress(label=s)
|
||||||
|
|
||||||
|
def fullSyncFinished(self):
|
||||||
|
self.finishProgress()
|
||||||
|
|
||||||
|
def fullSyncProgress(self, val):
|
||||||
|
self.updateProgress(value=val)
|
||||||
|
|
||||||
# Menu, title bar & status
|
# Menu, title bar & status
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,11 @@ import os, types, socket, time, traceback
|
||||||
import ankiqt
|
import ankiqt
|
||||||
import anki
|
import anki
|
||||||
from anki.sync import SyncClient, HttpSyncServerProxy, BulkMediaSyncerProxy
|
from anki.sync import SyncClient, HttpSyncServerProxy, BulkMediaSyncerProxy
|
||||||
from anki.sync import BulkMediaSyncer
|
from anki.sync import BulkMediaSyncer, SYNC_HOST, SYNC_PORT
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
from anki import DeckStorage
|
from anki import DeckStorage
|
||||||
import ankiqt.forms
|
import ankiqt.forms
|
||||||
|
from anki.hooks import addHook, removeHook
|
||||||
|
|
||||||
# Synchronising a deck with a public server
|
# Synchronising a deck with a public server
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -28,12 +29,27 @@ class Sync(QThread):
|
||||||
self.ok = True
|
self.ok = True
|
||||||
self.onlyMerge = onlyMerge
|
self.onlyMerge = onlyMerge
|
||||||
self.sourcesToCheck = sourcesToCheck
|
self.sourcesToCheck = sourcesToCheck
|
||||||
|
addHook('fullSyncStarted', self.fullSyncStarted)
|
||||||
|
addHook('fullSyncFinished', self.fullSyncFinished)
|
||||||
|
addHook('fullSyncProgress', self.fullSyncProgress)
|
||||||
|
|
||||||
def setStatus(self, msg, timeout=5000):
|
def setStatus(self, msg, timeout=5000):
|
||||||
self.emit(SIGNAL("setStatus"), msg, timeout)
|
self.emit(SIGNAL("setStatus"), msg, timeout)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.syncDeck()
|
self.syncDeck()
|
||||||
|
removeHook('fullSyncStarted', self.fullSyncStarted)
|
||||||
|
removeHook('fullSyncFinished', self.fullSyncFinished)
|
||||||
|
removeHook('fullSyncProgress', self.fullSyncProgress)
|
||||||
|
|
||||||
|
def fullSyncStarted(self, ret):
|
||||||
|
self.emit(SIGNAL("fullSyncStarted"), ret)
|
||||||
|
|
||||||
|
def fullSyncFinished(self):
|
||||||
|
self.emit(SIGNAL("fullSyncFinished"))
|
||||||
|
|
||||||
|
def fullSyncProgress(self, val):
|
||||||
|
self.emit(SIGNAL("fullSyncProgress"), val)
|
||||||
|
|
||||||
def error(self, error):
|
def error(self, error):
|
||||||
if getattr(error, 'data', None) is None:
|
if getattr(error, 'data', None) is None:
|
||||||
|
@ -101,24 +117,29 @@ class Sync(QThread):
|
||||||
# summary
|
# summary
|
||||||
self.setStatus(_("Fetching summary from server..."), 0)
|
self.setStatus(_("Fetching summary from server..."), 0)
|
||||||
sums = client.summaries()
|
sums = client.summaries()
|
||||||
# diff
|
if client.needFullSync(sums):
|
||||||
self.setStatus(_("Determining differences..."), 0)
|
self.setStatus(_("Preparing full sync..."), 0)
|
||||||
payload = client.genPayload(sums)
|
client.fullSync()
|
||||||
# send payload
|
self.setStatus(_("Sync complete."), 0)
|
||||||
pr = client.payloadChangeReport(payload)
|
else:
|
||||||
self.setStatus("<br>" + pr + "<br>", 0)
|
# diff
|
||||||
self.setStatus(_("Transferring payload..."), 0)
|
self.setStatus(_("Determining differences..."), 0)
|
||||||
res = client.server.applyPayload(payload)
|
payload = client.genPayload(sums)
|
||||||
# apply reply
|
# send payload
|
||||||
self.setStatus(_("Applying reply..."), 0)
|
pr = client.payloadChangeReport(payload)
|
||||||
client.applyPayloadReply(res)
|
self.setStatus("<br>" + pr + "<br>", 0)
|
||||||
if client.mediaSyncPending:
|
self.setStatus(_("Transferring payload..."), 0)
|
||||||
self.doBulkDownload(proxy.deckName)
|
res = client.server.applyPayload(payload)
|
||||||
# finished. save deck, preserving mod time
|
# apply reply
|
||||||
self.setStatus(_("Sync complete."))
|
self.setStatus(_("Applying reply..."), 0)
|
||||||
self.deck.lastLoaded = self.deck.modified
|
client.applyPayloadReply(res)
|
||||||
self.deck.s.flush()
|
if client.mediaSyncPending:
|
||||||
self.deck.s.commit()
|
self.doBulkDownload(proxy.deckName)
|
||||||
|
# finished. save deck, preserving mod time
|
||||||
|
self.setStatus(_("Sync complete."))
|
||||||
|
self.deck.lastLoaded = self.deck.modified
|
||||||
|
self.deck.s.flush()
|
||||||
|
self.deck.s.commit()
|
||||||
else:
|
else:
|
||||||
changes = False
|
changes = False
|
||||||
self.setStatus(_("No changes found."))
|
self.setStatus(_("No changes found."))
|
||||||
|
|
Loading…
Reference in a new issue