Commit bf20eeb294cba91d7d94f30e6e5c64c4f64d5fbd
1 parent
df4f610f
ładniejsze wywalanie się dla błędnych parametrów (bezsensowny input/output)
git-svn-id: svn://svn.nlp.ipipan.waw.pl/morfeusz/morfeusz@103 ff4e3ee1-f430-4e82-ade0-24591c43f1fd
Showing
1 changed file
with
12 additions
and
1 deletions
fsabuilder/buildfsa.py
... | ... | @@ -5,7 +5,7 @@ Created on 21 paź 2013 |
5 | 5 | |
6 | 6 | @author: mlenart |
7 | 7 | ''' |
8 | - | |
8 | +import os | |
9 | 9 | import sys |
10 | 10 | import logging |
11 | 11 | import codecs |
... | ... | @@ -42,6 +42,14 @@ def _checkExactlyOneOptionSet(optsList, parser, msg): |
42 | 42 | def _parseListCallback(option, opt, value, parser): |
43 | 43 | setattr(parser.values, option.dest, value.split(',')) |
44 | 44 | |
45 | +def _checkOpen(filename, mode): | |
46 | + try: | |
47 | + with open(filename, mode) as _: | |
48 | + pass | |
49 | + except IOError as ex: | |
50 | + print >> sys.stderr, str(ex) | |
51 | + exit(1) | |
52 | + | |
45 | 53 | def _parseOptions(): |
46 | 54 | """ |
47 | 55 | Parses commandline args |
... | ... | @@ -124,6 +132,9 @@ def _parseOptions(): |
124 | 132 | _checkOption(opts.serializationMethod, parser, "Serialization method file is missing") |
125 | 133 | _checkExactlyOneOptionSet([opts.analyzer, opts.generator], |
126 | 134 | parser, 'Must set exactly one FSA type: --analyzer or --generator') |
135 | + for filename in opts.inputFiles: | |
136 | + _checkOpen(filename, 'r') | |
137 | + _checkOpen(opts.outputFile, 'w') | |
127 | 138 | if opts.analyzer: |
128 | 139 | _checkOption(opts.segmentsFile, parser, "Segment rules file is missing") |
129 | 140 | |
... | ... |