Clean up the package manager a bit:

- Remove an unused method.
- Safely check if the plugin info exist
This commit is contained in:
Diego Prado Gesto 2018-05-11 11:43:34 +02:00
parent 6f402c9ea9
commit 7d725936ef

View file

@ -130,7 +130,6 @@ class CuraPackageManager(QObject):
return None return None
def getAllInstalledPackagesInfo(self) -> dict: def getAllInstalledPackagesInfo(self) -> dict:
# Add bundled, installed, and to-install packages to the set of installed package IDs # Add bundled, installed, and to-install packages to the set of installed package IDs
all_installed_ids = set() all_installed_ids = set()
@ -150,6 +149,7 @@ class CuraPackageManager(QObject):
if package_id in Application.getInstance().getRequiredPlugins(): if package_id in Application.getInstance().getRequiredPlugins():
continue continue
package_info = None
# Add bundled plugins # Add bundled plugins
if package_id in self._bundled_package_dict: if package_id in self._bundled_package_dict:
package_info = self._bundled_package_dict[package_id]["package_info"] package_info = self._bundled_package_dict[package_id]["package_info"]
@ -162,47 +162,24 @@ class CuraPackageManager(QObject):
if package_id in self._to_install_package_dict: if package_id in self._to_install_package_dict:
package_info = self._to_install_package_dict[package_id]["package_info"] package_info = self._to_install_package_dict[package_id]["package_info"]
if package_info is None:
continue
# We also need to get information from the plugin registry such as if a plugin is active # We also need to get information from the plugin registry such as if a plugin is active
if package_info["package_type"] == "plugin": package_info["is_active"] = self._plugin_registry.isActivePlugin(package_id)
package_info["is_active"] = self._plugin_registry.isActivePlugin(package_id)
else:
package_info["is_active"] = self._plugin_registry.isActivePlugin(package_id)
# If the package ID is in bundled, label it as such # If the package ID is in bundled, label it as such
if package_info["package_id"] in self._bundled_package_dict.keys(): package_info["is_bundled"] = package_info["package_id"] in self._bundled_package_dict.keys()
package_info["is_bundled"] = True
else:
package_info["is_bundled"] = False
# If there is not a section in the dict for this type, add it # If there is not a section in the dict for this type, add it
if package_info["package_type"] not in installed_packages_dict: if package_info["package_type"] not in installed_packages_dict:
installed_packages_dict[package_info["package_type"]] = [] installed_packages_dict[package_info["package_type"]] = []
# Finally, add the data # Finally, add the data
installed_packages_dict[package_info["package_type"]].append( package_info ) installed_packages_dict[package_info["package_type"]].append(package_info)
return installed_packages_dict return installed_packages_dict
def __convertPluginMetadataToPackageMetadata(self, plugin_metadata: dict) -> dict:
package_metadata = {
"package_id": plugin_metadata["id"],
"package_type": "plugin",
"display_name": plugin_metadata["plugin"]["name"],
"description": plugin_metadata["plugin"].get("description"),
"package_version": plugin_metadata["plugin"]["version"],
"cura_version": int(plugin_metadata["plugin"]["api"]),
"website": "",
"author_id": plugin_metadata["plugin"].get("author", "UnknownID"),
"author": {
"author_id": plugin_metadata["plugin"].get("author", "UnknownID"),
"display_name": plugin_metadata["plugin"].get("author", ""),
"email": "",
"website": "",
},
"tags": ["plugin"]
}
return package_metadata
# Checks if the given package is installed. # Checks if the given package is installed.
def isPackageInstalled(self, package_id: str) -> bool: def isPackageInstalled(self, package_id: str) -> bool:
return self.getInstalledPackageInfo(package_id) is not None return self.getInstalledPackageInfo(package_id) is not None