spinetoolbox.project

Spine Toolbox project class.

authors
  1. Savolainen (VTT), E. Rinne (VTT)

date

10.1.2018

Module Contents

Classes

SpineToolboxProject

Class for Spine Toolbox projects.

Functions

_ranks(node_successors)

Calculates node ranks.

class spinetoolbox.project.SpineToolboxProject(toolbox, name, description, p_dir, project_item_model, settings, logger)[source]

Bases: spinetoolbox.metaobject.MetaObject

Class for Spine Toolbox projects.

Parameters
  • toolbox (ToolboxUI) – toolbox of this project

  • name (str) – Project name

  • description (str) – Project description

  • p_dir (str) – Project directory

  • project_item_model (ProjectItemModel) – project item tree model

  • settings (QSettings) – Toolbox settings

  • logger (LoggerInterface) – a logger instance

dag_execution_finished[source]

Emitted after a single DAG execution has finished.

project_execution_about_to_start[source]

Emitted just before the entire project is executed.

project_execution_finished[source]

Emitted after the entire project execution finishes.

connection_established[source]

Emitted after new connection has been added to project.

connection_about_to_be_removed[source]

Emitted before connection removal.

connection_replaced[source]

Emitted after a connection has been replaced by another.

item_added[source]

Emitted after a project item has been added.

item_about_to_be_removed[source]

Emitted before project item removal.

toolbox(self)[source]

Returns Toolbox main window.

Returns

main window

Return type

ToolboxUI

_create_project_structure(self, directory)[source]

Makes the given directory a Spine Toolbox project directory. Creates directories and files that are common to all projects.

Parameters

directory (str) – Abs. path to a directory that should be made into a project directory

Returns

True if project structure was created successfully, False otherwise

Return type

bool

call_set_name(self, name)[source]
call_set_description(self, description)[source]
set_name(self, name)[source]

Changes project name.

Parameters

name (str) – New project name

set_description(self, description)[source]

Set object description.

Parameters

description (str) – Object description

save(self, spec_paths)[source]

Collects project information and objects into a dictionary and writes it to a JSON file.

Parameters

spec_paths (dict) – List of absolute paths to specification files keyed by item type

Returns

True or False depending on success

Return type

bool

load(self, items_dict, connection_dicts)[source]

Populates project item model with items loaded from project file.

Parameters
  • items_dict (dict) – Dictionary containing all project items in JSON format

  • connection_dicts (list of dict) – List containing all connections in JSON format

get_item(self, name)[source]

Returns project item.

Parameters

name (str) – item’s name

Returns

project item

Return type

ProjectItem

get_items(self)[source]

Returns all project items.

Returns

all project items

Return type

list of ProjectItem

add_project_items(self, items_dict, set_selected=False, verbosity=True)[source]

Pushes an AddProjectItemsCommand to the toolbox undo stack.

make_project_tree_items(self, items_dict)[source]

Creates and returns a dictionary mapping category indexes to a list of corresponding LeafProjectTreeItem instances.

Parameters

items_dict (dict) – a mapping from item name to item dict

Returns

dict(QModelIndex, list(LeafProjectTreeItem))

_do_add_project_tree_items(self, category_ind, *project_tree_items, set_selected=False, verbosity=True)[source]

Adds LeafProjectTreeItem instances to project.

Parameters
  • category_ind (QModelIndex) – The category index

  • project_tree_items (LeafProjectTreeItem) – one or more LeafProjectTreeItem instances to add

  • set_selected (bool) – Whether to set item selected after the item has been added to project

  • verbosity (bool) – If True, prints message

rename_item(self, previous_name, new_name, rename_data_dir_message)[source]

Renames a project item

Parameters
  • previous_name (str) – item’s current name

  • new_name (str) – item’s new name

  • rename_data_dir_message (str) – message to show when renaming item’s data directory

Returns

True if item was renamed successfully, False otherwise

Return type

bool

property connections(self)[source]
find_connection(self, source_name, destination_name)[source]

Searches for a connection between given items.

Parameters
  • source_name (str) – source item’s name

  • destination_name (str) – destination item’s name

Returns

connection instance or None if there is no connection

Return type

Connection

connections_for_item(self, item_name)[source]

Returns connections that have given item as source or destination.

Parameters

item_name (str) – item’s name

Returns

connections connected to item

Return type

list of Connection

add_connection(self, connection, silent=False)[source]

Adds a connection to the project.

Parameters
  • connection (Connection) – connection to add

  • silent (bool) – If False, prints ‘Link establ…’ msg to Event Log

Returns

True if connection was added successfully, False otherwise

Return type

bool

remove_connection(self, connection)[source]

Removes a connection from the project.

Parameters

connection (Connection) – connection to remove

replace_connection(self, existing_connection, new_connection)[source]

Replaces an existing connection between items.

Replacing does not trigger any updates to the DAG or project items.

Parameters
  • existing_connection (Connection) – an established connection

  • new_connection (Connection) – connection to replace by

