Commit 4e2f1031 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Switch to a text field for tools description

parent 9000d416
......@@ -3,3 +3,5 @@ application.properties
<path>
*__pycache__*
docs/data
*.pyc
*.bak
......@@ -139,10 +139,6 @@ if __name__ == '__main__':
elif args["cmd_object"] == "tools":
workflow = wfmanager.get_workflow_by_name(args["workflow_name"])
if workflow is not None:
nodes = workflow.tools.get_printable_tree()
i = 0
for node in nodes:
i += 1
print("{0}. {1}".format(i, node))
print(workflow.tools_description)
else:
print("Workflow not found: " + args["workflow_name"])
import random, string
class ToolTree:
@staticmethod
def randomword(length=10):
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))
def __init__(self, name="", choices=list()):
self.name = name
self.id = self.randomword()
self.choices = choices if name == "" else []
self.childs = []
self.parents = []
def add_tool(self, tool_name: str):
new_tool = ToolTree(name=tool_name)
self.add_child(new_tool)
return new_tool
def add_choices(self, *choices: str):
choices = list(choices)
if len(choices) >= 2:
new_tool = ToolTree(choices=choices)
self.add_child(new_tool)
return new_tool
raise Exception("You must specify at least two choices in tools description")
def add_child(self, node: "ToolTree"):
self.childs.append(node)
node.parents.append(self)
def build_printable_tree(self, printed_parents=dict()):
nodes = []
child_nodes = []
for child in self.childs:
nb_parents = len(child.parents)
if nb_parents == 1 or (child.id in printed_parents and len(printed_parents[child.id]) == nb_parents):
if child.name != "":
nodes.append(child.name)
elif len(child.choices) > 0:
nodes.append(" OR ".join(child.choices))
for my_child in child.childs:
if my_child.id not in printed_parents:
printed_parents[my_child.id] = []
printed_parents[my_child.id].append(child.id)
new_child_nodes, printed_parents = child.build_printable_tree()
child_nodes += new_child_nodes
nodes += child_nodes
return nodes, printed_parents
def get_printable_tree(self):
nodes, printed_parents = self.build_printable_tree()
return nodes
......@@ -46,7 +46,6 @@ from jflow.utils import get_octet_string_representation, get_nb_octet
from jflow.parameter import *
from jflow.exceptions import RuleException
import jflow.rules as j_rules
from jflow.tooltree import ToolTree
from cctools.util import time_format
......@@ -154,8 +153,7 @@ class Workflow(threading.Thread):
self.id = id
self.name = self.get_name()
self.description = self.get_description()
self.tools = ToolTree()
self.get_tools(self.tools)
self.tools_description = self.get_tools_description()
self.__group = self.jflow_config_reader.get_workflow_group(self.__class__.__name__) or Workflow.DEFAULT_GROUP
# define the parameters
......@@ -916,11 +914,11 @@ class Workflow(threading.Thread):
"""
raise NotImplementedError( "Workflow.get_description() must be implemented in " + self.__class__.__name__ )
def get_tools(self, toolstree: ToolTree):
def get_tools_description(self):
"""
Return the workflow description, has to be implemented by subclasses
"""
raise NotImplementedError( "Workflow.get_description() must be implemented in " + self.__class__.__name__ )
return ""
def get_summary(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