yml2proc
changeset 7 f81a4471bc28
parent 4 e7b49a65cf3a
child 11 7026ccc7a60e
equal deleted inserted replaced
6:5ea9477ef8bb 7:f81a4471bc28
   130             for line in files:
   130             for line in files:
   131                 rtext += line
   131                 rtext += line
   132         else:
   132         else:
   133             result = parse(ymlC, files, True, comment)
   133             result = parse(ymlC, files, True, comment)
   134             if options.parseonly:
   134             if options.parseonly:
   135                 print result
   135                 print(result)
   136                 sys.exit(0)
   136                 sys.exit(0)
   137             else:
   137             else:
   138                 rtext = backend.finish(result)
   138                 rtext = backend.finish(result)
   139 
   139 
   140     if not rtext:
   140     if not rtext:
   222     if options.outputFile and options.outputFile != "-":
   222     if options.outputFile and options.outputFile != "-":
   223         outfile = open(options.outputFile, "w")
   223         outfile = open(options.outputFile, "w")
   224         outfile.write(plaintext)
   224         outfile.write(plaintext)
   225         outfile.close()
   225         outfile.close()
   226     else:
   226     else:
   227         print plaintext
   227         print(plaintext)
   228 
   228 
   229 except KeyboardInterrupt:
   229 except KeyboardInterrupt:
   230     w("\n")
   230     w("\n")
   231     sys.exit(1)
   231     sys.exit(1)
   232 except YMLAssert, msg:
   232 except YMLAssert as msg:
   233     w(u"YML Assertion failed: " + u(msg) + u"\n")
   233     w(u"YML Assertion failed: " + u(msg) + u"\n")
   234     sys.exit(2)
   234     sys.exit(2)
   235 except KeyError, msg:
   235 except KeyError as msg:
   236     w(u"not found: " + u(msg) + u"\n")
   236     w(u"not found: " + u(msg) + u"\n")
   237     sys.exit(4)
   237     sys.exit(4)
   238 except LookupError, msg:
   238 except LookupError as msg:
   239     w(u"not found: " + u(msg) + u"\n")
   239     w(u"not found: " + u(msg) + u"\n")
   240     sys.exit(4)
   240     sys.exit(4)
   241 except etree.XMLSyntaxError, e:
   241 except etree.XMLSyntaxError as e:
   242     log = e.error_log.filter_from_level(etree.ErrorLevels.FATAL)
   242     log = e.error_log.filter_from_level(etree.ErrorLevels.FATAL)
   243     for entry in log:
   243     for entry in log:
   244         w(u"XML error: " + u(entry.message) + u"\n")
   244         w(u"XML error: " + u(entry.message) + u"\n")
   245     sys.exit(5)
   245     sys.exit(5)
   246 except Exception, msg:
   246 except Exception as msg:
   247     w(msg)
   247     w(msg)
   248     sys.exit(5)
   248     sys.exit(5)