mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Merge pull request #114 from timrae/export-deck-media
Don't include media files with _ unless they are referenced in model
This commit is contained in:
commit
965b3055a9
1 changed files with 16 additions and 1 deletions
|
@ -203,7 +203,12 @@ class AnkiExporter(Exporter):
|
||||||
if self.mediaDir:
|
if self.mediaDir:
|
||||||
for fname in os.listdir(self.mediaDir):
|
for fname in os.listdir(self.mediaDir):
|
||||||
if fname.startswith("_"):
|
if fname.startswith("_"):
|
||||||
|
# Scan all models in mids for reference to fname
|
||||||
|
for m in self.src.models.all():
|
||||||
|
if int(m['id']) in mids:
|
||||||
|
if self._modelHasMedia(m, fname):
|
||||||
media[fname] = True
|
media[fname] = True
|
||||||
|
break
|
||||||
self.mediaFiles = media.keys()
|
self.mediaFiles = media.keys()
|
||||||
self.dst.crt = self.src.crt
|
self.dst.crt = self.src.crt
|
||||||
# todo: tags?
|
# todo: tags?
|
||||||
|
@ -220,6 +225,16 @@ class AnkiExporter(Exporter):
|
||||||
def removeSystemTags(self, tags):
|
def removeSystemTags(self, tags):
|
||||||
return self.src.tags.remFromStr("marked leech", tags)
|
return self.src.tags.remFromStr("marked leech", tags)
|
||||||
|
|
||||||
|
def _modelHasMedia(self, model, fname):
|
||||||
|
# First check the styling
|
||||||
|
if fname in model["css"]:
|
||||||
|
return True
|
||||||
|
# If no reference to fname then check the templates as well
|
||||||
|
for t in model["tmpls"]:
|
||||||
|
if fname in t["qfmt"] or fname in t["afmt"]:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
# Packaged Anki decks
|
# Packaged Anki decks
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue