From 0fbc94c186553893ee7f64ce05f9cbb1f513cb85 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 18 Oct 2013 14:19:35 +0900 Subject: [PATCH] more logging tweaks - disable in browser, note.cards() - in getCard() we want the calling frame, not us - log current day - show card/note id in card info stat --- anki/collection.py | 9 +++++---- anki/notes.py | 2 +- anki/sched.py | 1 + anki/stats.py | 8 +++++++- aqt/browser.py | 2 +- aqt/main.py | 5 +++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/anki/collection.py b/anki/collection.py index aaabcf160..2af345bb9 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -205,9 +205,10 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""", # Object creation helpers ########################################################################## - def getCard(self, id): + def getCard(self, id, log=True): c = anki.cards.Card(self, id) - self.log(c) + if log: + self.log(c, stack=1) return c def getNote(self, id): @@ -774,5 +775,5 @@ and queue = 0""", intTime(), self.usn()) # Logging ########################################################################## - def log(self, *args): - runHook("log", args) + def log(self, *args, **kwargs): + runHook("log", args, kwargs) diff --git a/anki/notes.py b/anki/notes.py index 16be73e0a..d1f54a7b6 100644 --- a/anki/notes.py +++ b/anki/notes.py @@ -69,7 +69,7 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""", return joinFields(self.fields) def cards(self): - return [self.col.getCard(id) for id in self.col.db.list( + return [self.col.getCard(id, log=False) for id in self.col.db.list( "select id from cards where nid = ? order by ord", self.id)] def model(self): diff --git a/anki/sched.py b/anki/sched.py index 485424e3c..81818033c 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -1123,6 +1123,7 @@ did = ?, queue = %s, due = ?, mod = ?, usn = ? where id = ?""" % queue, data) self.today = int((time.time() - self.col.crt) // 86400) # end of day cutoff self.dayCutoff = self.col.crt + (self.today+1)*86400 + self.col.log(self.today, self.dayCutoff) # update all daily counts, but don't save decks to prevent needless # conflicts. we'll save on card answer instead def update(g): diff --git a/anki/stats.py b/anki/stats.py index 22eb3a728..8171a4ae6 100644 --- a/anki/stats.py +++ b/anki/stats.py @@ -3,11 +3,15 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from __future__ import division -import time, datetime, json +import time +import datetime +import json + import anki.js from anki.utils import fmtTimeSpan, ids2str from anki.lang import _, ngettext + # Card stats ########################################################################## @@ -56,6 +60,8 @@ class CardStats(object): self.addLine(_("Card Type"), c.template()['name']) self.addLine(_("Note Type"), c.model()['name']) self.addLine(_("Deck"), self.col.decks.name(c.did)) + self.addLine(_("Note ID"), c.nid) + self.addLine(_("Card ID"), c.id) self.txt += "" return self.txt diff --git a/aqt/browser.py b/aqt/browser.py index 91c4b5644..defe4fce9 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -45,7 +45,7 @@ class DataModel(QAbstractTableModel): def getCard(self, index): id = self.cards[index.row()] if not id in self.cardObjs: - self.cardObjs[id] = self.col.getCard(id) + self.cardObjs[id] = self.col.getCard(id, log=False) return self.cardObjs[id] def refreshNote(self, note): diff --git a/aqt/main.py b/aqt/main.py index cb7d58ac1..6efd166ff 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -860,12 +860,13 @@ the problem and restart Anki.""") # Debug logging ########################################################################## - def onLog(self, args): + 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)[0] + path, num, fn, y = traceback.extract_stack( + limit=4+kwargs.get("stack", 0))[0] buf = "[%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())