Externalize deck name and delete file.
--- a/Makefile Sat Nov 12 12:12:04 2016 +0200
+++ b/Makefile Sat Nov 12 12:32:13 2016 +0200
@@ -529,13 +529,13 @@
anki: $(SRS_ANKI_FILES)
dist/anki/%.apkg: %.gadict %.del py/gadict.py py/gadict_srs_anki.py $(FREQLIST_DEP) $(MAKEFILE_LIST) | dist/anki/
- PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py -rich $(FREQLIST_OPT) $< $@
+ PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py -name=$* -rich -delfile=$*.del $(FREQLIST_OPT) $< $@
dist/anki/gadict_voa.apkg: gadict_voa.gadict py/gadict.py py/gadict_srs_anki.py $(VOA_FREQLIST_DEP) $(MAKEFILE_LIST) | dist/anki/
- PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py $(VOA_FREQLIST_OPT) $< $@
+ PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py -name=gadict_voa $(VOA_FREQLIST_OPT) $< $@
dist/anki/%.apkg: %.gadict py/gadict.py py/gadict_srs_anki.py $(FREQLIST_DEP) $(MAKEFILE_LIST) | dist/anki/
- PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py -rich $(FREQLIST_OPT) $< $@
+ PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py -name=$* -rich -delfile=$*.del $(FREQLIST_OPT) $< $@
dist/srs/gadict_en-ru+uk.tab.txt: gadict_en-ru+uk.gadict py/gadict.py py/gadict_srs_tab.py $(MAKEFILE_LIST) | dist/srs/
python3 -B py/gadict_srs_tab.py $< $@ -lang:ru,uk
--- a/py/gadict_srs_anki.py Sat Nov 12 12:12:04 2016 +0200
+++ b/py/gadict_srs_anki.py Sat Nov 12 12:32:13 2016 +0200
@@ -16,14 +16,18 @@
FINAME = None
FONAME = None
+FDELNAME = None
+NAME = None
LANGS = None
FREQ_SOURCES = []
RICH_MODE = False
+ARG_NAME_RE = regex.compile("-name=(.+)")
# -lang:ru,uk
ARG_LANG_RE = regex.compile("-lang:(.+)")
# -freq:var:TAG=FILE or -freq:freq:TAG=FILE
ARG_FREQ_RE = regex.compile("-freq:(freq|var):([^=]+)=(.+)")
+ARG_DELFILE_RE = regex.compile("-delfile=(.+)")
look_for_files = False
for idx in range(1, len(sys.argv)):
@@ -32,6 +36,10 @@
look_for_files = True
continue
if not look_for_files:
+ m = ARG_NAME_RE.match(arg)
+ if m:
+ NAME = m.group(1)
+ continue
m = ARG_LANG_RE.match(arg)
if m:
LANGS = set(m.group(1).split(","))
@@ -54,6 +62,10 @@
wlist = parser.parse()
FREQ_SOURCES.append((tag, set(wlist)))
continue
+ m = ARG_DELFILE_RE.match(arg)
+ if m:
+ FDELNAME = m.group(1)
+ continue
if arg == "-rich":
RICH_MODE = True
continue
@@ -67,7 +79,8 @@
continue
raise Exception("Unnecessary argument: '{:s}'".format(arg))
-
+if not FINAME:
+ raise Exception("Input file name is not passed...")
FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8")
PARSER = gadict.Parser()
@@ -92,19 +105,20 @@
if FONAME is None:
- raise Exception('Missing output file name')
+ raise Exception("Output file name is not passed...")
# Looks like anki libs change working directory to media directory of current deck
# Therefore absolute path should be stored before creating temporary deck
FONAME = os.path.abspath(FONAME)
-FBASENAME, _ = os.path.splitext(os.path.basename(FONAME))
TMPDIR = tempfile.mkdtemp(dir = os.path.dirname(FONAME))
-try:
- FDEL = io.open(FBASENAME+".del", mode='r', buffering=1, encoding="utf-8")
-except:
+if not NAME:
+ NAME, _ = os.path.splitext(os.path.basename(FINAME))
+
+if FDELNAME:
+ FDEL = io.open(FDELNAME, mode='r', buffering=1, encoding="utf-8")
+else:
FDEL = None
-
import hashlib
import anki
@@ -299,7 +313,7 @@
buf.append("</div>")
try:
- builder = AnkiDbBuilder(TMPDIR, FBASENAME)
+ builder = AnkiDbBuilder(TMPDIR, NAME)
for identity in FDEL or []:
identity = identity.strip()