From 61bd803942a970c1c84ffdf60e04324c4c2f088e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sat, 20 Jun 2015 00:56:26 +0200 Subject: [PATCH] Fix: Properly report if a plugin simply could not be found after installation Also more resilience towards odd version numbers that get mangled by python's package management (1.2.3a0 => 1.2.3a) --- .../plugins/pluginmanager/__init__.py | 21 ++++++++++++++++++- .../pluginmanager/static/js/pluginmanager.js | 15 +++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index e7bde03c..3b254b33 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -241,12 +241,31 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, package_name = plugin.origin.package_name package_version = plugin.origin.package_version versioned_package = "{package_name}-{package_version}".format(**locals()) + if package_name in installed or versioned_package in installed: + # exact match, we are done here new_plugin_key = key new_plugin = plugin break + + else: + # it might still be a version that got stripped by python's package resources, e.g. 1.4.5a0 => 1.4.5a + found = False + + for inst in installed: + if inst.startswith(versioned_package): + found = True + break + + if found: + new_plugin_key = key + new_plugin = plugin + break else: - return make_response("Could not find plugin that was installed", 500) + self._logger.warn("The plugin was installed successfully, but couldn't be found afterwards to initialize properly during runtime. Please restart OctoPrint.") + result = dict(result=True, url=url, needs_restart=True, needs_refresh=True, was_reinstalled=False, plugin="unknown") + self._send_result_notification("install", result) + return jsonify(result) self._plugin_manager.mark_plugin(new_plugin_key, uninstalled=False) self._plugin_manager.reload_plugins() diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index c8178d20..f7508851 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -511,11 +511,22 @@ $(function() { var name = "Unknown"; if (action == "install") { + var unknown = false; + if (data.hasOwnProperty("plugin")) { - name = data.plugin.name; + if (data.plugin == "unknown") { + unknown = true; + } else { + name = data.plugin.name; + } } - if (data.was_reinstalled) { + if (unknown) { + titleSuccess = _.sprintf(gettext("Plugin installed")); + textSuccess = gettext("A plugin was installed successfully, however it was impossible to detect which one. Please Restart OctoPrint to make sure everything will be registered properly"); + textRestart = textSuccess; + textReload = textSuccess; + } else if (data.was_reinstalled) { titleSuccess = _.sprintf(gettext("Plugin \"%(name)s\" reinstalled"), {name: name}); textSuccess = gettext("The plugin was reinstalled successfully"); textRestart = gettext("The plugin was reinstalled successfully, however a restart of OctoPrint is needed for that to take effect.");