Commit c3d98e32 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Move print to workflow class

parent ae01af34
......@@ -19,8 +19,6 @@
import sys
import argparse
import time
import re
try:
import _preamble
......@@ -59,49 +57,6 @@ class JflowArgumentParser (argparse.ArgumentParser):
# return the modified argument list
return new_arg_strings
def print_workflow_outputs(the_workflow, logs):
outputs = the_workflow.get_outputs_per_components()
descriptions = the_workflow.get_description_per_components()
idx = 1
for output in outputs:
name = output[:output.index(".")]
component = str(idx) + ". "
if output in descriptions and descriptions[output] is not None:
component += descriptions[output]
else:
component += name
component += ":\n"
has_outputs = False
for output_file in outputs[output]:
if logs or (not output_file.endswith(".stdout") and not output_file.endswith(".stderr")):
has_outputs = True
component += " - " + outputs[output][output_file] + "\n"
if has_outputs:
print(component)
idx += 1
def print_workflow_programs(the_workflow):
programs = the_workflow.get_workflow_programs()
descriptions = the_workflow.get_description_per_components()
idx = 1
for component, program in programs.items():
name = component
component_str = str(idx) + ". "
if component in descriptions and descriptions[component] is not None:
component_str += descriptions[component]
else:
component_str += name
component_str += ":\n"
component_str += "\t- Program: {0}\n".format(program["name"])
component_str += "\t- Version: {0}\n".format(program["version"])
component_str += "\t- Parameters: {0}\n".format(", ".join(program["parameters"])
if len(program["parameters"]) > 0 else "None")
print(component_str)
idx += 1
if __name__ == '__main__':
# Create a workflow manager to get access to our workflows
......@@ -206,34 +161,13 @@ if __name__ == '__main__':
except Exception as e:
utils.display_error_message(str(e))
elif args["cmd_object"] == "print":
if args["what"] in ["outputs", "outputs_logs"]:
try:
my_workflow = wfmanager.get_workflow(args["workflow_id"])
print_workflow_outputs(my_workflow, args["what"] == "outputs_logs")
except Exception as e:
utils.display_error_message(str(e))
elif args["what"] == "execution_graph":
try:
workflow = wfmanager.get_workflow(args["workflow_id"])
except Exception as e:
utils.display_error_message(str(e))
gr = workflow.get_execution_graph()
inputs, components = [], []
for node in gr.nodes():
if Workflow.INPUTFILE_GRAPH_LABEL in gr.node_attributes(node):
inputs.append(gr.node_attributes(node)[1])
elif Workflow.INPUTFILES_GRAPH_LABEL in gr.node_attributes(node):
inputs.append(gr.node_attributes(node)[1])
elif Workflow.INPUTDIRECTORY_GRAPH_LABEL in gr.node_attributes(node):
inputs.append(gr.node_attributes(node)[1])
elif Workflow.COMPONENT_GRAPH_LABEL in gr.node_attributes(node):
components.append(gr.node_attributes(node)[1])
print(("inputs: ", inputs))
print(("components: ", components))
print(("edges: ", gr.edges()))
elif args["what"] == "programs":
my_workflow = None
try:
my_workflow = wfmanager.get_workflow(args["workflow_id"])
print_workflow_programs(my_workflow)
except Exception as e:
utils.display_error_message(str(e))
if my_workflow is not None:
my_workflow.print_output(args["what"])
elif args["cmd_object"] == "status":
if args["workflow_id"]:
try:
......
......@@ -361,6 +361,72 @@ class Workflow(threading.Thread):
new_param = self._prepare_parameter(args, param)
self.__setattr__(param.name, new_param)
def __print_execution_graph(self):
gr = self.get_execution_graph()
inputs, components = [], []
for node in gr.nodes():
if Workflow.INPUTFILE_GRAPH_LABEL in gr.node_attributes(node):
inputs.append(gr.node_attributes(node)[1])
elif Workflow.INPUTFILES_GRAPH_LABEL in gr.node_attributes(node):
inputs.append(gr.node_attributes(node)[1])
elif Workflow.INPUTDIRECTORY_GRAPH_LABEL in gr.node_attributes(node):
inputs.append(gr.node_attributes(node)[1])
elif Workflow.COMPONENT_GRAPH_LABEL in gr.node_attributes(node):
components.append(gr.node_attributes(node)[1])
print(("inputs: ", inputs))
print(("components: ", components))
print(("edges: ", gr.edges()))
def __print_outputs(self, logs):
outputs = self.get_outputs_per_components()
descriptions = self.get_description_per_components()
idx = 1
for output in outputs:
name = output[:output.index(".")]
component = str(idx) + ". "
if output in descriptions and descriptions[output] is not None:
component += descriptions[output]
else:
component += name
component += ":\n"
has_outputs = False
for output_file in outputs[output]:
if logs or (not output_file.endswith(".stdout") and not output_file.endswith(".stderr")):
has_outputs = True
component += " - " + outputs[output][output_file] + "\n"
if has_outputs:
print(component)
idx += 1
def __print_programs(self):
programs = self.get_workflow_programs()
descriptions = self.get_description_per_components()
idx = 1
for component, program in programs.items():
name = component
component_str = str(idx) + ". "
if component in descriptions and descriptions[component] is not None:
component_str += descriptions[component]
else:
component_str += name
component_str += ":\n"
component_str += "\t- Program: {0}\n".format(program["name"])
component_str += "\t- Version: {0}\n".format(program["version"])
component_str += "\t- Parameters: {0}\n".format(", ".join(program["parameters"])
if len(program["parameters"]) > 0 else "None")
print(component_str)
idx += 1
def print_output(self, type_o):
if type_o == "execution_graph":
self.__print_execution_graph()
elif type_o in ("outputs", "outputs_logs"):
self.__print_outputs(type_o == "outputs_logs")
elif type_o == "programs":
self.__print_programs()
else:
print("Unknow command to print: {0}".format(type_o))
def get_execution_graph(self):
gr = digraph()
# build a all_nodes table to store all nodes
......@@ -945,7 +1011,7 @@ class Workflow(threading.Thread):
print("# Results #")
print("###########")
print("")
self.print_workflow_outputs(False)
self.__print_outputs(False)
print("")
print(self.get_summary())
except:
......
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