plint

French poetry validator
git clone https://a3nm.net/git/plint/
Log | Files | Refs | README

commit e5a308e3c20df51b22b40f0b696d544558e0c8ee
parent 51bb1f5b98f0752965f654fc0bf2f878f0c5c448
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sun, 27 Jul 2014 11:39:32 +0200

use custom diaeresis file

Diffstat:
diaeresis.py | 19++++++++++++++-----
plint.py | 16++++++++++++----
2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/diaeresis.py b/diaeresis.py @@ -6,10 +6,14 @@ import os import json import sys -f = open(os.path.join(os.path.dirname( - os.path.realpath(__file__)), 'diaeresis.json')) -trie = json.load(f) -f.close() +trie = None + +def load_diaeresis(fname): + global trie + f = open(os.path.join(os.path.dirname( + os.path.realpath(__file__)), fname)) + trie = json.load(f) + f.close() def do_lookup(trie, key): if len(key) == 0 or (key[0] not in trie[1].keys()): @@ -25,7 +29,12 @@ def wrap_lookup(line): if __name__ == '__main__': if len(sys.argv) > 1: - for arg in sys.argv[1:]: + load_diaeresis(sys.argv[1]) + else: + load_diaeresis("diaeresis.json") + + if len(sys.argv) > 2: + for arg in sys.argv[2:]: wrap_lookup(arg) else: while True: diff --git a/plint.py b/plint.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 -uO +import diaeresis import localization import sys import template @@ -8,8 +9,8 @@ import error def run(): ok = True f2 = None - if len(sys.argv) == 3: - f2 = open(sys.argv[2], 'w') + if len(sys.argv) == 4: + f2 = open(sys.argv[3], 'w') should_end = False while True: line = sys.stdin.readline() @@ -26,13 +27,20 @@ def run(): if __name__ == '__main__': localization.init_locale() - if len(sys.argv) < 2 or len(sys.argv) > 3: - print(_("Usage: %s TEMPLATE [OCONTEXT]") % sys.argv[0], file=sys.stderr) + if len(sys.argv) < 2 or len(sys.argv) > 4: + print(_("Usage: %s TEMPLATE [DFILE [OCONTEXT]]") % sys.argv[0], file=sys.stderr) print(_("Check stdin according to TEMPLATE, report errors on stdout"), file=sys.stderr) sys.exit(1) template_name = sys.argv[1] + if len(sys.argv) > 2: + diaeresis_name = sys.argv[2] + else: + diaeresis_name = "diaeresis.json" + + diaeresis.load_diaeresis(diaeresis_name) + f = open(template_name) x = f.read() f.close()