spinetoolbox.project_upgrader¶
Contains ProjectUpgrader class used in upgrading and converting projects and project dicts from earlier versions to the latest version.
| authors: |
|
|---|---|
| date: | 8.11.2019 |
Module Contents¶
Classes¶
ProjectUpgrader |
Class to upgrade/convert projects from earlier versions to the current version. |
-
class
spinetoolbox.project_upgrader.ProjectUpgrader(toolbox)[source]¶ Class to upgrade/convert projects from earlier versions to the current version.
Parameters: toolbox (ToolboxUI) – toolbox of this project -
upgrade_to_v1(self, project_dict, old_project_dir)[source]¶ Upgrades no version project dict to version 1. This may be removed when we no longer want to support upgrading legacy .proj projects to current ones.
-
upgrade(self, project_dict, project_dir)[source]¶ Upgrades the project described in given project dictionary to the latest version.
Parameters: - project_dict (dict) – Project configuration dictionary
- project_dir (str) – Path to current project directory
Returns: Latest version of the project info dictionary
Return type: dict
-
upgrade_to_latest(self, v, project_dict)[source]¶ Upgrades the given project dictionary to the latest version.
Parameters: - v (int) – Current version of the project dictionary
- project_dict (dict) – Project dictionary (JSON) to be upgraded
Returns: Upgraded project dictionary
Return type: dict
-
static
upgrade_v1_to_v2(old, item_makers)[source]¶ Upgrades version 1 project dictionary to version 2.
- Changes:
- objects -> items, tool_specifications -> specifications store project item dicts under [“items”][<project item name>] instead of using their categories as keys specifications must be a dict instead of a list Add specifications[“Tool”] that must be a dict Remove “short name” from all project items
Parameters: - old (dict) – Version 1 project dictionary
- item_makers (dict) – Mapping of item type to item class
Returns: Version 2 project dictionary
Return type: dict
-
upgrade_from_no_version_to_version_1(self, old, old_project_dir)[source]¶ Converts project information dictionaries without ‘version’ to version 1.
Parameters: - old (dict) – Project information JSON
- old_project_dir (str) – Path to old project directory
Returns: Project information JSON upgraded to version 1
Return type: dict
-
upgrade_connections(self, item_names, connections_old)[source]¶ Upgrades connections from old format to the new format.
- Old format. List of lists, e.g.
- New format. List of dicts, e.g.
-
static
upgrade_tool_specification_paths(spec_paths, old_project_dir)[source]¶ Upgrades a list of tool specifications paths to new format. Paths in (old) project directory (yes, old is correct) are converted to relative, others as absolute.
-
open_proj_json(self, proj_file_path)[source]¶ Opens an old style project file (.proj) for reading,
Parameters: proj_file_path (str) – Full path to the old .proj project file Returns: Project dictionary or None if the operation fails. Return type: dict
-
get_project_directory(self)[source]¶ Asks the user to select a new project directory. If the selected directory is already a Spine Toolbox project directory, asks if overwrite is ok. Used when opening a project from an old style project file (.proj).
Returns: Path to project directory or an empty string if operation is canceled. Return type: str
-
copy_data(self, proj_file_path, project_dir)[source]¶ Copies project item directories from the old project to the new project directory.
Parameters: - proj_file_path (str) – Path to .proj file
- project_dir (str) – New project directory
Returns: True if copying succeeded, False if it failed
Return type: bool
-
is_valid_v1(self, p)[source]¶ Checks that the given project JSON dictionary contains a valid version 1 Spine Toolbox project. Valid meaning, that it contains all required keys and values are of the correct type.
Parameters: p (dict) – Project information JSON Returns: True if project is a valid version 1 project, False if it is not Return type: bool
-
is_valid_v2(self, p)[source]¶ Checks that the given project JSON dictionary contains a valid version 2 Spine Toolbox project. Valid meaning, that it contains all required keys and values are of the correct type.
Parameters: p (dict) – Project information JSON Returns: True if project is a valid version 2 project, False if it is not Return type: bool
-