Skip to content

Commit

Permalink
Add support for --show history=config.foo.bar
Browse files Browse the repository at this point in the history
The "config." is optional
  • Loading branch information
RobertLuptonTheGood committed Oct 10, 2016
1 parent 06158e9 commit b101c85
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions python/lsst/pipe/base/argumentParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ def obeyShowArgument(showOpts, config=None, exit=False):
Supports the following options in showOpts:
- config[=PAT] Dump all the config entries, or just the ones that match the glob pattern
- history=PAT Show where the config entries that match the glob pattern were set
- tasks Show task hierarchy
- data Ignored; to be processed by caller
- run Keep going (the default behaviour is to exit if --show is specified)
Expand All @@ -715,9 +716,10 @@ def obeyShowArgument(showOpts, config=None, exit=False):
return

for what in showOpts:
mat = re.search(r"^config(?:=(.+))?", what)
if mat:
pattern = mat.group(1)
matConfig = re.search(r"^config(?:=(?:config.)?(.+))?", what)
matHistory = None if matConfig else re.search(r"^history(?:=(?:config.)?(.+))?", what)
if matConfig:
pattern = matConfig.group(1)
if pattern:
class FilteredStream(object):
"""A file object that only prints lines that match the glob "pattern"
Expand Down Expand Up @@ -750,6 +752,32 @@ def write(self, showStr):
fd = sys.stdout

config.saveToStream(fd, "config")
elif matHistory:
pattern = matHistory.group(1)
if not pattern:
print("Please provide a value with --show history (e.g. =XXX)", file=sys.stderr)
sys.exit(1)

pattern = pattern.split(".")
cpath, cname = pattern[:-1], pattern[-1]
hconfig = config # the config that we're interested in
for i, cpt in enumerate(cpath):
try:
hconfig = getattr(hconfig, cpt)
except AttributeError:
print("Error: configuration %s has no subconfig %s" %
(".".join(["config"] + cpath[:i]), cpt), file=sys.stderr)

sys.exit(1)

import lsst.pex.config.history as pch

try:
print(pch.format(hconfig, cname))
except KeyError:
print("Error: %s has no field %s" % (".".join(["config"] + cpath), cname), file=sys.stderr)
sys.exit(1)

elif what == "data":
pass
elif what == "run":
Expand All @@ -758,7 +786,7 @@ def write(self, showStr):
showTaskHierarchy(config)
else:
print(u"Unknown value for show: %s (choose from '%s')" %
(what, "', '".join("config[=XXX] data tasks run".split())), file=sys.stderr)
(what, "', '".join("config[=XXX] data history=XXX tasks run".split())), file=sys.stderr)
sys.exit(1)

if exit and "run" not in showOpts:
Expand Down

0 comments on commit b101c85

Please sign in to comment.