Commit 5dc71e8e authored by Jerome Mariette's avatar Jerome Mariette
Browse files

update iofeatures and add python object parameter

parent 10cd9f3f
......@@ -210,11 +210,55 @@ class PythonFunction(ScriptFunction):
"""
PYTHON_VERSION = 'python{0}.{1}'.format(sys.version_info[0], sys.version_info[1])
PYTHON_TEMPLATE = '''#!/usr/bin/env {0}
import pickle
import {{0}}
{{1}}
from jflow.parameter import IOObject
def prepare_arguments(*args):
ioobj_ext = IOObject.IOOBJECT_EXT
new_args = []
output_path = []
# load input object
for i, arg in enumerate(args):
if arg.endswith(ioobj_ext):
if os.path.exists(arg):
ioobjh = open(arg, 'rb')
try:
ioobj = pickle.load(ioobjh)
if isinstance(ioobj, list):
for j, cioobj in enumerate(ioobj):
if (hasattr(cioobj, "is_ioobject")):
cioobjh = open(cioobj.dump_path, 'rb')
ioobj[j] = pickle.load(cioobjh)
cioobjh.close()
finally:
ioobjh.close()
new_args.append(ioobj)
else :
output_path.append(arg)
else :
new_args.append(arg)
return (new_args, output_path)
{{2}}
if __name__ == '__main__':
{{3}}(*sys.argv[1:])
(new_args, output_path) = prepare_arguments(*sys.argv[1:])
outputs = {{3}}(*new_args)
if not isinstance(outputs, list): outputs = [outputs]
# in case the returned object is a table
if len(output_path) == 1 and len(outputs) != len(output_path):
outputs = [outputs]
# otherwise the number does not match
elif len(outputs) != len(output_path) and len (output_path) != 0:
raise Exception( "The number of object returned by the function is different from the number of outputs specified!")
if len (output_path) > 0 :
for i, obj in enumerate(outputs):
objh = open(output_path[i], "w")
pickle.dump(obj, objh)
objh.close()
'''.format(PYTHON_VERSION)
def __init__(self, function, add_path=None, executable=None, cmd_format=None):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment