executioner

Contains classes for handling project item execution.

author:
  1. Savolainen (VTT)
date:

8.4.2019

Module Contents

class executioner.DirectedGraphHandler(toolbox)[source]

Class for manipulating graphs according to user’s actions.

Parameters:toolbox (ToolboxUI) – QMainWindow instance
dags(self)[source]

Returns a list of graphs (DiGraph) in the project.

add_dag(self, dag)[source]

Add graph to list.

Parameters:dag (DiGraph) – Graph to add
remove_dag(self, dag)[source]

Remove graph from instance variable list.

Parameters:dag (DiGraph) – Graph to remove
add_dag_node(self, node_name)[source]

Create directed graph with one node and add it to list.

Parameters:node_name (str) – Project item name to add as a node
add_graph_edge(self, src_node, dst_node)[source]

Adds an edge between the src and dst nodes. If nodes are in different graphs, the reference to union graph is saved and the references to the original graphs are removed. If src and dst nodes are already in the same graph, the edge is added to the graph. If src and dst are the same node, a self-loop (feedback) edge is added.

Parameters:
  • src_node (str) – Source project item node name
  • dst_node (str) – Destination project item node name
remove_graph_edge(self, src_node, dst_node)[source]

Removes edge from a directed graph.

Parameters:
  • src_node (str) – Source project item node name
  • dst_node (str) – Destination project item node name
remove_node_from_graph(self, node_name)[source]

Removes node from a graph that contains it. Called when project item is removed from project.

Parameters:node_name (str) – Project item name
rename_node(self, old_name, new_name)[source]

Handles renaming the node and edges in a graph when a project item is renamed.

Parameters:
  • old_name (str) – Old project item name
  • new_name (str) – New project item name
Returns:

True if successful, False if renaming failed

Return type:

bool

dag_with_node(self, node_name)[source]

Returns directed graph that contains given node.

Parameters:node_name (str) – Node to look for
Returns:Directed graph that contains node or None if not found.
Return type:(DiGraph)
dag_with_edge(self, src_node, dst_node)[source]

Returns directed graph that contains given edge.

Parameters:
  • src_node (str) – Source node name
  • dst_node (str) – Destination node name
Returns:

Directed graph that contains edge or None if not found.

Return type:

(DiGraph)

calc_exec_order(self, g)[source]

Returns an bfs-ordered list of nodes in the given graph. Adds a dummy source node to the graph if there are more than one nodes that have no inbound connections. The dummy source node is needed for the bfs-algorithm.

Parameters:g (DiGraph) – Directed graph to process
Returns:bfs-ordered list of node names (first item at index 0). Empty list if given graph is not a DAG.
Return type:list
node_is_isolated(self, node, allow_self_loop=False)[source]

Checks if the project item with the given name has any connections.

Parameters:
  • node (str) – Project item name
  • allow_self_loop (bool) – If default (False), Self-loops are considered as an in-neighbor or an out-neighbor so the method returns False. If True, single node with a self-loop is considered isolated.
Returns:

True if project item has no in-neighbors nor out-neighbors, False if it does.

Single node with a self-loop is NOT isolated (returns False).

Return type:

bool

static source_nodes(g)[source]

Returns a list of source nodes in given graph. A source node has no incoming edges. This is determined by calculating the in-degree of each node in the graph. If nodes in-degree == 0, it is a source node

Parameters:g (DiGraph) – Graph to examine
Returns:List of source node names or an empty list is there are none.
Return type:list
static nodes_connected(dag, a, b)[source]

Checks if node a is connected to node b. Edge directions are ignored. If any of source node a’s ancestors or descendants have a path to destination node b, returns True. Also returns True if destination node b has a path to any of source node a’s ancestors or descendants.

Parameters:
  • dag (DiGraph) – Graph that contains nodes a and b
  • a (str) – Node name
  • b (str) – Another node name
Returns:

True if a and b are connected, False otherwise

Return type:

bool

static export_to_graphml(g, path)[source]

Export given graph to a path in GraphML format.

Parameters:
  • g (DiGraph) – Graph to export
  • path (str) – Full output path for GraphML file
Returns:

Operation success status

Return type:

bool

class executioner.ExecutionInstance(toolbox, execution_list)[source]

Bases: PySide2.QtCore.QObject

Class for the graph that is being executed. Contains references to files and resources advertised by project items so that project items downstream can find them.

Parameters:
  • toolbox (ToolboxUI) – QMainWindow instance
  • execution_list (list) – Ordered list of nodes to execute
graph_execution_finished_signal[source]
project_item_execution_finished_signal[source]
start_execution(self)[source]

Pops the next item from the execution list and starts executing it.

execute_project_item(self)[source]

Starts executing project item.

item_execution_finished(self, item_finish_state)[source]

Pop next project item to execute or finish current graph if there are no items left.

Parameters:
  • item_finish_state (int) – 0=Continue to next project item. -2=Stop executing this graph (happens when e.g.
  • does not find req. input files or something) (Tool) –
stop(self)[source]

Stops running project item and terminates current graph execution.

add_ds_ref(self, dialect, ref)[source]

Adds given database reference to a dictionary. Key is the dialect. If dialect is sqlite, value is a list of full paths to sqlite files. For other dialects, key is the dialect and value is a list of URLs to database servers.

Parameters:
  • dialect (str) – Dialect name (lower case)
  • ref (str) – Database reference
add_di_data(self, di_name, data)[source]

Adds given data from data interface to a list.

Parameters:
  • di_name (str) – Data interface name
  • data (dict) – Data to import
append_dc_refs(self, refs)[source]

Adds given file paths (Data Connection file references) to a list.

Parameters:refs (list) – List of file paths (references)
append_dc_files(self, files)[source]

Adds given project data file paths to a list.

Parameters:files (list) – List of file paths
append_tool_output_file(self, filepath)[source]

Adds given file path to a list containing paths to Tool output files.

Parameters:filepath (str) – Path to a tool output file (in tool result directory)
find_file(self, filename)[source]

Returns the first occurrence to full path to given file name or None if file was not found.

Parameters:filename (str) – Searched file name (no path) TODO: Change to pattern
Returns:Full path to file if found, None if not found
Return type:str
find_optional_files(self, pattern)[source]

Returns a list of found paths to files that match the given pattern.

Returns:List of (full) paths
Return type:list