コード例 #1
0
ファイル: VersionUpgradeManager.py プロジェクト: ohrn/Uranium
    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.
コード例 #2
0
 def _addPluginObject(self, plugin_object: PluginObject, plugin_id: str, plugin_type: str) -> None:
     plugin_object.setPluginId(plugin_id)
     self._plugin_objects[plugin_id] = plugin_object
     try:
         self._type_register_map[plugin_type](plugin_object)
     except Exception as e:
         Logger.logException("e", "Unable to add plugin %s", plugin_id)
コード例 #3
0
 def _loadUpgrades(self, upgrades):
     registry = Application.getInstance().getPluginRegistry()
     for upgrade in upgrades:  # Artificially fill the plug-in registry with my own metadata!
         plugin_object = PluginObject()
         metadata = {  # Correctly fill the metadata for this plug-in.
             "plugin": {
                 "name":
                 "Upgrade Test",  # Note: Don't use internationalisation here, lest it be grabbed by gettext.
                 "author": "Ultimaker",
                 "version": "1.0",
                 "description": "Upgrade plug-in to test with.",
                 "api": 2
             },
             "version_upgrade": {}
         }
         metadata["version_upgrade"][upgrade["preference_type"]] = {}
         metadata["version_upgrade"][
             upgrade["preference_type"]]["from"] = upgrade["from_version"]
         metadata["version_upgrade"][
             upgrade["preference_type"]]["to"] = upgrade["to_version"]
         id = upgrade["preference_type"] + "-from-" + str(
             upgrade["from_version"]) + "-to-" + str(
                 upgrade["to_version"])  # ID becomes "type-from-#-to-#".
         plugin_object.setPluginId(id)
         registry._plugins[id] = plugin_object
         registry._meta_data[id] = metadata
         self._upgrade_manager._addVersionUpgrade(plugin_object)
コード例 #4
0
    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.
コード例 #5
0
ファイル: PluginRegistry.py プロジェクト: Ultimaker/Uranium
 def _addPluginObject(self, plugin_object: PluginObject, plugin_id: str, plugin_type: str) -> None:
     plugin_object.setPluginId(plugin_id)
     self._plugin_objects[plugin_id] = plugin_object
     try:
         self._type_register_map[plugin_type](plugin_object)
     except Exception as e:
         Logger.logException("e", "Unable to add plugin %s", plugin_id)
コード例 #6
0
 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"])
コード例 #7
0
ファイル: FileProvider.py プロジェクト: wjj11/Uranium
    def __init__(self) -> None:
        PluginObject.__init__(self)
        QObject.__init__(self)

        self.menu_item_display_text = None  # type: Optional[str]
        """
        Text that will be displayed as an option in the Open File(s) menu.
        """

        self.shortcut = None  # type: Optional[str]
        """
        Shortcut key combination (e.g. "Ctrl+O").
        """

        self.enabled = True
        """
        If the provider is not enabled, it should not be displayed in the interface.
        """

        self.priority = 0
        """
コード例 #8
0
 def _loadUpgrades(self, upgrades):
     registry = Application.getInstance().getPluginRegistry()
     for upgrade in upgrades: # Artificially fill the plug-in registry with my own metadata!
         plugin_object = PluginObject()
         metadata = { # Correctly fill the metadata for this plug-in.
             "plugin": {
                 "name": "Upgrade Test", # Note: Don't use internationalisation here, lest it be grabbed by gettext.
                 "author": "Ultimaker",
                 "version": "1.0",
                 "description": "Upgrade plug-in to test with.",
                 "api": 2
             },
             "version_upgrade": {}
         }
         metadata["version_upgrade"][upgrade["preference_type"]] = {}
         metadata["version_upgrade"][upgrade["preference_type"]]["from"] = upgrade["from_version"]
         metadata["version_upgrade"][upgrade["preference_type"]]["to"] = upgrade["to_version"]
         id = upgrade["preference_type"] + "-from-" + str(upgrade["from_version"]) + "-to-" + str(upgrade["to_version"]) # ID becomes "type-from-#-to-#".
         plugin_object.setPluginId(id)
         registry._plugins[id] = plugin_object
         registry._meta_data[id] = metadata
         self._upgrade_manager._addVersionUpgrade(plugin_object)
コード例 #9
0
    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.
コード例 #10
0
ファイル: __init__.py プロジェクト: lulzbackup/uranium
def register(app):
    return {"test": PluginObject()}
コード例 #11
0
def test_getId_unhappy():
    plugin = PluginObject()
    with pytest.raises(Exception):
        plugin.getPluginId()  # We didn't set an id yet.
コード例 #12
0
def test_getId_happy():
    plugin = PluginObject()
    plugin.setPluginId("UltiBot")
    assert plugin.getPluginId() == "UltiBot"
コード例 #13
0
def test_getVersion_happy():
    plugin = PluginObject()
    plugin.setVersion("12.0.0")
    assert plugin.getVersion() == "12.0.0"
コード例 #14
0
def test_getVersion_unhappy():
    plugin = PluginObject()
    with pytest.raises(Exception):
        plugin.getVersion()  # We didn't set a version yet.
コード例 #15
0
def test_getId_unhappy():
    plugin = PluginObject()
    with pytest.raises(ValueError):
        plugin.getPluginId()  # We didn't set an id yet.
コード例 #16
0
def test_getVersion_unhappy():
    plugin = PluginObject()
    with pytest.raises(ValueError):
        plugin.getVersion()  # We didn't set a version yet.