Commit d605f15b authored by Céline Noirot's avatar Céline Noirot
Browse files

Add trace execution

parent c334bce3
......@@ -37,15 +37,15 @@ from weaver.function import PythonFunction
class Component(object):
TRACE="trace.cmd"
def __init__(self):
self.prefix = "default"
self.params_order = []
self.output_directory = None
self.config_reader = JFlowConfigReader()
self.version = self.get_version()
if isinstance(self.version, bytes):
self.version = self.version.decode()
self.batch_options = self.config_reader.get_component_batch_options(self.__class__.__name__)
def is_dynamic(self):
......@@ -543,6 +543,8 @@ class Component(object):
else:
py_function(inputs=new_inputs, outputs=new_outputs, arguments=arguments, includes=includes+includes_in)
self.write_trace(function.__name__, inputs, outputs, arguments, cmd_format, map, "PythonFunction")
def add_shell_execution(self, source, inputs=[], outputs=[], arguments=[], includes=[],
cmd_format=None, map=False, shell=None, collect=False, local=False):
shell_function = ShellFunction( source, shell=shell, cmd_format=cmd_format )
......@@ -562,3 +564,33 @@ class Component(object):
else :
shell_function( inputs=inputs, outputs=outputs, arguments=arguments, includes=includes )
self.write_trace(source, inputs, outputs, arguments, cmd_format, map, "Shell")
def write_trace(self, name, inputs, outputs, arguments, cmd_format, map, type):
trace_fh=open(os.path.join(self.output_directory,Component.TRACE),"a")
trace_fh.write("###\n###Execution trace of "+type+": "+name+"\n")
if map :
trace_fh.write("MODE MAP\n")
if cmd_format != "" and type == "Shell":
trace_fh.write("COMMAND: " + str(cmd_format) + "\n")
self.write_element(trace_fh,"ARGCUMENTS",arguments)
self.write_element(trace_fh,"INPUTS",inputs)
self.write_element(trace_fh,"OUTPUTS",outputs)
trace_fh.close()
def write_element(self,fh, title, element):
to_write=''
if isinstance(element, list):
if len (element)> 0 :
if isinstance(element[0], list):
for i in range(len(element)) :
to_write+="List"+str(i+1)+": \n"
to_write+="\n".join(element[i])+"\n"
else :
to_write+="\n".join(element)+"\n"
else :
to_write+= element+"\n"
if to_write != "" :
fh.write(title+" :\n")
fh.write(to_write)
\ No newline at end of file
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