本文整理汇总了Python中anki.tags.TagManager.registerNotes方法的典型用法代码示例。如果您正苦于以下问题:Python TagManager.registerNotes方法的具体用法?Python TagManager.registerNotes怎么用?Python TagManager.registerNotes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.tags.TagManager
的用法示例。
在下文中一共展示了TagManager.registerNotes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Collection
# 需要导入模块: from anki.tags import TagManager [as 别名]
# 或者: from anki.tags.TagManager import registerNotes [as 别名]
#.........这里部分代码省略.........
self.cleanup()
self.sched = self._stdSched
return True
def cramDecks(self, order="mod desc", min=0, max=None):
self.stdSched()
self.sched = anki.cram.CramScheduler(self, order, min, max)
# Undo
##########################################################################
def clearUndo(self):
# [type, undoName, data]
# type 1 = review; type 2 = checkpoint
self._undo = None
def undoName(self):
"Undo menu item name, or None if undo unavailable."
if not self._undo:
return None
return self._undo[1]
def undo(self):
if self._undo[0] == 1:
self._undoReview()
else:
self._undoOp()
def markReview(self, card):
old = []
if self._undo:
if self._undo[0] == 1:
old = self._undo[2]
self.clearUndo()
self._undo = [1, _("Review"), old + [copy.copy(card)]]
def _undoReview(self):
data = self._undo[2]
c = data.pop()
if not data:
self.clearUndo()
# write old data
c.flush()
# and delete revlog entry
last = self.db.scalar(
"select id from revlog where cid = ? "
"order by id desc limit 1", c.id)
self.db.execute("delete from revlog where id = ?", last)
# and finally, update daily counts
# fixme: what to do in cramming case?
type = ("new", "lrn", "rev")[c.queue]
self.sched._updateStats(c, type, -1)
def _markOp(self, name):
"Call via .save()"
if name:
self._undo = [2, name]
else:
# saving disables old checkpoint, but not review undo
if self._undo and self._undo[0] == 2:
self.clearUndo()
def _undoOp(self):
self.rollback()
self.clearUndo()
# DB maintenance
##########################################################################
def fixIntegrity(self):
"Fix possible problems and rebuild caches."
problems = []
self.save()
oldSize = os.stat(self.path)[stat.ST_SIZE]
if self.db.scalar("pragma integrity_check") != "ok":
return _("Collection is corrupt. Please see the manual.")
# delete any notes with missing cards
ids = self.db.list("""
select id from notes where id not in (select distinct nid from cards)""")
self._remNotes(ids)
# tags
self.tags.registerNotes()
# field cache
for m in self.models.all():
self.updateFieldCache(self.models.nids(m))
# and finally, optimize
self.optimize()
newSize = os.stat(self.path)[stat.ST_SIZE]
save = (oldSize - newSize)/1024
txt = _("Database rebuilt and optimized.")
if save > 0:
txt += "\n" + _("Saved %dKB.") % save
problems.append(txt)
self.save()
return "\n".join(problems)
def optimize(self):
self.db.execute("vacuum")
self.db.execute("analyze")
self.lock()
示例2: _Collection
# 需要导入模块: from anki.tags import TagManager [as 别名]
# 或者: from anki.tags.TagManager import registerNotes [as 别名]
#.........这里部分代码省略.........
"Deleted %d notes with no cards.", cnt) % cnt)
self._remNotes(ids)
# cards with missing notes
ids = self.db.list("""
select id from cards where nid not in (select id from notes)""")
if ids:
cnt = len(ids)
problems.append(
ngettext("Deleted %d card with missing note.",
"Deleted %d cards with missing note.", cnt) % cnt)
self.remCards(ids)
# cards with odue set when it shouldn't be
ids = self.db.list("""
select id from cards where odue > 0 and (type=1 or queue=2) and not odid""")
if ids:
cnt = len(ids)
problems.append(
ngettext("Fixed %d card with invalid properties.",
"Fixed %d cards with invalid properties.", cnt) % cnt)
self.db.execute("update cards set odue=0 where id in "+
ids2str(ids))
# cards with odid set when not in a dyn deck
dids = [id for id in self.decks.allIds() if not self.decks.isDyn(id)]
ids = self.db.list("""
select id from cards where odid > 0 and did in %s""" % ids2str(dids))
if ids:
cnt = len(ids)
problems.append(
ngettext("Fixed %d card with invalid properties.",
"Fixed %d cards with invalid properties.", cnt) % cnt)
self.db.execute("update cards set odid=0, odue=0 where id in "+
ids2str(ids))
# tags
self.tags.registerNotes()
# field cache
for m in self.models.all():
self.updateFieldCache(self.models.nids(m))
# new cards can't have a due position > 32 bits
self.db.execute("""
update cards set due = 1000000, mod = ?, usn = ? where due > 1000000
and queue = 0""", intTime(), self.usn())
# new card position
self.conf['nextPos'] = self.db.scalar(
"select max(due)+1 from cards where type = 0") or 0
# reviews should have a reasonable due #
ids = self.db.list(
"select id from cards where queue = 2 and due > 10000")
if ids:
problems.append("Reviews had incorrect due date.")
self.db.execute(
"update cards set due = 0, mod = ?, usn = ? where id in %s"
% ids2str(ids), intTime(), self.usn())
# and finally, optimize
self.optimize()
newSize = os.stat(self.path)[stat.ST_SIZE]
txt = _("Database rebuilt and optimized.")
ok = not problems
problems.append(txt)
# if any problems were found, force a full sync
if not ok:
self.modSchema(check=False)
self.save()
return ("\n".join(problems), ok)
def optimize(self):
self.db.execute("vacuum")