New command line format for passing language list.
--- a/Makefile Tue Nov 08 17:44:04 2016 +0200
+++ b/Makefile Tue Nov 08 18:08:02 2016 +0200
@@ -483,15 +483,15 @@
# -B suppress __pycache__ dir
dist/dictd/gadict_en-ru.c5: gadict_en-ru+uk.gadict py/gadict.py py/gadict_c5.py | dist/dictd/
- python3 -B py/gadict_c5.py $< $@ ru
+ python3 -B py/gadict_c5.py $< $@ -lang:ru
echo "gadict En-Ru"> dist/dictd/gadict_en-ru.c5.name
dist/dictd/gadict_en-uk.c5: gadict_en-ru+uk.gadict py/gadict.py py/gadict_c5.py | dist/dictd/
- python3 -B py/gadict_c5.py $< $@ uk
+ python3 -B py/gadict_c5.py $< $@ -lang:uk
echo "gadict En-Uk"> dist/dictd/gadict_en-uk.c5.name
dist/dictd/gadict_voa.c5: gadict_voa.gadict py/gadict.py py/gadict_c5.py | dist/dictd/
- python3 -B py/gadict_c5.py $< $@ en
+ python3 -B py/gadict_c5.py $< $@ -lang:en
dist/dictd/%.c5: %.gadict py/gadict.py py/gadict_c5.py | dist/dictd/
python3 -B py/gadict_c5.py $< $@
@@ -512,7 +512,7 @@
PYTHONPATH=/usr/share/anki: python -B py/gadict_srs_anki.py $< $@
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 $< $@ ru,uk
+ python3 -B py/gadict_srs_tab.py $< $@ -lang:ru,uk
dist/srs/%.tab.txt: %.gadict py/gadict.py py/gadict_srs_tab.py $(MAKEFILE_LIST) | dist/srs/
python3 -B py/gadict_srs_tab.py $< $@
--- a/py/gadict_c5.py Tue Nov 08 17:44:04 2016 +0200
+++ b/py/gadict_c5.py Tue Nov 08 18:08:02 2016 +0200
@@ -4,19 +4,51 @@
import io
import sys
import codecs
+import regex
import gadict
FINAME = None
FONAME = None
-if len(sys.argv) >= 2:
- FINAME = sys.argv[1]
-if len(sys.argv) >= 3:
- FONAME = sys.argv[2]
LANGS = None
-if len(sys.argv) >= 4:
- LANGS = set(sys.argv[3].split(","))
+
+# -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):([^=]+)=(.+)")
+
+look_for_files = False
+for idx in range(1, len(sys.argv)):
+ arg = sys.argv[idx]
+ if arg == "--":
+ look_for_files = True
+ continue
+ if not look_for_files:
+ m = ARG_LANG_RE.match(arg)
+ if m:
+ LANGS = set(m.group(1).split(","))
+ for lang in LANGS:
+ if len(lang) != 2:
+ raise Exception("Incorrect language specification: '{:s}'".format(arg))
+ continue
+ m = ARG_FREQ_RE.match(arg)
+ if m:
+ LANGS = set(arg.split(","))
+ for lang in LANGS:
+ if len(lang) != 2:
+ raise Exception("Incorrect language specification: '{:s}'".format(arg))
+ continue
+ if arg.startswith("-"):
+ raise Exception("Unsupported option format: '{:s}'".format(arg))
+ if not FINAME:
+ FINAME = arg
+ continue
+ if not FONAME:
+ FONAME = arg
+ continue
+ raise Exception("Unnecessary argument: '{:s}'".format(arg))
+
FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8")
--- a/py/gadict_srs_anki.py Tue Nov 08 17:44:04 2016 +0200
+++ b/py/gadict_srs_anki.py Tue Nov 08 18:08:02 2016 +0200
@@ -7,19 +7,51 @@
import tempfile
import shutil
import signal
+import regex
import gadict
FINAME = None
FONAME = None
-if len(sys.argv) >= 2:
- FINAME = sys.argv[1]
-if len(sys.argv) >= 3:
- FONAME = sys.argv[2]
LANGS = None
-if len(sys.argv) >= 4:
- LANGS = set(sys.argv[3].split(","))
+
+# -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):([^=]+)=(.+)")
+
+look_for_files = False
+for idx in range(1, len(sys.argv)):
+ arg = sys.argv[idx]
+ if arg == "--":
+ look_for_files = True
+ continue
+ if not look_for_files:
+ m = ARG_LANG_RE.match(arg)
+ if m:
+ LANGS = set(m.group(1).split(","))
+ for lang in LANGS:
+ if len(lang) != 2:
+ raise Exception("Incorrect language specification: '{:s}'".format(arg))
+ continue
+ m = ARG_FREQ_RE.match(arg)
+ if m:
+ LANGS = set(arg.split(","))
+ for lang in LANGS:
+ if len(lang) != 2:
+ raise Exception("Incorrect language specification: '{:s}'".format(arg))
+ continue
+ if arg.startswith("-"):
+ raise Exception("Unsupported option format: '{:s}'".format(arg))
+ if not FINAME:
+ FINAME = arg
+ continue
+ if not FONAME:
+ FONAME = arg
+ continue
+ raise Exception("Unnecessary argument: '{:s}'".format(arg))
+
FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8")