py/gadict_srs_anki.py
changeset 674 fe57401d8109
parent 673 ca1d4a6e201b
child 675 f3465e45b958
--- 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()