Uranium
Application Framework
Loading...
Searching...
No Matches
UM.VersionUpgradeManager.VersionUpgradeManager Class Reference

Regulates the upgrading of configuration from one application version to the next. More...

Public Member Functions

"VersionUpgradeManager" getInstance (cls)
 Gets the instance of the VersionUpgradeManager, or creates one.
 
 __init__ (self)
 Initialises the version upgrade manager.
 
 getStoragePaths (self, configuration_type)
 Gets the paths where a specified type of file should be stored.
 
 setCurrentVersions (self, current_versions)
 Changes the target versions to upgrade to.
 
 registerCurrentVersion (self, version_info, type_info)
 
 upgrade (self)
 Performs the version upgrades of all configuration files to the most recent version.
 
 upgradeExtraFile (self, storage_path, file_name, configuration_type)
 Schedules an additional file for upgrading.
 
 copyVersionFolder (self, src_path, dest_path)
 
 getFileVersion (self, configuration_type, file_data)
 Gets the version of the given file data.
 
 updateFilesData (self, configuration_type, version, files_data, file_names_without_extension)
 

Protected Member Functions

 _addVersionUpgrade (self, version_upgrade_plugin)
 Adds a version upgrade plug-in.
 
 _findShortestUpgradeRoutes (self)
 Finds the next step to take to upgrade each combination of configuration type and version.
 
 _getFilesInDirectory (self, directory)
 Get the filenames of all files in a specified directory.
 
 _getUpgradeTasks (self)
 Gets all files that need to be upgraded.
 
 _storeOldFile (self, resource_directory, relative_path, old_version)
 Stores an old version of a configuration file away.
 
 _upgradeFile (self, storage_path_absolute, configuration_file, old_configuration_type)
 Upgrades a single file to any version in self._current_versions.
 
 _stripMimeTypeExtension (self, mime_type, file_name)
 

Protected Attributes

 _version_upgrades
 
 _get_version_functions
 
 _storage_paths
 
 _current_versions
 
 _upgrade_tasks
 
 _upgrade_routes
 
 _registry
 
 _addVersionUpgrade
 

Detailed Description

Regulates the upgrading of configuration from one application version to the next.

The process of upgrading will take a look at all profiles, preferences and machine instances and check their version numbers. If they are older than the current version number of their respective type of file, an upgrade route will be planned for it in order to upgrade the file to the current version in as few conversions as possible.

To this end, the upgrade manager will maintain the shortest routes to the current version for each of the types of profiles and each old version it encounters. Once a shortest route is found, it is cached and can be re-used for all nodes along this route. This minimises the extra start-up time required for the conversions.

Old versions of the configuration are not deleted, but put in a folder next to the current (upgraded) versions, where they are never loaded again unless the user manually retrieves the files.

Constructor & Destructor Documentation

◆ __init__()

UM.VersionUpgradeManager.VersionUpgradeManager.__init__ (   self)

Initialises the version upgrade manager.

This initialises the cache for shortest upgrade routes, and registers the version upgrade plug-ins.

Member Function Documentation

◆ _addVersionUpgrade()

UM.VersionUpgradeManager.VersionUpgradeManager._addVersionUpgrade (   self,
  version_upgrade_plugin 
)
protected

Adds a version upgrade plug-in.

This reads from the metadata which upgrades the plug-in can perform and sorts the upgrade functions in memory so that the upgrades can be used when an upgrade is requested.

Parameters
version_upgrade_pluginThe plug-in object of the version upgrade plug-in.

◆ _findShortestUpgradeRoutes()

UM.VersionUpgradeManager.VersionUpgradeManager._findShortestUpgradeRoutes (   self)
protected

Finds the next step to take to upgrade each combination of configuration type and version.

Returns
A dictionary of type/version pairs that map to functions that upgrade said data format one step towards the most recent version, such that the fewest number of steps is required.

◆ _getFilesInDirectory()

UM.VersionUpgradeManager.VersionUpgradeManager._getFilesInDirectory (   self,
  directory 
)
protected

Get the filenames of all files in a specified directory.

If an exclude path is given, the specified path is ignored (relative to the specified directory).

Parameters
directoryThe directory to read the files from.
Returns
The filename of each file relative to the specified directory.

◆ _getUpgradeTasks()

UM.VersionUpgradeManager.VersionUpgradeManager._getUpgradeTasks (   self)
protected

Gets all files that need to be upgraded.

Returns
A sequence of UpgradeTasks of files to upgrade.

◆ _storeOldFile()

UM.VersionUpgradeManager.VersionUpgradeManager._storeOldFile (   self,
  resource_directory,
  relative_path,
  old_version 
)
protected

Stores an old version of a configuration file away.

This old file is intended as a back-up. It will be stored in the ./old directory in the resource directory, in a subdirectory made specifically for the version of the old file. The subdirectory will mirror the directory structure of the original directory.

Parameters
resource_directoryThe resource directory of the configuration type of the file in question.
relative_pathThe path relative to the resource directory to the file in question.
old_versionThe version number in the file in question.

◆ _upgradeFile()

UM.VersionUpgradeManager.VersionUpgradeManager._upgradeFile (   self,
  storage_path_absolute,
  configuration_file,
  old_configuration_type 
)
protected

Upgrades a single file to any version in self._current_versions.

A single file will be taken as source file, but may result in any number of output files.

Parameters
storage_path_absoluteThe path where to find the file.
configuration_fileThe file to upgrade to a current version.
old_configuration_typeThe type of the configuration file before upgrading it.
Returns
True if the file was successfully upgraded, or False otherwise.

◆ getStoragePaths()

UM.VersionUpgradeManager.VersionUpgradeManager.getStoragePaths (   self,
  configuration_type 
)

Gets the paths where a specified type of file should be stored.

This differs from the storage path in the Resources class, since it also knows where to store old file types. This information is gathered from the upgrade plug-ins.

Parameters
configuration_typeThe type of configuration to be stored.
Returns
A set of storage paths for the specified configuration type.

◆ setCurrentVersions()

UM.VersionUpgradeManager.VersionUpgradeManager.setCurrentVersions (   self,
  current_versions 
)

Changes the target versions to upgrade to.

Parameters
current_versionsA dictionary of tuples of configuration types and their versions currently in use, and with each of these a tuple of where to store this type of file and its MIME type.

◆ upgrade()

UM.VersionUpgradeManager.VersionUpgradeManager.upgrade (   self)

Performs the version upgrades of all configuration files to the most recent version.

The upgrade plug-ins must all be loaded at this point, or no upgrades can be performed.

Returns
True if anything was upgraded, or False if it was already up to date.

◆ upgradeExtraFile()

UM.VersionUpgradeManager.VersionUpgradeManager.upgradeExtraFile (   self,
  storage_path,
  file_name,
  configuration_type 
)

Schedules an additional file for upgrading.

This method is intended to be called by upgrade plug-ins during upgrading, to make sure we also upgrade any extra files that should be added during the upgrade process. Note that the file is not immediately upgraded, but scheduled for upgrading. If this method is called while the upgrade() function is still running, it will get upgraded at the end of that run. If it is called while the upgrade() function is not running, it would get upgraded during the next call to upgrade().

Parameters
storage_pathThe path to where the specified type of file is stored.
file_nameThe path to the file to upgrade, relative to the storage path.
configuration_typeThe file type of the specified file.

The documentation for this class was generated from the following file: