spinetoolbox.project_upgrader

Contains ProjectUpgrader class used in upgrading and converting projects and project dicts from earlier versions to the latest version.

authors:
  1. Savolainen (VTT)
date:

8.11.2019

Module Contents

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
is_valid(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
upgrade(self, project_dict, old_project_dir, new_project_dir)[source]

Converts the project described in given project description file to the latest version.

Parameters:
  • project_dict (dict) – Full path to project description file, ie. .proj or .json
  • old_project_dir (str) – Path to the original project directory
  • new_project_dir (str) – New project directory
Returns:

Latest version of the project info dictionary

Return type:

dict

static upgrade_to_latest(v, project_dict)[source]

Upgrades the given project dictionary to the latest version.

NOTE: Implement this when the structure of the project file needs to be changed.

Parameters:
  • v (int) – project version
  • project_dict (dict) – Project JSON to be converted
Returns:

Upgraded project information JSON

Return type:

dict

upgrade_from_no_version_to_version_1(self, old, old_project_dir, new_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
  • new_project_dir (str) – Path to new 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:Upgraded project information JSON or None if the operation failed
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