575 def parse_args(self, config, args=None, log=None, override=None):
576 """Parse arguments for a command-line task. 580 config : `lsst.pex.config.Config` 581 Config for the task being run. 582 args : `list`, optional 583 Argument list; if `None` then ``sys.argv[1:]`` is used. 584 log : `lsst.log.Log`, optional 585 `~lsst.log.Log` instance; if `None` use the default log. 586 override : callable, optional 587 A config override function. It must take the root config object 588 as its only argument and must modify the config in place. 589 This function is called after camera-specific overrides files 590 are applied, and before command-line config overrides 591 are applied (thus allowing the user the final word). 595 namespace : `argparse.Namespace` 596 A `~argparse.Namespace` instance containing fields: 598 - ``camera``: camera name. 599 - ``config``: the supplied config with all overrides applied, 600 validated and frozen. 601 - ``butler``: a `lsst.daf.persistence.Butler` for the data. 602 - An entry for each of the data ID arguments registered by 603 `add_id_argument`, of the type passed to its ``ContainerClass`` 604 keyword (`~lsst.pipe.base.DataIdContainer` by default). It 605 includes public elements ``idList`` and ``refList``. 606 - ``log``: a `lsst.log` Log. 607 - An entry for each command-line argument, 608 with the following exceptions: 610 - config is the supplied config, suitably updated. 611 - configfile, id and loglevel are all missing. 612 - ``obsPkg``: name of the ``obs_`` package for this camera. 617 if len(args) < 1
or args[0].startswith(
"-")
or args[0].startswith(
"@"):
619 if len(args) == 1
and args[0]
in (
"-h",
"--help"):
622 self.exit(
"%s: error: Must specify input as first argument" % self.prog)
626 namespace = argparse.Namespace()
627 namespace.input = _fixPath(DEFAULT_INPUT_NAME, args[0])
628 if not os.path.isdir(namespace.input):
629 self.error(
"Error: input=%r not found" % (namespace.input,))
631 namespace.config = config
632 namespace.log = log
if log
is not None else lsstLog.Log.getDefaultLogger()
633 mapperClass = dafPersist.Butler.getMapperClass(namespace.input)
634 if mapperClass
is None:
635 self.error(
"Error: no mapper specified for input repo %r" % (namespace.input,))
637 namespace.camera = mapperClass.getCameraName()
638 namespace.obsPkg = mapperClass.getPackageName()
640 self.handleCamera(namespace)
642 self._applyInitialOverrides(namespace)
643 if override
is not None:
644 override(namespace.config)
647 for dataIdArgument
in self._dataIdArgDict.values():
648 setattr(namespace, dataIdArgument.name, dataIdArgument.ContainerClass(level=dataIdArgument.level))
650 namespace = argparse.ArgumentParser.parse_args(self, args=args, namespace=namespace)
651 del namespace.configfile
653 self._parseDirectories(namespace)
655 if namespace.clobberOutput:
656 if namespace.output
is None:
657 self.error(
"--clobber-output is only valid with --output or --rerun")
658 elif namespace.output == namespace.input:
659 self.error(
"--clobber-output is not valid when the output and input repos are the same")
660 if os.path.exists(namespace.output):
661 namespace.log.info(
"Removing output repo %s for --clobber-output", namespace.output)
662 shutil.rmtree(namespace.output)
664 namespace.log.debug(
"input=%s", namespace.input)
665 namespace.log.debug(
"calib=%s", namespace.calib)
666 namespace.log.debug(
"output=%s", namespace.output)
671 if self.requireOutput
and namespace.output
is None and namespace.rerun
is None:
672 self.error(
"no output directory specified.\n" 673 "An output directory must be specified with the --output or --rerun\n" 674 "command-line arguments.\n")
678 butlerArgs = {
'mapperArgs': {
'calibRoot': namespace.calib}}
680 outputs = {
'root': namespace.output,
'mode':
'rw'}
681 inputs = {
'root': namespace.input}
682 inputs.update(butlerArgs)
683 outputs.update(butlerArgs)
686 outputs = {
'root': namespace.input,
'mode':
'rw'}
687 outputs.update(butlerArgs)
694 self._processDataIds(namespace)
695 if "data" in namespace.show:
696 for dataIdName
in self._dataIdArgDict.
keys():
697 for dataRef
in getattr(namespace, dataIdName).refList:
698 print(
"%s dataRef.dataId = %s" % (dataIdName, dataRef.dataId))
700 if namespace.show
and "run" not in namespace.show:
708 sys.stderr.write(
"Warning: no 'debug' module found\n")
709 namespace.debug =
False 711 del namespace.loglevel
713 if namespace.longlog:
714 lsstLog.configure_prop(
""" 715 log4j.rootLogger=INFO, A1 716 log4j.appender.A1=ConsoleAppender 717 log4j.appender.A1.Target=System.out 718 log4j.appender.A1.layout=PatternLayout 719 log4j.appender.A1.layout.ConversionPattern=%-5p %d{yyyy-MM-ddTHH:mm:ss.SSSZ} %c (%X{LABEL})(%F:%L)- %m%n 721 del namespace.longlog
723 namespace.config.validate()
724 namespace.config.freeze()
def obeyShowArgument(showOpts, config=None, exit=False)