9 |
9 |
10 import sys, os, codecs, locale |
10 import sys, os, codecs, locale |
11 import fileinput, unicodedata |
11 import fileinput, unicodedata |
12 from optparse import OptionParser |
12 from optparse import OptionParser |
13 |
13 |
14 from pyPEG import parse, u |
14 from pyPEG import parse |
15 from yml2 import ymlCStyle, comment, oldSyntax |
15 from yml2 import ymlCStyle, comment, oldSyntax |
16 import backend |
16 import backend |
17 |
17 |
18 def printInfo(option, opt_str, value, parser): |
18 def printInfo(option, opt_str, value, parser): |
19 sys.stdout.write(__doc__) |
19 sys.stdout.write(__doc__) |
|
20 sys.exit(0) |
20 |
21 |
21 def w(msg): |
22 def w(msg): |
22 if isinstance(msg, BaseException): |
23 if isinstance(msg, BaseException): |
23 try: |
24 msg = str(msg) + "\n" |
24 msg = str(msg) + "\n" |
|
25 except: |
|
26 msg = u(msg) + u"\n" |
|
27 if type(msg) is unicode: |
|
28 msg = codecs.encode(msg, sys.stderr.encoding) |
|
29 sys.stderr.write(msg) |
25 sys.stderr.write(msg) |
30 |
26 |
31 optParser = OptionParser() |
27 optParser = OptionParser() |
32 optParser.add_option("-C", "--old-syntax", action="store_true", dest="old_syntax", |
28 optParser.add_option("-C", "--old-syntax", action="store_true", dest="old_syntax", |
33 help="syntax of YML 2 version 1.x (compatibility mode)", default=False) |
29 help="syntax of YML 2 version 1.x (compatibility mode)", default=False) |
84 |
80 |
85 except KeyboardInterrupt: |
81 except KeyboardInterrupt: |
86 w("\n") |
82 w("\n") |
87 sys.exit(1) |
83 sys.exit(1) |
88 except KeyError as msg: |
84 except KeyError as msg: |
89 w(u"not found: " + u(msg) + u"\n") |
85 w("not found: " + msg + "\n") |
90 sys.exit(4) |
86 sys.exit(4) |
91 except LookupError as msg: |
87 except LookupError as msg: |
92 w(u"not found: " + u(msg) + u"\n") |
88 w("not found: " + msg + "\n") |
93 sys.exit(4) |
89 sys.exit(4) |
94 except Exception as msg: |
90 except Exception as msg: |
95 w(msg) |
91 w(msg) |
96 sys.exit(5) |
92 sys.exit(5) |