spinetoolbox.project
¶
Spine Toolbox project class.
- authors
Savolainen (VTT), E. Rinne (VTT)
- date
10.1.2018
Module Contents¶
Classes¶
Class for Spine Toolbox projects. |
Functions¶
|
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
- _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
- 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
- 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
- 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_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)) –
- 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