diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-20 20:04:25 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-20 20:04:25 +0800 |
commit | 64562a847da6adff7ca8e8f64d6cdac73d5c412b (patch) | |
tree | aa2abbc93a6fc03445b4ecc1eeaafa59a881e2e8 | |
parent | aaa3c4fa01ea0019b4ee721a03662cb32ddd0923 (diff) | |
download | chandra-acis-analysis-64562a847da6adff7ca8e8f64d6cdac73d5c412b.tar.bz2 |
acispy/manifest.py: Add "sep" support to "getpath()" method
-rw-r--r-- | acispy/manifest.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/acispy/manifest.py b/acispy/manifest.py index d111d94..03320f8 100644 --- a/acispy/manifest.py +++ b/acispy/manifest.py @@ -104,10 +104,21 @@ class Manifest: data = ds return data - def getpath(self, key, relative=False): + def getpath(self, key, relative=False, sep=None): """ Get the absolute path to the specified item by joining with the location of this manifest file. + + Parameters + ---------- + key : str + Key of the file item + relative : bool, optional + Whether return the file path(s) as relative path w.r.t. + the current working directory? + sep : str, optional + If not ``None``, join the multiple file paths with the + specified separator, instead of returning a list of paths. """ value = self.get(key) cwd = os.getcwd() @@ -116,6 +127,8 @@ class Manifest: for f in value] if relative: path = [os.path.relpath(p, start=cwd) for p in path] + if sep is not None: + path = sep.join(path) else: path = os.path.join(os.path.dirname(self.filepath), value) if relative: @@ -301,11 +314,9 @@ def cmd_getpath(args, manifest): """ if not args.brief: print("%s:" % args.key, end=" ") - path = manifest.getpath(args.key, relative=args.relative) - if isinstance(path, list): - print(args.separator.join(path)) - else: - print(path) + path = manifest.getpath(args.key, relative=args.relative, + sep=args.separator) + print(path) def cmd_set(args, manifest): |