397 SupportedParsers = [
'direct',
'xml',
'list' ]
399 logging.warn(
"XML parser is not supported (cam't find python XML module)")
400 SupportedParsers.remove(
'xml')
403 parser = argparse.ArgumentParser(description=__doc__)
404 parser.set_defaults(NoROOTformula=
False, Parser=SupportedParsers[0])
406 parser.add_argument(
'--stdin', dest=
"FromSTDIN", action=
'store_true',
407 help=
"read input from stdin")
409 parser.add_argument(
"InputFiles", nargs=
"*", default=
None,
410 help=
"input GDML files [default: stdin]")
412 parser.add_argument(
"--parser", choices=SupportedParsers, dest=
"Parser",
413 help=
"choose which parser to use ('list' for a list) [%(default)s]")
415 parser.add_argument(
"--direct", action=
"store_const", const=
"direct",
416 dest=
"Parser", help=
"use simple internal parser [%(default)s]")
418 parser.add_argument(
"--xml", action=
"store_const", const=
"xml",
419 dest=
"Parser", help=
"use complete XML parser [%(default)s]")
429 parser.add_argument(
"--output",
"-o", dest=
"OutputFile", default=
None,
430 help=
"for a single input, use this as output file")
432 parser.add_argument(
'--warnzero',
'-z', dest=
"WarnZero", action=
'store_true',
433 help=
"emit a warning each time an expression evaluates to 0 [%(default)s]")
434 parser.add_argument(
'--dryrun',
'--fake',
'-n', dest=
"Fake", action=
'store_true',
435 help=
"do not write output [%(default)s]")
436 parser.add_argument(
'--verbose',
'-v', dest=
"DoVerbose", action=
'store_true',
437 help=
"shows all the changes on screen [%(default)s]")
438 parser.add_argument(
'--debug', dest=
"DoDebug", action=
'store_true',
439 help=
"enables debug messages on screen")
441 parser.add_argument(
'--version', action=
'version',
442 version=
'%(prog)s ' + __version__)
444 arguments = parser.parse_args()
450 logging.getLogger().setLevel \
451 (logging.DEBUG
if arguments.DoDebug
else logging.INFO)
453 arguments.LogMsg = logging.info
if arguments.DoVerbose
else logging.debug
455 if arguments.Parser ==
'list':
456 SupportedParsers.remove(
'list')
457 logging.info(
"Supported parsers: '%s'.",
"', '".
join(SupportedParsers))
461 if arguments.Parser ==
'direct':
462 Parser = RemoveMathFromGDMLfile
463 elif arguments.Parser ==
'xml':
464 Parser = RemoveMathFromXMLfile
468 if bool(arguments.FromSTDIN) ==
bool(arguments.InputFiles):
469 raise ConfigurationError \
470 (
"Please either specify option --stdin OR some input files.")
476 if arguments.FromSTDIN:
477 Parser(
None, options=arguments)
478 elif arguments.OutputFile
is not None:
479 if len(arguments.InputFiles) > 1:
480 raise ConfigurationError \
481 (
"Named output is supported only when a single input file is specified.")
483 Parser(arguments.InputFiles[0], arguments.OutputFile, options=arguments)
485 for InputFileName
in arguments.InputFiles:
486 RunParserOn(Parser, InputFileName, options=arguments)