mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
log imported card/media counts
This commit is contained in:
parent
b5c0b1f2c7
commit
faf2f061a8
3 changed files with 11 additions and 2 deletions
|
@ -30,4 +30,3 @@ class Anki1Importer(Anki2Importer):
|
|||
self.deckPrefix = os.path.basename(self.file).replace(".anki", "")
|
||||
self.file = deck.path
|
||||
Anki2Importer.run(self, mdir)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
from anki import Collection
|
||||
from anki.utils import intTime
|
||||
from anki.importing.base import Importer
|
||||
from anki.lang import _
|
||||
|
||||
#
|
||||
# Import a .anki2 file into the current collection. Used for migration from
|
||||
|
@ -175,6 +176,7 @@ class Anki2Importer(Importer):
|
|||
cards = []
|
||||
revlog = []
|
||||
print "fixme: need to check schema issues in card import"
|
||||
cnt = 0
|
||||
for card in self.src.db.execute(
|
||||
"select f.guid, f.mid, c.* from cards c, notes f "
|
||||
"where c.nid = f.id"):
|
||||
|
@ -208,17 +210,21 @@ class Anki2Importer(Importer):
|
|||
rev = list(rev)
|
||||
rev[1] = card[0]
|
||||
revlog.append(rev)
|
||||
cnt += 1
|
||||
# apply
|
||||
self.dst.db.executemany("""
|
||||
insert into cards values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", cards)
|
||||
self.dst.db.executemany("""
|
||||
insert into revlog values (?,?,?,?,?,?,?,?,?)""", revlog)
|
||||
self.log.append(_("%d cards imported.") % cnt)
|
||||
|
||||
# Media
|
||||
######################################################################
|
||||
|
||||
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
|
||||
######################################################################
|
||||
|
|
|
@ -172,14 +172,18 @@ If the same name exists, compare checksums."""
|
|||
# if necessary
|
||||
|
||||
def copyTo(self, rdir):
|
||||
"Copy media to RDIR. Return number of files copied."
|
||||
ldir = self.dir()
|
||||
if not os.path.exists(ldir):
|
||||
return
|
||||
cnt = 0
|
||||
for f in os.listdir(ldir):
|
||||
src = os.path.join(ldir, f)
|
||||
dst = os.path.join(rdir, f)
|
||||
if not os.path.exists(dst):
|
||||
shutil.copy2(src, dst)
|
||||
cnt += 1
|
||||
return cnt
|
||||
|
||||
# Tracking changes (public)
|
||||
##########################################################################
|
||||
|
|
Loading…
Reference in a new issue