Skip to content

Commit accec7b

Browse files
committed
The command now runs.
1 parent 036325c commit accec7b

File tree

1 file changed

+17
-44
lines changed

1 file changed

+17
-44
lines changed

bin/nipype_cmd.py

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,36 @@ def add_options(parser=None, module=None, function=None):
2424
interface = getattr(sys.modules[module],function)()
2525

2626
for k,v in interface.inputs.items():
27-
parser.add_argument("--%s"%k, dest=k,
27+
if hasattr(v, "mandatory") and v.mandatory:
28+
parser.add_argument(k, help=v.desc)
29+
else:
30+
parser.add_argument("--%s"%k, dest=k,
2831
help=v.desc)
2932
return parser, interface
3033

3134
def run_instance(interface, options):
3235
if interface:
3336
print "setting function inputs"
34-
for k,v in interface.inputs.items():
35-
optionskey = ''.join(('IXI',k))
36-
if hasattr(options, optionskey):
37+
for k,_ in interface.inputs.items():
38+
if getattr(options, k) != None:
3739
setattr(interface.inputs, k,
38-
getattr(options, optionskey))
40+
getattr(options, k))
3941
print interface.inputs
40-
print "not really running anything"
42+
res = interface.run()
43+
print res.outputs
4144

42-
def get_modfunc(args):
43-
module = None
44-
function = None
45-
posargs = []
46-
skip = False
47-
for a in args:
48-
if skip:
49-
skip = False
50-
continue
51-
if a.startswith('--'):
52-
pass
53-
elif a.startswith('-'):
54-
skip = True
55-
else:
56-
posargs.append(a)
57-
if posargs:
58-
module = posargs[0]
59-
if len(posargs)==2:
60-
function = posargs[1]
61-
return module, function
6245

6346
def parse_args():
6447
parser = argparse.ArgumentParser(description='Nipype interface runner')
65-
parser.add_argument("--run", dest="run", help="Execute", default=False)
66-
67-
#
68-
# usage = "usage: %prog [options] module function"
69-
# parser = OptionParser(usage=usage,version="%prog 1.0",
70-
# conflict_handler="resolve")
48+
parser.add_argument("module", type=str, help="Module name")
49+
parser.add_argument("interface", type=str, help="Interface name")
50+
parsed = parser.parse_args(args=sys.argv[1:3])
7151

72-
73-
module, function = get_modfunc(sys.argv[1:])
74-
parser, interface = add_options(parser, module, function)
75-
args = parser.parse_args()
76-
if args.run and interface:
77-
#assign inputs
78-
run_instance(interface, args)
79-
else:
80-
parser.print_help()
81-
if module and not function:
82-
listClasses(module)
83-
parser.exit()
52+
_, prog = os.path.split(sys.argv[0])
53+
interface_parser = argparse.ArgumentParser(description="Run %s"%parsed.interface, prog=" ".join([prog] + sys.argv[1:3]))
54+
interface_parser, interface = add_options(interface_parser, parsed.module, parsed.interface)
55+
args = interface_parser.parse_args(args=sys.argv[3:])
56+
run_instance(interface, args)
8457

8558

8659
#*****************************************************************************

0 commit comments

Comments
 (0)