From 64562a847da6adff7ca8e8f64d6cdac73d5c412b Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 20 Feb 2017 20:04:25 +0800 Subject: acispy/manifest.py: Add "sep" support to "getpath()" method --- acispy/manifest.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'acispy/manifest.py') 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): -- cgit v1.2.2