本文整理汇总了Python中anki.db.DB.first方法的典型用法代码示例。如果您正苦于以下问题:Python DB.first方法的具体用法?Python DB.first怎么用?Python DB.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.db.DB
的用法示例。
在下文中一共展示了DB.first方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from anki.db import DB [as 别名]
# 或者: from anki.db.DB import first [as 别名]
#.........这里部分代码省略.........
# wrong filename encoding which will cause sync errors
if os.path.exists(normpath):
os.unlink(path)
else:
os.rename(path, normpath)
# newly added?
if f not in self.cache:
added.append(f)
else:
# modified since last time?
if self._mtime(path) != self.cache[f][1]:
# and has different checksum?
if self._checksum(path) != self.cache[f][0]:
added.append(f)
# mark as used
self.cache[f][2] = True
# look for any entries in the cache that no longer exist on disk
for (k, v) in list(self.cache.items()):
if not v[2]:
removed.append(k)
return added, removed
# Syncing-related
##########################################################################
def lastUsn(self):
return self.db.scalar("select lastUsn from meta")
def setLastUsn(self, usn):
self.db.execute("update meta set lastUsn = ?", usn)
self.db.commit()
def syncInfo(self, fname):
ret = self.db.first(
"select csum, dirty from media where fname=?", fname)
return ret or (None, 0)
def markClean(self, fnames):
for fname in fnames:
self.db.execute(
"update media set dirty=0 where fname=?", fname)
def syncDelete(self, fname):
path = os.path.join(self.dir(), fname)
if os.path.exists(path):
os.unlink(path)
self.db.execute("delete from media where fname=?", fname)
def mediaCount(self):
return self.db.scalar(
"select count() from media where csum is not null")
def dirtyCount(self):
return self.db.scalar(
"select count() from media where dirty=1")
def forceResync(self):
self.db.execute("delete from media")
self.db.execute("update meta set lastUsn=0,dirMod=0")
self.db.commit()
self.db.setAutocommit(True)
self.db.execute("vacuum")
self.db.execute("analyze")
self.db.setAutocommit(False)
# Media syncing: zips