diff --git a/anki/collection.py b/anki/collection.py index 4f23d765e..4b6bb7c01 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -51,9 +51,8 @@ defaultConf = { # this is initialized by storage.Collection class _Collection(object): - debugLog = False - - def __init__(self, db, server=False): + def __init__(self, db, server=False, log=False): + self._debugLog = log self.db = db self.path = db._path self._openLog() @@ -783,7 +782,7 @@ and queue = 0""", intTime(), self.usn()) ########################################################################## def log(self, *args, **kwargs): - if not self.debugLog: + if not self._debugLog: return def customRepr(x): if isinstance(x, basestring): @@ -798,7 +797,7 @@ and queue = 0""", intTime(), self.usn()) print buf def _openLog(self): - if not self.debugLog: + if not self._debugLog: return lpath = re.sub("\.anki2$", ".log", self.path) self._logHnd = open(lpath, "ab") diff --git a/anki/storage.py b/anki/storage.py index bd2d9a1b7..d83fef1ca 100644 --- a/anki/storage.py +++ b/anki/storage.py @@ -2,7 +2,10 @@ # Copyright: Damien Elmes # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import os, copy, re +import os +import copy +import re + from anki.lang import _ from anki.utils import intTime, json from anki.db import DB @@ -11,7 +14,8 @@ from anki.consts import * from anki.stdmodels import addBasicModel, addClozeModel, addForwardReverse, \ addForwardOptionalReverse -def Collection(path, lock=True, server=False, sync=True): + +def Collection(path, lock=True, server=False, sync=True, log=False): "Open a new or existing collection. Path must be unicode." assert path.endswith(".anki2") path = os.path.abspath(path) @@ -33,7 +37,7 @@ def Collection(path, lock=True, server=False, sync=True): else: db.execute("pragma synchronous = off") # add db to col and do any remaining upgrades - col = _Collection(db, server) + col = _Collection(db, server, log) if ver < SCHEMA_VERSION: _upgrade(col, ver) elif create: diff --git a/aqt/main.py b/aqt/main.py index a8133f561..2b0f840f8 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -31,8 +31,6 @@ class AnkiQt(QMainWindow): self.state = "startup" aqt.mw = self self.app = app - from anki.collection import _Collection - _Collection.debugLog = True if isWin: self._xpstyle = QStyleFactory.create("WindowsXP") self.app.setStyle(self._xpstyle) @@ -270,7 +268,7 @@ To import into a password protected profile, please open the profile before atte def loadCollection(self): self.hideSchemaMsg = True try: - self.col = Collection(self.pm.collectionPath()) + self.col = Collection(self.pm.collectionPath(), log=True) except anki.db.Error: # move back to profile manager showWarning("""\ diff --git a/aqt/sync.py b/aqt/sync.py index 0d6cc51e5..8fc9bb1f1 100644 --- a/aqt/sync.py +++ b/aqt/sync.py @@ -280,7 +280,7 @@ class SyncThread(QThread): self.syncMsg = "" self.uname = "" try: - self.col = Collection(self.path) + self.col = Collection(self.path, log=True) except: self.fireEvent("corrupt") return