Commit e9c11fa6 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

No commit message

No commit message
parent c7e4923d
......@@ -28,6 +28,7 @@ from argparse import _ensure_value
import urllib2
import copy as _copy
from urlparse import urlparse
import pickle
from jflow.config_reader import JFlowConfigReader
from jflow.utils import get_octet_string_representation, get_nb_octet, display_error_message
......@@ -482,11 +483,17 @@ class MultiParameterList(list, AbstractParameter):
if isinstance(key, int):
return getitem(self, key)
else :
if getitem(self, 0).has_key(key):
res=[]
for mparam in self :
res.append(mparam[key])
return res
if len(self) > 0:
if getitem(self, 0).has_key(key):
res=[]
for mparam in self :
if isinstance(getitem(self, 0)[key], list):
res.extend(mparam[key])
else:
res.append(mparam[key])
return res
else:
return []
class ParameterFactory(object):
......@@ -1101,4 +1108,155 @@ class OutputFilesPattern(DynamicOutput):
output_files.append( IOFile(os.path.join(self.output_directory, file), self.file_format, self.linkTrace_nameid, None) )
elif not self.include and re.search( self.pattern, file ) is None:
output_files.append( IOFile(os.path.join(self.output_directory, file), self.file_format, self.linkTrace_nameid, None) )
return list.__init__(self, output_files)
\ No newline at end of file
return list.__init__(self, output_files)
class IOObject(object):
IOOBJECT_EXT = ".ioobj"
@staticmethod
def add_required_attributs(obj):
jflowconf = JFlowConfigReader()
obj.is_ioobject = True
obj.dump_path = os.path.join(jflowconf.get_tmp_directory(), os.path.basename(tempfile.NamedTemporaryFile(suffix=IOObject.IOOBJECT_EXT).name))
obj.includes = []
obj.linkTrace_nameid = None
obj.parent_linkTrace_nameid = []
def __init__(self):
IOObject.add_required_attributs(self)
class IObjectList(list, IOObject):
def __new__(self, value):
val = list.__new__(self)
val.extend(value)
return val
def __init__(self, value):
IOObject.__init__(self)
for cobj in value:
if isinstance(cobj, OObject):
self.includes.append(cobj.dump_path)
if isinstance(cobj, InputFile) or isinstance(cobj, OutputFile) :
self.includes.append(cobj)
if isinstance(cobj, list): # list of list
for elt in cobj:
if issubclass(elt.__class__, AbstractIOFile) and issubclass(elt.__class__, ParameterList) :
self.includes.extend(elt)
elif issubclass(elt.__class__, AbstractIOFile) :
self.includes.append(elt)
if isinstance(cobj, dict): # list of dict
for ckey,cval in cobj.items():
if issubclass(cval.__class__, AbstractIOFile) and issubclass(cval.__class__, ParameterList) :
self.includes.extend(cval)
elif issubclass(cval.__class__, AbstractIOFile) :
self.includes.append(cval)
class IObjectDict(dict, IOObject):
def __new__(self, value):
val = dict.__new__(self, value)
for ckey in value.keys(): val[ckey] = value[ckey]
return val
def __init__(self, value):
IOObject.__init__(self)
for ckey,value in value.items():
if isinstance(value, OObject):
self.includes.append(value.dump_path)
if isinstance(value, InputFile) or isinstance(value, OutputFile) :
self.includes.append(value)
if isinstance(value, list): # list of list
if issubclass(value.__class__, AbstractIOFile) and issubclass(value.__class__, ParameterList) :
self.includes.extend(value)
elif issubclass(value.__class__, AbstractIOFile) :
self.includes.append(value)
if isinstance(value, dict): # list of dict
for k,cval in cobj.items():
if issubclass(cval.__class__, AbstractIOFile) and issubclass(cval.__class__, ParameterList) :
self.includes.extend(cval)
elif issubclass(cval.__class__, AbstractIOFile) :
self.includes.append(cval)
class IObjectFactory(object):
@staticmethod
def factory(obj):
new_obj = None
to_pickle = True
if isinstance(obj, OObject):
to_pickle = False
new_obj = obj
elif isinstance(obj, list):
new_obj = IObjectList(obj)
elif isinstance(obj, dict):
new_obj = IObjectDict(obj)
else:
new_obj = obj
IOObject.add_required_attributs(new_obj)
if to_pickle:
ioobjh = open(new_obj.dump_path, "w")
pickle.dump(new_obj, ioobjh)
ioobjh.close()
return new_obj
class OObject(IOObject):
def load(self):
if os.path.exists(self.dump_path):
fh = open(self.dump_path, 'rb')
o=pickle.load(fh)
fh.close()
return o
class InputObject(AbstractParameter, LinkTraceback):
def __init__( self, name, help, default=None, required=False):
new_object = IObjectFactory.factory(default)
AbstractParameter.__init__(self, name, help, default=new_object, type="object", required=required, action="store")
LinkTraceback.__init__(self)
class InputObjectList(ParameterList, LinkTraceback) :
def __init__ (self, name, help, default=None, required=False) :
new_default = []
if isinstance(default, list):
if len(default)>0 :
objects_class = default[0].__class__.__name__
for cobj in default:
if objects_class != cobj.__class__.__name__:
raise Exception('All object in an InputObjectList should have the same type!')
for obj in default:
new_obj = IObjectFactory.factory(obj)
new_default.append(new_obj)
else :
new_obj = IObjectFactory.factory(default)
new_default = [new_obj]
ParameterList.__init__(self, name, help, default=new_default, type="object", required=required)
LinkTraceback.__init__(self)
class OutputObject(AbstractParameter, LinkTraceback):
def __init__( self, name, help, required=False):
AbstractParameter.__init__(self, name, help, default=OObject(), type="object", required=required, action="store")
LinkTraceback.__init__(self)
class OutputObjectList(ParameterList, LinkTraceback) :
def __init__ (self, name, help, nb_items=0, required=False) :
new_default = [ OObject() for i in range(nb_items) ]
ParameterList.__init__(self, name, help, default=new_default, type="object", required=required)
LinkTraceback.__init__(self)
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