966 """Process arguments specified with ``--show`` (but ignores
971 showOpts : `list` of `str`
972 List of options passed to ``--show``.
975 exit : bool, optional
976 Exit if ``"run"`` isn't included in ``showOpts``.
980 Supports the following options in showOpts:
982 - ``config[=PAT]``. Dump all the config entries, or just the ones that
983 match the glob pattern.
984 - ``history=PAT``. Show where the config entries that match the glob
986 - ``tasks``. Show task hierarchy.
987 - ``data``. Ignored; to be processed by caller.
988 - ``run``. Keep going (the default behaviour is to exit if
989 ``--show`` is specified).
991 Calls ``sys.exit(1)`` if any other option found.
996 for what
in showOpts:
997 showCommand, showArgs = what.split(
"=", 1)
if "=" in what
else (what,
"")
999 if showCommand ==
"config":
1000 matConfig = re.search(
r"^(?:config.)?(.+)?", showArgs)
1001 pattern = matConfig.group(1)
1003 class FilteredStream:
1004 """A file object that only prints lines
1005 that match the glob "pattern".
1007 N.b. Newlines are silently discarded and reinserted;
1008 crude but effective.
1011 def __init__(self, pattern):
1013 mat = re.search(
r"(.*):NOIGNORECASE$", pattern)
1016 pattern = mat.group(1)
1017 self._pattern = re.compile(fnmatch.translate(pattern))
1019 if pattern != pattern.lower():
1020 print(f
"Matching {pattern!r} without regard to case "
1021 "(append :NOIGNORECASE to prevent this)", file=sys.stdout)
1022 self._pattern = re.compile(fnmatch.translate(pattern), re.IGNORECASE)
1024 def write(self, showStr):
1025 showStr = showStr.rstrip()
1028 matchStr = showStr.split(
"\n")[-1].split(
"=")[0]
1029 if self._pattern.search(matchStr):
1030 print(
"\n" + showStr)
1032 fd = FilteredStream(pattern)
1036 config.saveToStream(fd,
"config")
1037 elif showCommand ==
"history":
1038 matHistory = re.search(
r"^(?:config.)?(.+)?", showArgs)
1039 globPattern = matHistory.group(1)
1041 print(
"Please provide a value with --show history (e.g. history=*.doXXX)", file=sys.stderr)
1045 for i, pattern
in enumerate(fnmatch.filter(config.names(), globPattern)):
1049 pattern = pattern.split(
".")
1050 cpath, cname = pattern[:-1], pattern[-1]
1052 for i, cpt
in enumerate(cpath):
1054 hconfig = getattr(hconfig, cpt)
1055 except AttributeError:
1056 config_path =
".".join([
"config"] + cpath[:i])
1057 print(f
"Error: configuration {config_path} has no subconfig {cpt}", file=sys.stderr)
1061 print(pexConfig.history.format(hconfig, cname))
1063 config_path =
".".join([
"config"] + cpath)
1064 print(f
"Error: {config_path} has no field {cname}", file=sys.stderr)
1070 elif showCommand ==
"data":
1072 elif showCommand ==
"run":
1074 elif showCommand ==
"tasks":
1077 choices =
"', '".join(
"config[=XXX] data history=XXX tasks run".split())
1078 print(f
"Unknown value for show: {what} (choose from {choices!r})", file=sys.stderr)
1081 if exit
and "run" not in showOpts: