本文整理汇总了Python中anki.media.MediaManager.close方法的典型用法代码示例。如果您正苦于以下问题:Python MediaManager.close方法的具体用法?Python MediaManager.close怎么用?Python MediaManager.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.media.MediaManager
的用法示例。
在下文中一共展示了MediaManager.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Collection
# 需要导入模块: from anki.media import MediaManager [as 别名]
# 或者: from anki.media.MediaManager import close [as 别名]
class _Collection(object):
def __init__(self, db, server=False):
self.db = db
self.path = db._path
self.server = server
self._lastSave = time.time()
self.clearUndo()
self.media = MediaManager(self)
self.models = ModelManager(self)
self.decks = DeckManager(self)
self.tags = TagManager(self)
self.load()
if not self.crt:
d = datetime.datetime.today()
d -= datetime.timedelta(hours=4)
d = datetime.datetime(d.year, d.month, d.day)
d += datetime.timedelta(hours=4)
self.crt = int(time.mktime(d.timetuple()))
self.undoEnabled = False
self.sessionStartReps = 0
self.sessionStartTime = 0
self.lastSessionStart = 0
self._stdSched = Scheduler(self)
self.sched = self._stdSched
# check for improper shutdown
self.cleanup()
def name(self):
n = os.path.splitext(os.path.basename(self.path))[0]
return n
# DB-related
##########################################################################
def load(self):
(self.crt,
self.mod,
self.scm,
self.dty,
self._usn,
self.ls,
self.conf,
models,
decks,
dconf,
tags) = self.db.first("""
select crt, mod, scm, dty, usn, ls,
conf, models, decks, dconf, tags from col""")
self.conf = simplejson.loads(self.conf)
self.models.load(models)
self.decks.load(decks, dconf)
self.tags.load(tags)
def setMod(self):
"""Mark DB modified.
DB operations and the deck/tag/model managers do this automatically, so this
is only necessary if you modify properties of this object or the conf dict."""
self.db.mod = True
def flush(self, mod=None):
"Flush state to DB, updating mod time."
self.mod = intTime(1000) if mod is None else mod
self.db.execute(
"""update col set
crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
self.crt, self.mod, self.scm, self.dty,
self._usn, self.ls, simplejson.dumps(self.conf))
def save(self, name=None, mod=None):
"Flush, commit DB, and take out another write lock."
# let the managers conditionally flush
self.models.flush()
self.decks.flush()
self.tags.flush()
# and flush deck + bump mod if db has been changed
if self.db.mod:
self.flush(mod=mod)
self.db.commit()
self.lock()
self.db.mod = False
self._markOp(name)
self._lastSave = time.time()
def autosave(self):
"Save if 5 minutes has passed since last save."
if time.time() - self._lastSave > 300:
self.save()
def lock(self):
# make sure we don't accidentally bump mod time
mod = self.db.mod
self.db.execute("update col set mod=mod")
self.db.mod = mod
def close(self, save=True):
"Disconnect from DB."
if self.db:
self.cleanup()
#.........这里部分代码省略.........
示例2: _Collection
# 需要导入模块: from anki.media import MediaManager [as 别名]
# 或者: from anki.media.MediaManager import close [as 别名]
class _Collection(object):
def __init__(self, db, server=False, log=False):
self._debugLog = log
self.db = db
self.path = db._path
self._openLog()
self.log(self.path, anki.version)
self.server = server
self._lastSave = time.time()
self.clearUndo()
self.media = MediaManager(self, server)
self.models = ModelManager(self)
self.decks = DeckManager(self)
self.tags = TagManager(self)
self.load()
if not self.crt:
d = datetime.datetime.today()
d -= datetime.timedelta(hours=4)
d = datetime.datetime(d.year, d.month, d.day)
d += datetime.timedelta(hours=4)
self.crt = int(time.mktime(d.timetuple()))
self.sched = Scheduler(self)
if not self.conf.get("newBury", False):
self.conf['newBury'] = True
self.setMod()
def name(self):
n = os.path.splitext(os.path.basename(self.path))[0]
return n
# DB-related
##########################################################################
def load(self):
(self.crt,
self.mod,
self.scm,
self.dty, # no longer used
self._usn,
self.ls,
self.conf,
models,
decks,
dconf,
tags) = self.db.first("""
select crt, mod, scm, dty, usn, ls,
conf, models, decks, dconf, tags from col""")
self.conf = json.loads(self.conf)
self.models.load(models)
self.decks.load(decks, dconf)
self.tags.load(tags)
def setMod(self):
"""Mark DB modified.
DB operations and the deck/tag/model managers do this automatically, so this
is only necessary if you modify properties of this object or the conf dict."""
self.db.mod = True
def flush(self, mod=None):
"Flush state to DB, updating mod time."
self.mod = intTime(1000) if mod is None else mod
self.db.execute(
"""update col set
crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
self.crt, self.mod, self.scm, self.dty,
self._usn, self.ls, json.dumps(self.conf))
def save(self, name=None, mod=None):
"Flush, commit DB, and take out another write lock."
# let the managers conditionally flush
self.models.flush()
self.decks.flush()
self.tags.flush()
# and flush deck + bump mod if db has been changed
if self.db.mod:
self.flush(mod=mod)
self.db.commit()
self.lock()
self.db.mod = False
self._markOp(name)
self._lastSave = time.time()
def autosave(self):
"Save if 5 minutes has passed since last save."
if time.time() - self._lastSave > 300:
self.save()
def lock(self):
# make sure we don't accidentally bump mod time
mod = self.db.mod
self.db.execute("update col set mod=mod")
self.db.mod = mod
def close(self, save=True):
"Disconnect from DB."
if self.db:
if save:
self.save()
#.........这里部分代码省略.........