mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
Merge branch 'master' of https://github.com/dae/anki
This commit is contained in:
commit
f491d79d28
3 changed files with 31 additions and 21 deletions
|
@ -2,12 +2,15 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import stat
|
import stat
|
||||||
import datetime
|
import datetime
|
||||||
import copy
|
import copy
|
||||||
|
import traceback
|
||||||
|
|
||||||
from anki.lang import _, ngettext
|
from anki.lang import _, ngettext
|
||||||
from anki.utils import ids2str, fieldChecksum, stripHTML, \
|
from anki.utils import ids2str, fieldChecksum, stripHTML, \
|
||||||
|
@ -48,9 +51,12 @@ defaultConf = {
|
||||||
# this is initialized by storage.Collection
|
# this is initialized by storage.Collection
|
||||||
class _Collection(object):
|
class _Collection(object):
|
||||||
|
|
||||||
|
debugLog = False
|
||||||
|
|
||||||
def __init__(self, db, server=False):
|
def __init__(self, db, server=False):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.path = db._path
|
self.path = db._path
|
||||||
|
self._openLog()
|
||||||
self.log(self.path, anki.version)
|
self.log(self.path, anki.version)
|
||||||
self.server = server
|
self.server = server
|
||||||
self._lastSave = time.time()
|
self._lastSave = time.time()
|
||||||
|
@ -773,4 +779,25 @@ and queue = 0""", intTime(), self.usn())
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def log(self, *args, **kwargs):
|
def log(self, *args, **kwargs):
|
||||||
runHook("log", args, kwargs)
|
if not self.debugLog:
|
||||||
|
return
|
||||||
|
def customRepr(x):
|
||||||
|
if isinstance(x, basestring):
|
||||||
|
return x
|
||||||
|
return pprint.pformat(x)
|
||||||
|
path, num, fn, y = traceback.extract_stack(
|
||||||
|
limit=2+kwargs.get("stack", 0))[0]
|
||||||
|
buf = u"[%s] %s:%s(): %s" % (intTime(), os.path.basename(path), fn,
|
||||||
|
", ".join([customRepr(x) for x in args]))
|
||||||
|
self._logHnd.write(buf.encode("utf8") + "\n")
|
||||||
|
if os.environ.get("ANKIDEV"):
|
||||||
|
print buf
|
||||||
|
|
||||||
|
def _openLog(self):
|
||||||
|
if not self.debugLog:
|
||||||
|
return
|
||||||
|
lpath = re.sub("\.anki2$", ".log", self.path)
|
||||||
|
self._logHnd = open(lpath, "ab")
|
||||||
|
|
||||||
|
def _closeLog(self):
|
||||||
|
self._logHnd = None
|
||||||
|
|
|
@ -1366,7 +1366,7 @@ usn=:usn, mod=:mod, factor=:fact where id=:id and odid=0 and queue >=0""",
|
||||||
% sids)
|
% sids)
|
||||||
# reset all cards
|
# reset all cards
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set reps=0,lapses=0,odid=0,odue=0"
|
"update cards set reps=0,lapses=0,odid=0,odue=0,queue=0"
|
||||||
" where id in %s" % sids
|
" where id in %s" % sids
|
||||||
)
|
)
|
||||||
# and forget any non-new cards, changing their due numbers
|
# and forget any non-new cards, changing their due numbers
|
||||||
|
|
21
aqt/main.py
21
aqt/main.py
|
@ -3,7 +3,6 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pprint
|
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -32,6 +31,8 @@ class AnkiQt(QMainWindow):
|
||||||
self.state = "startup"
|
self.state = "startup"
|
||||||
aqt.mw = self
|
aqt.mw = self
|
||||||
self.app = app
|
self.app = app
|
||||||
|
from anki.collection import _Collection
|
||||||
|
_Collection.debugLog = True
|
||||||
if isWin:
|
if isWin:
|
||||||
self._xpstyle = QStyleFactory.create("WindowsXP")
|
self._xpstyle = QStyleFactory.create("WindowsXP")
|
||||||
self.app.setStyle(self._xpstyle)
|
self.app.setStyle(self._xpstyle)
|
||||||
|
@ -864,7 +865,6 @@ Difference to correct time: %s.""") % diffText
|
||||||
def setupHooks(self):
|
def setupHooks(self):
|
||||||
addHook("modSchema", self.onSchemaMod)
|
addHook("modSchema", self.onSchemaMod)
|
||||||
addHook("remNotes", self.onRemNotes)
|
addHook("remNotes", self.onRemNotes)
|
||||||
addHook("log", self.onLog)
|
|
||||||
|
|
||||||
# Log note deletion
|
# Log note deletion
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -882,23 +882,6 @@ Difference to correct time: %s.""") % diffText
|
||||||
f.write(("\t".join([str(id), str(mid)] + fields)).encode("utf8"))
|
f.write(("\t".join([str(id), str(mid)] + fields)).encode("utf8"))
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
|
||||||
# Debug logging
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
def onLog(self, args, kwargs):
|
|
||||||
def customRepr(x):
|
|
||||||
if isinstance(x, basestring):
|
|
||||||
return x
|
|
||||||
return pprint.pformat(x)
|
|
||||||
path, num, fn, y = traceback.extract_stack(
|
|
||||||
limit=4+kwargs.get("stack", 0))[0]
|
|
||||||
buf = u"[%s] %s:%s(): %s" % (intTime(), os.path.basename(path), fn,
|
|
||||||
", ".join([customRepr(x) for x in args]))
|
|
||||||
lpath = re.sub("\.anki2$", ".log", self.pm.collectionPath())
|
|
||||||
open(lpath, "ab").write(buf.encode("utf8") + "\n")
|
|
||||||
if os.environ.get("ANKIDEV"):
|
|
||||||
print buf
|
|
||||||
|
|
||||||
# Schema modifications
|
# Schema modifications
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue