From 876c0fcabac3829cd48fb228502f3259488ce118 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 13 Sep 2016 13:10:24 -0400 Subject: [PATCH] Fix serializing Directory[] on command line. (#190) * Fix serializing Directory[] on command line. Also handle Directory[] in generate_parser. --- cwltool/builder.py | 2 +- cwltool/main.py | 44 +++++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/cwltool/builder.py b/cwltool/builder.py index e7abb9417..7ac35fecc 100644 --- a/cwltool/builder.py +++ b/cwltool/builder.py @@ -155,7 +155,7 @@ def generate_arg(self, binding): # type: (Dict[Text,Any]) -> List[Text] if binding.get("itemSeparator"): l = [binding["itemSeparator"].join([self.tostr(v) for v in value])] elif binding.get("valueFrom"): - value = [v["path"] if isinstance(v, dict) and v.get("class") == "File" else v for v in value] + value = [self.tostr(v) for v in value] return ([prefix] if prefix else []) + value elif prefix: return [prefix] diff --git a/cwltool/main.py b/cwltool/main.py index 5ca672f0a..e8c9f214a 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -237,45 +237,30 @@ def output_callback(out, processStatus): return final_output[0] -class FileAction(argparse.Action): +class FSAction(argparse.Action): + objclass = None # type: Text def __init__(self, option_strings, dest, nargs=None, **kwargs): # type: (List[Text], Text, Any, **Any) -> None if nargs is not None: raise ValueError("nargs not allowed") - super(FileAction, self).__init__(option_strings, dest, **kwargs) + super(FSAction, self).__init__(option_strings, dest, **kwargs) def __call__(self, parser, namespace, values, option_string=None): # type: (argparse.ArgumentParser, argparse.Namespace, Union[AnyStr, Sequence[Any], None], AnyStr) -> None setattr(namespace, self.dest, # type: ignore - {"class": "File", + {"class": self.objclass, "location": "file://%s" % os.path.abspath(cast(AnyStr, values))}) - -class DirectoryAction(argparse.Action): +class FSAppendAction(argparse.Action): + objclass = None # type: Text def __init__(self, option_strings, dest, nargs=None, **kwargs): # type: (List[Text], Text, Any, **Any) -> None if nargs is not None: raise ValueError("nargs not allowed") - super(DirectoryAction, self).__init__(option_strings, dest, **kwargs) - - def __call__(self, parser, namespace, values, option_string=None): - # type: (argparse.ArgumentParser, argparse.Namespace, Union[AnyStr, Sequence[Any], None], AnyStr) -> None - setattr(namespace, - self.dest, # type: ignore - {"class": "Directory", - "location": "file://%s" % os.path.abspath(cast(AnyStr, values))}) - - -class FileAppendAction(argparse.Action): - - def __init__(self, option_strings, dest, nargs=None, **kwargs): - # type: (List[Text], Text, Any, **Any) -> None - if nargs is not None: - raise ValueError("nargs not allowed") - super(FileAppendAction, self).__init__(option_strings, dest, **kwargs) + super(FSAppendAction, self).__init__(option_strings, dest, **kwargs) def __call__(self, parser, namespace, values, option_string=None): # type: (argparse.ArgumentParser, argparse.Namespace, Union[AnyStr, Sequence[Any], None], AnyStr) -> None @@ -288,9 +273,20 @@ def __call__(self, parser, namespace, values, option_string=None): self.dest, # type: ignore g) g.append( - {"class": "File", + {"class": self.objclass, "location": "file://%s" % os.path.abspath(cast(AnyStr, values))}) +class FileAction(FSAction): + objclass = "File" + +class DirectoryAction(FSAction): + objclass = "Directory" + +class FileAppendAction(FSAppendAction): + objclass = "File" + +class DirectoryAppendAction(FSAppendAction): + objclass = "Directory" def generate_parser(toolparser, tool, namemap): # type: (argparse.ArgumentParser, Process, Dict[Text, Text]) -> argparse.ArgumentParser @@ -330,6 +326,8 @@ def generate_parser(toolparser, tool, namemap): elif isinstance(inptype, dict) and inptype["type"] == "array": if inptype["items"] == "File": action = cast(argparse.Action, FileAppendAction) + elif inptype["items"] == "Directory": + action = cast(argparse.Action, DirectoryAppendAction) else: action = "append" elif isinstance(inptype, dict) and inptype["type"] == "enum":