diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-13 22:07:54 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-13 22:07:54 +0800 |
commit | 499deec0d6e28f4e842f6072de000bae236ac1e4 (patch) | |
tree | d504d01b85bdf5a7c5472bf325e624ca3d562ac2 | |
parent | 0c0b313ef9bb6dda7c2deda8db713545278dec06 (diff) | |
download | chandra-acis-analysis-499deec0d6e28f4e842f6072de000bae236ac1e4.tar.bz2 |
manifest.py: Implement "getpath" sub-command
-rwxr-xr-x | scripts/manifest.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/scripts/manifest.py b/scripts/manifest.py index 4555714..1fb41d7 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -30,7 +30,7 @@ class Manifest: Manage the observational products manifest. """ def __init__(self, filepath): - self.filepath = filepath + self.filepath = os.path.abspath(filepath) self.manifest = ruamel.yaml.load( open(filepath), Loader=ruamel.yaml.RoundTripLoader) if self.manifest is None: @@ -88,6 +88,14 @@ class Manifest: ]) return data + def getpath(self, key): + """ + Get the absolute path to the specified item by joining + with the location of this manifest file. + """ + value = self.get(key) + return os.path.join(os.path.dirname(self.filepath), value) + def set(self, key, value): """ Set the value of the specified item in the manifest. @@ -190,6 +198,16 @@ def cmd_get(args, manifest): print(manifest.get(args.key)) +def cmd_getpath(args, manifest): + """ + Sub-command "getpath": Get the absolute path to the specified file + item in the manifest. + """ + if not args.brief: + print("%s:" % args.key, end=" ") + print(manifest.getpath(args.key)) + + def cmd_set(args, manifest): """ Sub-command "set": Set the value of an item in the manifest. @@ -249,6 +267,11 @@ def main(description="Manage the observation manifest (YAML format)", parser_get = subparsers.add_parser("get", help="Get an item from manifest") parser_get.add_argument("key", help="key of the item") parser_get.set_defaults(func=cmd_get) + # sub-command: getpath + parser_getpath = subparsers.add_parser( + "getpath", help="Get absolute path to a file item from manifest") + parser_getpath.add_argument("key", help="key of the file item") + parser_getpath.set_defaults(func=cmd_getpath) # sub-command: set parser_set = subparsers.add_parser( "set", help="Set (add/update) an item in manifest") |