log imported card/media counts

This commit is contained in:
Damien Elmes 2011-11-25 14:13:14 +09:00
parent b5c0b1f2c7
commit faf2f061a8
3 changed files with 11 additions and 2 deletions

View file

@ -30,4 +30,3 @@ class Anki1Importer(Anki2Importer):
self.deckPrefix = os.path.basename(self.file).replace(".anki", "") self.deckPrefix = os.path.basename(self.file).replace(".anki", "")
self.file = deck.path self.file = deck.path
Anki2Importer.run(self, mdir) Anki2Importer.run(self, mdir)

View file

@ -5,6 +5,7 @@
from anki import Collection from anki import Collection
from anki.utils import intTime from anki.utils import intTime
from anki.importing.base import Importer from anki.importing.base import Importer
from anki.lang import _
# #
# Import a .anki2 file into the current collection. Used for migration from # Import a .anki2 file into the current collection. Used for migration from
@ -175,6 +176,7 @@ class Anki2Importer(Importer):
cards = [] cards = []
revlog = [] revlog = []
print "fixme: need to check schema issues in card import" print "fixme: need to check schema issues in card import"
cnt = 0
for card in self.src.db.execute( for card in self.src.db.execute(
"select f.guid, f.mid, c.* from cards c, notes f " "select f.guid, f.mid, c.* from cards c, notes f "
"where c.nid = f.id"): "where c.nid = f.id"):
@ -208,17 +210,21 @@ class Anki2Importer(Importer):
rev = list(rev) rev = list(rev)
rev[1] = card[0] rev[1] = card[0]
revlog.append(rev) revlog.append(rev)
cnt += 1
# apply # apply
self.dst.db.executemany(""" self.dst.db.executemany("""
insert into cards values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", cards) insert into cards values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", cards)
self.dst.db.executemany(""" self.dst.db.executemany("""
insert into revlog values (?,?,?,?,?,?,?,?,?)""", revlog) insert into revlog values (?,?,?,?,?,?,?,?,?)""", revlog)
self.log.append(_("%d cards imported.") % cnt)
# Media # Media
###################################################################### ######################################################################
def _importMedia(self): def _importMedia(self):
self.src.media.copyTo(self.dst.media.dir()) self.log.append(
_("%d media imported.") %
self.src.media.copyTo(self.dst.media.dir()))
# Post-import cleanup # Post-import cleanup
###################################################################### ######################################################################

View file

@ -172,14 +172,18 @@ If the same name exists, compare checksums."""
# if necessary # if necessary
def copyTo(self, rdir): def copyTo(self, rdir):
"Copy media to RDIR. Return number of files copied."
ldir = self.dir() ldir = self.dir()
if not os.path.exists(ldir): if not os.path.exists(ldir):
return return
cnt = 0
for f in os.listdir(ldir): for f in os.listdir(ldir):
src = os.path.join(ldir, f) src = os.path.join(ldir, f)
dst = os.path.join(rdir, f) dst = os.path.join(rdir, f)
if not os.path.exists(dst): if not os.path.exists(dst):
shutil.copy2(src, dst) shutil.copy2(src, dst)
cnt += 1
return cnt
# Tracking changes (public) # Tracking changes (public)
########################################################################## ##########################################################################