本文整理汇总了Python中anki.sync.SyncClient.sync方法的典型用法代码示例。如果您正苦于以下问题:Python SyncClient.sync方法的具体用法?Python SyncClient.sync怎么用?Python SyncClient.sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.sync.SyncClient
的用法示例。
在下文中一共展示了SyncClient.sync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_anki10_modtime
# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import sync [as 别名]
def test_anki10_modtime():
deck1 = DeckStorage.Deck()
deck2 = DeckStorage.Deck()
client = SyncClient(deck1)
server = SyncServer(deck2)
client.setServer(server)
deck1.addModel(BasicModel())
f = deck1.newFact()
f['Front'] = u"foo"; f['Back'] = u"bar"
deck1.addFact(f)
assert deck1.cardCount == 1
assert deck2.cardCount == 0
client.sync()
assert deck1.cardCount == 1
assert deck2.cardCount == 1
file_ = unicode(os.path.join(testDir, "importing/test10-3.anki"))
file = "/tmp/test10-3.anki"
shutil.copy(file_, file)
i = anki10.Anki10Importer(deck1, file)
i.doImport()
client.sync()
assert i.total == 1
assert deck2.s.scalar("select count(*) from cards") == 2
assert deck2.s.scalar("select count(*) from facts") == 2
assert deck2.s.scalar("select count(*) from models") == 2
示例2: test_localsync_threeway
# 需要导入模块: from anki.sync import SyncClient [as 别名]
# 或者: from anki.sync.SyncClient import sync [as 别名]
def test_localsync_threeway():
# deck1 (client) <-> deck2 (server) <-> deck3 (client)
deck3 = DeckStorage.Deck()
client2 = SyncClient(deck3)
server2 = SyncServer(deck2)
client2.setServer(server2)
client.sync()
client2.sync()
# add a new question
f = deck1.newFact()
f['Front'] = u"a"; f['Back'] = u"b"
f = deck1.addFact(f)
card = f.cards[0]
client.sync()
assert deck1.cardCount == 6
assert deck2.cardCount == 6
# check it propagates from server to deck3
client2.sync()
assert deck3.cardCount == 6
# delete a card on deck1
deck1.deleteCard(card.id)
client.sync()
assert deck1.cardCount == 5
assert deck2.cardCount == 5
# make sure the delete is now propagated from the server to deck3
client2.sync()
assert deck3.cardCount == 5