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

Classes

ProjectUpgrader

Class to upgrade/convert projects from earlier versions to the current version.

Functions

_fix_1d_array_to_array(mappings)

Replaces ‘1d array’ with ‘array’ for parameter type in Importer mappings.

class spinetoolbox.project_upgrader.ProjectUpgrader(toolbox)[source]

Class to upgrade/convert projects from earlier versions to the current version.

Parameters

toolbox (ToolboxUI) – App main window instance

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, project_dir)[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

  • project_dir (str) – Path to current project directory

Returns

Upgraded project dictionary

Return type

dict

static upgrade_v1_to_v2(old, factories)[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

  • factories (dict) – Mapping of item type to item factory

Returns

Version 2 project dictionary

Return type

dict

upgrade_v2_to_v3(self, old, project_dir, factories)[source]

Upgrades version 2 project dictionary to version 3.

Changes:
  1. Move “specifications” from “project” -> “Tool” to just “project”

  2. The “mappings” from importer items are used to build Importer specifications

Parameters
  • old (dict) – Version 2 project dictionary

  • project_dir (str) – Path to current project directory

  • factories (dict) – Mapping of item type to item factory

Returns

Version 3 project dictionary

Return type

dict

static upgrade_v3_to_v4(old)[source]

Upgrades version 3 project dictionary to version 4.

Changes:
  1. Rename “Exporter” item type to “GdxExporter”

Parameters

old (dict) – Version 3 project dictionary

Returns

Version 4 project dictionary

Return type

dict

static upgrade_v4_to_v5(old)[source]

Upgrades version 4 project dictionary to version 5.

Changes:
  1. Get rid of “Combiner” items.

Parameters

old (dict) – Version 4 project dictionary

Returns

Version 5 project dictionary

Return type

dict

static upgrade_v5_to_v6(old, project_dir)[source]

Upgrades version 5 project dictionary to version 6.

Changes:
  1. Data store URL labels do not have ‘{’ and ‘}’ anymore

  2. Importer stores resource labels instead of serialized paths in “file_selection”.

  3. Gimlet’s “selections” is now called “file_selection”

  4. Gimlet stores resource labels instead of serialized paths in “file_selection”.

  5. Gimlet and Tool store command line arguments as serialized CmdLineArg objects, not serialized paths

Parameters

old (dict) – Version 5 project dictionary

Returns

Version 6 project dictionary

Return type

dict

static make_unique_importer_specification_name(importer_name, label, k)[source]
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

is_valid(self, v, p)[source]

Checks given project dict if it is valid for given version.

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_to_6(self, p, v)[source]

Checks that the given project JSON dictionary contains a valid version 2 to 6 Spine Toolbox project. Valid meaning, that it contains all required keys and values are of the correct type.

Parameters
  • p (dict) – Project information JSON

  • v (int) – Version

Returns

True if project is a valid version 2 project, False if it is not

Return type

bool

backup_project_file(self, project_dir, v)[source]

Makes a backup copy of project.json file.

force_save(self, p, project_dir)[source]

Saves given project dictionary to project.json file. Used to force save project.json file when the project dictionary has been upgraded.

spinetoolbox.project_upgrader._fix_1d_array_to_array(mappings)[source]

Replaces ‘1d array’ with ‘array’ for parameter type in Importer mappings.

With spinedb_api >= 0.3, ‘1d array’ parameter type was replaced by ‘array’. Other settings in a mapping are backwards compatible except the name.