Skip to content

Commit

Permalink
Fix serializing Directory[] on command line. (#190)
Browse files Browse the repository at this point in the history
* Fix serializing Directory[] on command line.  Also handle Directory[] in
generate_parser.
  • Loading branch information
tetron authored Sep 13, 2016
1 parent 17fcf8d commit 876c0fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cwltool/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
44 changes: 21 additions & 23 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit 876c0fc

Please sign in to comment.