mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 00:36:38 -04:00
import media too
This commit is contained in:
parent
83f8ef45ff
commit
b242b06052
3 changed files with 20 additions and 3 deletions
|
@ -39,6 +39,7 @@ class Anki2Importer(Importer):
|
||||||
self._prepareModels()
|
self._prepareModels()
|
||||||
self._importFacts()
|
self._importFacts()
|
||||||
self._importCards()
|
self._importCards()
|
||||||
|
self._importMedia()
|
||||||
|
|
||||||
# Facts
|
# Facts
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -184,3 +185,9 @@ class Anki2Importer(Importer):
|
||||||
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)
|
||||||
|
|
||||||
|
# Media
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
def _importMedia(self):
|
||||||
|
self.src.media.copyTo(self.dst.media.dir())
|
||||||
|
|
|
@ -161,6 +161,17 @@ If the same name exists, compare checksums."""
|
||||||
files.add(f)
|
files.add(f)
|
||||||
return files
|
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)
|
# Tracking changes (public)
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ def test_import():
|
||||||
srcFacts = src.factCount()
|
srcFacts = src.factCount()
|
||||||
srcCards = src.cardCount()
|
srcCards = src.cardCount()
|
||||||
srcRev = src.db.scalar("select count() from revlog")
|
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()
|
src.close()
|
||||||
# create a new empty deck
|
# create a new empty deck
|
||||||
dst = getEmptyDeck()
|
dst = getEmptyDeck()
|
||||||
|
@ -61,6 +63,3 @@ def test_import():
|
||||||
imp.run()
|
imp.run()
|
||||||
check()
|
check()
|
||||||
print dst.path
|
print dst.path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue