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

Public Member Functions

None __init__ (self, Application application)
 
None registerIgnoredFile (self, str file_name)
 
Dict[int, Set[str]] getStoragePaths (self, str configuration_type)
 
None setCurrentVersions (self, Dict[Tuple[str, int], Any] current_versions)
 
None registerCurrentVersion (self, Tuple[str, int] version_info, Any type_info)
 
bool upgrade (self)
 
None upgradeExtraFile (self, str storage_path, str file_name, str configuration_type)
 
Optional[int] getFileVersion (self, str configuration_type, str file_data)
 
Optional[FilesDataUpdateResult] updateFilesData (self, str configuration_type, int version, List[str] files_data, List[str] file_names_without_extension)
 
"VersionUpgradeManager" getInstance (cls, *args, **kwargs)
 

Protected Member Functions

None _addVersionUpgrade (self, PluginObject version_upgrade_plugin)
 
Dict[Tuple[str, int], Tuple[str, int, Callable[[str, str], Optional[Tuple[List[str], List[str]]]]]] _findShortestUpgradeRoutes (self)
 
Iterator[str] _getFilesInDirectory (self, str directory)
 
Iterator[UpgradeTask] _getUpgradeTasks (self)
 
bool _upgradeFile (self, str storage_path_absolute, str configuration_file, str old_configuration_type)
 
str _stripMimeTypeExtension (self, MimeType mime_type, str file_name)
 

Protected Attributes

 _application = application
 
dict _version_upgrades = {}
 
dict _get_version_functions = {}
 
dict _storage_paths = {}
 
dict _current_versions = {}
 
collections.deque _upgrade_tasks = collections.deque()
 
dict _upgrade_routes = {}
 
PluginRegistry _registry = PluginRegistry.getInstance()
 
 _addVersionUpgrade
 
list _ignored_files
 

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__()

None UM.VersionUpgradeManager.VersionUpgradeManager.__init__ ( self,
Application application )
Initialises the version upgrade manager.

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

Member Function Documentation

◆ _addVersionUpgrade()

None UM.VersionUpgradeManager.VersionUpgradeManager._addVersionUpgrade ( self,
PluginObject 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.

:param version_upgrade_plugin: The plug-in object of the version upgrade plug-in.

◆ _findShortestUpgradeRoutes()

Dict[Tuple[str, int], Tuple[str, int, Callable[[str, str], Optional[Tuple[List[str], List[str]]]]]] UM.VersionUpgradeManager.VersionUpgradeManager._findShortestUpgradeRoutes ( self)
protected
Finds the next step to take to upgrade each combination of configuration
type and version.

:return: 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()

Iterator[str] UM.VersionUpgradeManager.VersionUpgradeManager._getFilesInDirectory ( self,
str 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).

:param directory: The directory to read the files from.
:return: The filename of each file relative to the specified directory. Note that without an * in the path, it
    will not look at sub directories.

◆ _getUpgradeTasks()

Iterator[UpgradeTask] UM.VersionUpgradeManager.VersionUpgradeManager._getUpgradeTasks ( self)
protected
Gets all files that need to be upgraded.

:return: A sequence of UpgradeTasks of files to upgrade.

◆ _upgradeFile()

bool UM.VersionUpgradeManager.VersionUpgradeManager._upgradeFile ( self,
str storage_path_absolute,
str configuration_file,
str 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.

:param storage_path_absolute: The path where to find the file.
:param configuration_file: The file to upgrade to a current version.
:param old_configuration_type: The type of the configuration file before upgrading it.
:return: True if the file was successfully upgraded, or False otherwise.

◆ getFileVersion()

Optional[int] UM.VersionUpgradeManager.VersionUpgradeManager.getFileVersion ( self,
str configuration_type,
str file_data )
Gets the version of the given file data

◆ getStoragePaths()

Dict[int, Set[str]] UM.VersionUpgradeManager.VersionUpgradeManager.getStoragePaths ( self,
str 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.

:param configuration_type: The type of configuration to be stored.
:return: A set of storage paths for the specified configuration type.

◆ registerIgnoredFile()

None UM.VersionUpgradeManager.VersionUpgradeManager.registerIgnoredFile ( self,
str file_name )
Registers a file to be ignored by version upgrade checks (eg log files).

:param file_name: The base file name of the file to be ignored.

◆ setCurrentVersions()

None UM.VersionUpgradeManager.VersionUpgradeManager.setCurrentVersions ( self,
Dict[Tuple[str, int], Any] current_versions )
Changes the target versions to upgrade to.

:param current_versions: A 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()

bool 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.

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

◆ upgradeExtraFile()

None UM.VersionUpgradeManager.VersionUpgradeManager.upgradeExtraFile ( self,
str storage_path,
str file_name,
str 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()``.

:param storage_path: The path to where the specified type of file is stored.
:param file_name: The path to the file to upgrade, relative to the storage path.
:param configuration_type: The file type of the specified file.

Member Data Documentation

◆ _ignored_files

list UM.VersionUpgradeManager.VersionUpgradeManager._ignored_files
protected
Initial value:
= [
".*\\.lock", # Don't upgrade the configuration file lock. It's not persistent.
"plugins\\.json", # plugins.json and packages.json need to remain the same for the version upgrade plug-ins.
"packages\\.json",
".*\\.log", # Don't process the log. It's not needed and it could be really big.
".*\\.log.?", # Don't process the backup of the log. It's not needed and it could be really big.
"3.[0-3]\\.*", # Don't upgrade folders that are back-ups from older version upgrades. Until v3.3 we stored the back-up in the config folder itself. "3.[0-3]/.*", "2.[0-7]\\.*", "2.[0-7]/.*", "cura\\.*", "cura/.*", "plugins\\.*", # Don't upgrade manually installed plug-ins.
"plugins/.*",
"./*packages\\.json",
"./*plugins\\.json"
]

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