import media too

This commit is contained in:
Damien Elmes 2011-10-21 07:53:22 +09:00
parent 83f8ef45ff
commit b242b06052
3 changed files with 20 additions and 3 deletions

View file

@ -39,6 +39,7 @@ class Anki2Importer(Importer):
self._prepareModels()
self._importFacts()
self._importCards()
self._importMedia()
# Facts
######################################################################
@ -184,3 +185,9 @@ class Anki2Importer(Importer):
insert into cards values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", cards)
self.dst.db.executemany("""
insert into revlog values (?,?,?,?,?,?,?,?,?)""", revlog)
# Media
######################################################################
def _importMedia(self):
self.src.media.copyTo(self.dst.media.dir())

View file

@ -161,6 +161,17 @@ If the same name exists, compare checksums."""
files.add(f)
return files
# Copying on import
##########################################################################
def copyTo(self, rdir):
ldir = self.dir()
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)
# Tracking changes (public)
##########################################################################

View file

@ -39,6 +39,8 @@ def test_import():
srcFacts = src.factCount()
srcCards = src.cardCount()
srcRev = src.db.scalar("select count() from revlog")
# add a media file for testing
open(os.path.join(src.media.dir(), "foo.jpg"), "w").write("foo")
src.close()
# create a new empty deck
dst = getEmptyDeck()
@ -61,6 +63,3 @@ def test_import():
imp.run()
check()
print dst.path