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