diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-15 09:53:34 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-17 01:16:46 +0800 |
commit | 508edcdf0255484be4107810af7e498c97719916 (patch) | |
tree | ceb0b2912d615201248f49868491a0d209357e2b | |
parent | 09bcd7b1a95764889cce11f7c80a767e97d6e548 (diff) | |
download | chandra-acis-analysis-508edcdf0255484be4107810af7e498c97719916.tar.bz2 |
manifest.py: Support return relative path w.r.t CWD for "getpath()"
-rwxr-xr-x | scripts/manifest.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/scripts/manifest.py b/scripts/manifest.py index c95b218..4f932d0 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -105,17 +105,22 @@ class Manifest: data = ds return data - def getpath(self, key): + def getpath(self, key, relative=False): """ Get the absolute path to the specified item by joining with the location of this manifest file. """ value = self.get(key) + cwd = os.getcwd() if isinstance(value, list): path = [os.path.join(os.path.dirname(self.filepath), f) for f in value] + if relative: + path = [os.path.relpath(p, start=cwd) for p in path] else: path = os.path.join(os.path.dirname(self.filepath), value) + if relative: + path = os.path.relpath(path, start=cwd) return path def set(self, key, value): @@ -282,7 +287,7 @@ def cmd_getpath(args, manifest): """ if not args.brief: print("%s:" % args.key, end=" ") - path = manifest.getpath(args.key) + path = manifest.getpath(args.key, relative=args.relative) if isinstance(path, list): print(args.separator.join(path)) else: @@ -366,7 +371,11 @@ def main(description="Manage the observation manifest (YAML format)", 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") + "getpath", help="Get the path to a file item from manifest") + parser_getpath.add_argument("-r", "--relative", dest="relative", + action="store_true", + help="Return relative path w.r.t. current " + + "working directory instead of absolute path") parser_getpath.add_argument("key", help="key of the file item") parser_getpath.set_defaults(func=cmd_getpath) # sub-command: set |