def _addVersionUpgrade(self, version_upgrade_plugin: PluginObject) -> None: meta_data = self._registry.getMetaData(version_upgrade_plugin.getPluginId()) if "version_upgrade" not in meta_data: Logger.log("w", "Version upgrade plug-in %s doesn't define any configuration types it can upgrade.", version_upgrade_plugin.getPluginId()) return # Don't need to add. # Additional metadata about the source types: How to recognise the version and where to find them. if "sources" in meta_data: for configuration_type, source in meta_data["sources"].items(): if "get_version" in source: self._get_version_functions[configuration_type] = source["get_version"] #May overwrite from other plug-ins that can also load the same configuration type. if "location" in source: if configuration_type not in self._storage_paths: self._storage_paths[configuration_type] = set() self._storage_paths[configuration_type] |= source["location"] upgrades = self._registry.getMetaData(version_upgrade_plugin.getPluginId())["version_upgrade"] for source, destination in upgrades.items(): # Each conversion that this plug-in can perform. source_type, source_version = source destination_type, destination_version, upgrade_function = destination # Fill in the dictionary representing the graph, if it doesn't have the keys yet. if (destination_type, destination_version) not in self._version_upgrades: self._version_upgrades[(destination_type, destination_version)] = set() self._version_upgrades[(destination_type, destination_version)].add((source_type, source_version, upgrade_function)) #Add the edge to the graph.
def _addVersionUpgrade(self, version_upgrade_plugin: PluginObject) -> None: """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. """ meta_data = self._registry.getMetaData( version_upgrade_plugin.getPluginId()) if "version_upgrade" not in meta_data: Logger.log( "w", "Version upgrade plug-in %s doesn't define any configuration types it can upgrade.", version_upgrade_plugin.getPluginId()) return # Don't need to add. # Take a note of the source version of each configuration type. The source directories defined in each version # upgrade should only be limited to that version. src_version_dict = {} for item in meta_data.get("version_upgrade", {}): configuration_type, src_version = item src_version_dict[configuration_type] = src_version # Additional metadata about the source types: How to recognise the version and where to find them. if "sources" in meta_data: for configuration_type, source in meta_data["sources"].items(): if "get_version" in source: self._get_version_functions[configuration_type] = source[ "get_version"] # May overwrite from other plug-ins that can also load the same configuration type. if "location" in source: if configuration_type in src_version_dict: src_version = src_version_dict[configuration_type] if configuration_type not in self._storage_paths: self._storage_paths[configuration_type] = {} if src_version not in self._storage_paths[ configuration_type]: self._storage_paths[configuration_type][ src_version] = set() self._storage_paths[configuration_type][ src_version] |= source["location"] upgrades = self._registry.getMetaData( version_upgrade_plugin.getPluginId())["version_upgrade"] for source, destination in upgrades.items( ): # Each conversion that this plug-in can perform. source_type, source_version = source destination_type, destination_version, upgrade_function = destination # Fill in the dictionary representing the graph, if it doesn't have the keys yet. if (destination_type, destination_version) not in self._version_upgrades: self._version_upgrades[(destination_type, destination_version)] = set() self._version_upgrades[( destination_type, destination_version)].add( (source_type, source_version, upgrade_function)) #Add the edge to the graph.
def addContainerType(cls, container: PluginObject) -> None: plugin_id = container.getPluginId() metadata = PluginRegistry.getInstance().getMetaData(plugin_id) if "settings_container" not in metadata or "mimetype" not in metadata[ "settings_container"]: raise Exception( "Plugin {plugin} has incorrect metadata: Expected a 'settings_container' block with a 'mimetype' entry" .format(plugin=plugin_id)) cls.addContainerTypeByName(container.__class__, plugin_id, metadata["settings_container"]["mimetype"])
def _addVersionUpgrade(self, version_upgrade_plugin: PluginObject) -> None: meta_data = self._registry.getMetaData(version_upgrade_plugin.getPluginId()) if "version_upgrade" not in meta_data: Logger.log("w", "Version upgrade plug-in %s doesn't define any configuration types it can upgrade.", version_upgrade_plugin.getPluginId()) return # Don't need to add. # Take a note of the source version of each configuration type. The source directories defined in each version # upgrade should only be limited to that version. src_version_dict = {} for item in meta_data.get("version_upgrade", {}): configuration_type, src_version = item src_version_dict[configuration_type] = src_version # Additional metadata about the source types: How to recognise the version and where to find them. if "sources" in meta_data: for configuration_type, source in meta_data["sources"].items(): if "get_version" in source: self._get_version_functions[configuration_type] = source["get_version"] # May overwrite from other plug-ins that can also load the same configuration type. if "location" in source: if configuration_type in src_version_dict: src_version = src_version_dict[configuration_type] if configuration_type not in self._storage_paths: self._storage_paths[configuration_type] = {} if src_version not in self._storage_paths[configuration_type]: self._storage_paths[configuration_type][src_version] = set() self._storage_paths[configuration_type][src_version] |= source["location"] upgrades = self._registry.getMetaData(version_upgrade_plugin.getPluginId())["version_upgrade"] for source, destination in upgrades.items(): # Each conversion that this plug-in can perform. source_type, source_version = source destination_type, destination_version, upgrade_function = destination # Fill in the dictionary representing the graph, if it doesn't have the keys yet. if (destination_type, destination_version) not in self._version_upgrades: self._version_upgrades[(destination_type, destination_version)] = set() self._version_upgrades[(destination_type, destination_version)].add((source_type, source_version, upgrade_function)) #Add the edge to the graph.
def test_getId_unhappy(): plugin = PluginObject() with pytest.raises(Exception): plugin.getPluginId() # We didn't set an id yet.
def test_getId_happy(): plugin = PluginObject() plugin.setPluginId("UltiBot") assert plugin.getPluginId() == "UltiBot"
def test_getId_unhappy(): plugin = PluginObject() with pytest.raises(ValueError): plugin.getPluginId() # We didn't set an id yet.