set_item_selected(self, item)[source]

Selects the given item.

Parameters

item (LeafProjectTreeItem) –

make_and_add_project_items(self, items_dict, set_selected=False, verbosity=True)[source]

Adds items to project at loading.

Parameters
  • items_dict (dict) – a mapping from item name to item dict

  • set_selected (bool) – Whether to set item selected after the item has been added to project

  • verbosity (bool) – If True, prints message

remove_all_items(self)[source]

Pushes a RemoveAllProjectItemsCommand to the Toolbox undo stack.

remove_project_items(self, *indexes, ask_confirmation=False)[source]

Pushes a RemoveProjectItemsCommand to the toolbox undo stack.

Parameters
  • *indexes (QModelIndex) – Indexes of the items in project item model

  • ask_confirmation (bool) – If True, shows ‘Are you sure?’ message box

remove_item_by_name(self, item_name, delete_data=False)[source]

Removes project item by its name.

Parameters
  • item_name (str) – Item’s name

  • delete_data (bool) – If set to True, deletes the directories and data associated with the item

do_remove_project_tree_items(self, *items, delete_data=False, silent=False)[source]

Removes LeafProjectTreeItem instances from project.

Parameters
  • *items (LeafProjectTreeItem) – the items to remove

  • delete_data (bool) – If set to True, deletes the directories and data associated with the item

  • silent (bool) – Used to prevent unnecessary log messages when switching projects

execute_dags(self, dags, execution_permits, msg)[source]

Executes given dags.

Parameters
  • dags (Sequence(DiGraph)) –

  • execution_permits (Sequence(dict)) –

get_node_successors(self, dag, dag_identifier)[source]
_execute_dags(self, dags, execution_permits_list)[source]
create_engine_worker(self, dag, execution_permits, dag_identifier, settings)[source]
_handle_engine_worker_finished(self, worker)[source]
dag_with_node(self, item_name)[source]
execute_selected(self)[source]

Executes DAGs corresponding to all selected project items.

execute_project(self)[source]

Executes all dags in the project.

stop(self)[source]

Stops execution. Slot for the main window Stop tool button in the toolbar.

notify_resource_changes_to_predecessors(self, item)[source]

Updates resources for direct predecessors of given item.

Parameters

item (ProjectItem) – item whose resources have changed

notify_resource_changes_to_successors(self, item)[source]

Updates resources for direct successors and outgoing connections of given item.

Parameters

item (ProjectItem) – item whose resources have changed

_notify_resource_changes(self, trigger_name, target_names, provider_connections, update_resources, trigger_resources)[source]

Updates resources in given direction for immediate neighbours of an item.

Parameters
  • trigger_name (str) – item whose resources have changed

  • target_names (list(str)) – items to be notified

  • provider_connections (function) – function that receives a target item name and returns a list of Connections from resource providers

  • update_resources (function) – function that takes an item name, a list of provider names, and a dictionary of resources, and does the updating

  • trigger_resources (list(ProjectItemResources)) – resources from the trigger item

notify_resource_replacement_to_successors(self, item, old, new)[source]

Replaces a resource for direct successors and outgoing connections of given item.

Parameters
  • item (ProjectItem) – item whose resources have changed

  • old (ProjectItemResource) – old resource

  • new (ProjectItemResource) – new resource

notify_resource_replacement_to_predecessors(self, item, old, new)[source]

Replaces a resource for direct predecessors.

Parameters
  • item (ProjectItem) – item whose resources have changed

  • old (ProjectItemResource) – old resource

  • new (ProjectItemResource) – new resource

_update_item_resources(self, target_item, direction)[source]

Updates up or downstream resources for a single project item. Called in both directions after removing a Connection.

Parameters
  • target_item (ProjectItem) – item whose resource need update

  • direction (ExecutionDirection) – FORWARD updates resources from upstream, BACKWARD from downstream

successor_names(self, name)[source]

Collects direct successor item names.

Parameters

name (str) – name of the project item whose successors to collect

Returns

direct successor names

Return type

set of str

_outgoing_connections(self, name)[source]

Collects outgoing connections.

Parameters

name (str) – name of the project item whose connections to collect

Returns

outgoing connections

Return type

set of Connection

_incoming_connections(self, name)[source]

Collects incoming connections.

Parameters

name (str) – name of the project item whose connections to collect

Returns

incoming connections

Return type

set of Connection

_update_successor(self, successor, incoming_connections, resource_cache)[source]
_update_predecessor(self, predecessor, outgoing_connections, resource_cache)[source]
_is_dag_valid(self, dag)[source]
_update_ranks(self, dag)[source]
property settings(self)[source]
tear_down(self, silent=False)[source]

Cleans up project.

spinetoolbox.project._ranks(node_successors)[source]

Calculates node ranks.

Parameters

node_successors (dict) – a mapping from successor name to a list of predecessor names

Returns

a mapping from node name to rank

Return type

dict