From e335055a9836326013c7bdd78a35fa3fe11d6482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 18 Jan 2023 15:36:10 +0100 Subject: [PATCH 01/24] =?UTF-8?q?=E2=9C=A8=20Install=20multiple=20plugins?= =?UTF-8?q?=20from=20a=20json=20file=20(export=20or=20basic=20list)=20(#47?= =?UTF-8?q?10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🚧 WIP: multi install of plugins from JSON export * 🚧 pmgr: Multi install works TODO: better tracking in install log of individual steps/results. * 🚧 Fix error reporting, improve working dialog * 🐛 Hide action buttons while still installing * 🚸 Confirmation dialog for json multi install * 🐛 Fix notifications for single installs Also: a typo --- .../plugins/pluginmanager/__init__.py | 196 +++++++++++++++--- .../static/css/pluginmanager.css | 2 +- .../pluginmanager/static/js/pluginmanager.js | 184 +++++++++++----- .../static/less/pluginmanager.less | 7 + 4 files changed, 304 insertions(+), 85 deletions(-) diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index a32123038..ecb2d7352 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -123,6 +123,7 @@ class PluginManagerPlugin( ARCHIVE_EXTENSIONS = (".zip", ".tar.gz", ".tgz", ".tar", ".gz", ".whl") PYTHON_EXTENSIONS = (".py",) + JSON_EXTENSIONS = (".json",) # valid pip install URL schemes according to https://pip.pypa.io/en/stable/reference/pip_install/ URL_SCHEMES = ( @@ -174,6 +175,7 @@ class PluginManagerPlugin( self._repository_available = False self._repository_plugins = [] + self._repository_plugins_by_id = {} self._repository_cache_path = None self._repository_cache_ttl = 0 self._repository_mtime = None @@ -192,6 +194,7 @@ class PluginManagerPlugin( self._install_task = None self._install_lock = threading.RLock() + self._jsoninstall_lock = threading.Lock() self._queued_installs = [] self._queued_installs_abort_timer = None @@ -348,7 +351,9 @@ class PluginManagerPlugin( return { "all": plugins, "thirdparty": list(filter(lambda p: not p["bundled"], plugins)), - "file_extensions": self.ARCHIVE_EXTENSIONS + self.PYTHON_EXTENSIONS, + "file_extensions": self.ARCHIVE_EXTENSIONS + + self.PYTHON_EXTENSIONS + + self.JSON_EXTENSIONS, } def get_template_types(self, template_sorting, template_rules, *args, **kwargs): @@ -391,7 +396,7 @@ class PluginManagerPlugin( exts = list( filter( lambda x: upload_name.lower().endswith(x), - self.ARCHIVE_EXTENSIONS + self.PYTHON_EXTENSIONS, + self.ARCHIVE_EXTENSIONS + self.PYTHON_EXTENSIONS + self.JSON_EXTENSIONS, ) ) if not len(exts): @@ -445,11 +450,15 @@ class PluginManagerPlugin( def export_plugin_list(self): import json - plugins = self.generate_plugins_json(self._settings, self._plugin_manager) + plugins = self.generate_plugins_json( + self._settings, + self._plugin_manager, + repo_plugins=self._repository_plugins_by_id, + ) return Response( json.dumps(plugins), - mimetype="text/plain", + mimetype="application/json", headers={"Content-Disposition": 'attachment; filename="plugin_list.json"'}, ) @@ -472,6 +481,7 @@ class PluginManagerPlugin( "supported_extensions": { "archive": self.ARCHIVE_EXTENSIONS, "python": self.PYTHON_EXTENSIONS, + "json": self.JSON_EXTENSIONS, }, } @@ -877,6 +887,18 @@ class PluginManagerPlugin( return False + def _is_jsonfile(self, path): + _, ext = os.path.splitext(path) + if ext in PluginManagerPlugin.JSON_EXTENSIONS: + import json + + try: + with open(path) as f: + json.load(f) + return True + except Exception as exc: + self._logger.exception(f"Could not parse {path} as json file: {exc}") + def command_install( self, url=None, @@ -885,6 +907,7 @@ class PluginManagerPlugin( force=False, reinstall=None, dependency_links=False, + partial=False, ): folder = None @@ -909,11 +932,25 @@ class PluginManagerPlugin( force=force, reinstall=reinstall, dependency_links=dependency_links, + partial=partial, ) elif self._is_pythonfile(path): result = self._command_install_pythonfile( - path, source=source, source_type=source_type, name=name + path, + source=source, + source_type=source_type, + name=name, + partial=partial, + ) + + elif self._is_jsonfile(path): + result = self._command_install_jsonfile( + path, + source=source, + source_type=source_type, + name=name, + partial=partial, ) else: @@ -927,7 +964,7 @@ class PluginManagerPlugin( "source_type": source_type, "reason": f"Could not fetch plugin from server, got {e}", } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) except exceptions.InvalidPackageFormat: self._logger.error( @@ -942,7 +979,7 @@ class PluginManagerPlugin( "reason": "Could not install plugin from {}, was neither " "a plugin archive nor a single file plugin".format(source), } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) except Exception: error_msg = ( @@ -957,7 +994,7 @@ class PluginManagerPlugin( "source_type": source_type, "reason": error_msg, } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) finally: if folder is not None: @@ -975,6 +1012,7 @@ class PluginManagerPlugin( force=False, reinstall=None, dependency_links=False, + partial=False, ): throttled = self._get_throttled() if ( @@ -995,7 +1033,7 @@ class PluginManagerPlugin( "source_type": source_type, "reason": error_msg, } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result from urllib.parse import quote as url_quote @@ -1049,11 +1087,11 @@ class PluginManagerPlugin( source ), } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result if is_python_mismatch(stderr): - return self.handle_python_mismatch(source, source_type) + return self.handle_python_mismatch(source, source_type, partial=partial) if force: # We don't use --upgrade here because that will also happily update all our dependencies - we'd rather @@ -1072,7 +1110,7 @@ class PluginManagerPlugin( source ), } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result if is_python_mismatch(stderr): @@ -1091,7 +1129,7 @@ class PluginManagerPlugin( "reason": "Could not parse output from pip, see plugin_pluginmanager_console.log " "for generated output", } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result # We'll need to fetch the "Successfully installed" line, strip the "Successfully" part, then split @@ -1118,7 +1156,7 @@ class PluginManagerPlugin( "source_type": source_type, "reason": "Pip did not report successful installation", } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result installed = list( @@ -1145,7 +1183,7 @@ class PluginManagerPlugin( "was_reinstalled": False, "plugin": "unknown", } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result self._plugin_manager.reload_plugins() @@ -1201,10 +1239,10 @@ class PluginManagerPlugin( or reinstall is not None, "plugin": self._to_external_plugin(new_plugin), } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result - def _handle_python_mismatch(self, source, source_type): + def _handle_python_mismatch(self, source, source_type, partial=False): self._logger.error( "Installing the plugin from {} failed, pip reported a Python version mismatch".format( source @@ -1217,11 +1255,13 @@ class PluginManagerPlugin( "reason": "Pip reported a Python version mismatch", "faq": "https://faq.octoprint.org/plugin-python-mismatch", } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result # noinspection DuplicatedCode - def _command_install_pythonfile(self, path, source=None, source_type=None, name=None): + def _command_install_pythonfile( + self, path, source=None, source_type=None, name=None, partial=False + ): if name is None: name = os.path.basename(path) @@ -1250,7 +1290,7 @@ class PluginManagerPlugin( ) ) result = PYTHON_MISMATCH - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result pythoncompat = metadata.get( @@ -1264,7 +1304,7 @@ class PluginManagerPlugin( ) ) result = PYTHON_MISMATCH - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result # copy plugin @@ -1279,7 +1319,7 @@ class PluginManagerPlugin( "source_type": source_type, "reason": "Plugin could not be copied", } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result plugins = self._plugin_manager.find_plugins(existing={}, ignore_uninstalled=False) @@ -1299,7 +1339,7 @@ class PluginManagerPlugin( "was_reinstalled": False, "plugin": "unknown", } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) return result self._plugin_manager.reload_plugins() @@ -1343,7 +1383,96 @@ class PluginManagerPlugin( "was_reinstalled": new_plugin.key in all_plugins_before, "plugin": self._to_external_plugin(new_plugin), } - self._send_result_notification("install", result) + self._send_result_notification("install", result, partial=partial) + return result + + def _command_install_jsonfile( + self, path, source=None, source_type=None, name=None, partial=False + ): + import json + + sub_results = [] + + try: + if not self._jsoninstall_lock.acquire(blocking=False): + self._logger.error( + "Attempting to install from json file from within an install running from a json install - this is not supported" + ) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Recursive json install", + } + self._send_result_notification("install", result, partial=partial) + return result + + if name is None: + name = os.path.basename(path) + + self._logger.info(f"Installing plugins from export {name} from {source}") + + with open(path) as f: + export = json.load(f) + + if not isinstance(export, list): + self._logger.error( + f"Installing plugins from export {name} from {source} failed, export is not a list" + ) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Invalid export", + } + self._send_result_notification("install", result, partial=partial) + return result + + for entry in export: + if isinstance(entry, dict): + archive = entry.get("archive") + name = None + + if archive is None: + if not self._repository_available: + continue + key = entry.get("key") + if not key: + continue + repo_entry = self._repository_plugins_by_id.get(key) + if not repo_entry: + continue + archive = repo_entry.get("archive") + if not archive: + continue + + elif isinstance(entry, str): + # just a URL? + archive = entry + + try: + message = f"Installing plugin from {archive}" + self._logger.info(message) + self._log_message(message) + sub_result = self.command_install( + url=archive, name=name, partial=True + ) + sub_results.append(sub_result) + + except Exception: + self._logger.exception( + f"Installing plugin from {archive} failed, continuing with next entry" + ) + finally: + self._jsoninstall_lock.release() + + result = { + "result": True, + "source": source, + "source_type": source_type, + "sub_results": sub_results, + } + self._send_result_notification("install", result, partial=partial) return result def command_uninstall(self, plugin, cleanup=False): @@ -1680,8 +1809,11 @@ class PluginManagerPlugin( return None - def _send_result_notification(self, action, result): - notification = {"type": "result", "action": action} + def _send_result_notification(self, action, result, partial=False): + notification = { + "type": "partial_result" if partial else "result", + "action": action, + } notification.update(result) self._plugin_manager.send_plugin_message(self._identifier, notification) @@ -1912,6 +2044,7 @@ class PluginManagerPlugin( self._repository_plugins = list( filter(lambda x: x is not None, map(map_repository_entry, repo_data)) ) + self._repository_plugins_by_id = {x["id"]: x for x in self._repository_plugins} return True def _is_notices_cache_valid(self, mtime=None): @@ -2089,7 +2222,11 @@ class PluginManagerPlugin( @staticmethod def generate_plugins_json( - settings, plugin_manager, ignore_bundled=True, ignore_plugins_folder=True + settings, + plugin_manager, + ignore_bundled=True, + ignore_plugins_folder=True, + repo_plugins=None, ): plugins = [] plugin_folder = settings.getBaseFolder("plugins") @@ -2102,7 +2239,10 @@ class PluginManagerPlugin( # ignore bundled or from the plugins folder already included in the backup continue - plugins.append({"key": plugin.key, "name": plugin.name, "url": plugin.url}) + data = {"key": plugin.key, "name": plugin.name, "url": plugin.url} + if repo_plugins and plugin.key in repo_plugins: + data["archive"] = repo_plugins[plugin.key]["archive"] + plugins.append(data) return plugins def _to_external_plugin(self, plugin): diff --git a/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css b/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css index fb903cebb..f843a51d1 100644 --- a/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css +++ b/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css @@ -1 +1 @@ -#settings_plugin_pluginmanager_pluginlist{height:calc(100vh - 450px);display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em;position:relative;border-top:1px solid #eee;padding-top:6px}#settings_plugin_pluginmanager_pluginlist>table{margin-top:0px}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_checkbox,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_checkbox{text-align:center;width:10px}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_checkbox input[type="checkbox"],#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_checkbox input[type="checkbox"]{margin-top:0}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name .prop,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name .prop{white-space:nowrap}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a.disabled,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_orphanlist{display:block;width:auto;max-height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_id,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_id{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a.disabled,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px !important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px;padding-right:10px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty{overflow:hidden;width:100%;height:400px;background-image:url("../img/repo_unavailable.png");text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{width:auto;height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .meta{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .stats .prop{white-space:nowrap}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:bold}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:bold;color:#990000}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#990000}#settings_plugin_pluginmanager_workingdialog_output .call{color:#000099} \ No newline at end of file +#settings_plugin_pluginmanager_pluginlist{height:calc(100vh - 450px);display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em;position:relative;border-top:1px solid #eee;padding-top:6px}#settings_plugin_pluginmanager_pluginlist>table{margin-top:0px}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_checkbox,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_checkbox{text-align:center;width:10px}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_checkbox input[type="checkbox"],#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_checkbox input[type="checkbox"]{margin-top:0}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name .prop,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name .prop{white-space:nowrap}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a.disabled,#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_orphanlist{display:block;width:auto;max-height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_id,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_id{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a.disabled,#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px !important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px;padding-right:10px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty{overflow:hidden;width:100%;height:400px;background-image:url("../img/repo_unavailable.png");text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{width:auto;height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .meta{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .stats .prop{white-space:nowrap}#settings_plugin_pluginmanager_workingdialog_output{font-size:.8em}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:bold}#settings_plugin_pluginmanager_workingdialog_output .separator{font-weight:bold;color:#666666}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:bold;color:#990000}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#990000}#settings_plugin_pluginmanager_workingdialog_output .call{color:#000099} \ No newline at end of file diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index 6afae8e33..9dd0c37d4 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -212,6 +212,7 @@ $(function () { self.online = ko.observable(); self.supportedArchiveExtensions = ko.observableArray([]); self.supportedPythonExtensions = ko.observableArray([]); + self.supportedJsonExtensions = ko.observableArray([]); var createExtensionsHelp = function (extensions) { return _.reduce( @@ -235,15 +236,21 @@ $(function () { self.supportedExtensionsHelp = ko.pureComputed(function () { var archiveExts = createExtensionsHelp(self.supportedArchiveExtensions()); var pythonExts = createExtensionsHelp(self.supportedPythonExtensions()); + var jsonExts = createExtensionsHelp(self.supportedJsonExtensions()); return _.sprintf( gettext( "This does not look like a valid plugin. Valid plugins should be " + "either archives installable via pip that " + "have the extension %(archiveExtensions)s, or single file python " + - "plugins with the extension %(pythonExtensions)s." + "plugins with the extension %(pythonExtensions)s, or a plugin list " + + "export with the extension %(jsonExtensions)s." ), - {archiveExtensions: archiveExts, pythonExtensions: pythonExts} + { + archiveExtensions: archiveExts, + pythonExtensions: pythonExts, + jsonExtensions: jsonExts + } ); }); @@ -429,21 +436,19 @@ $(function () { ); }); + self.hasExtension = function (name, extensions) { + const lowerName = name.toLocaleLowerCase(); + return extensions.some((ext) => lowerName.endsWith(ext)); + }; + self.invalidFile = ko.pureComputed(function () { var allowedFileExtensions = self .supportedArchiveExtensions() - .concat(self.supportedPythonExtensions()); + .concat(self.supportedPythonExtensions()) + .concat(self.supportedJsonExtensions()); var name = self.uploadFilename(); - var lowerName = name !== undefined ? name.toLocaleLowerCase() : undefined; - - var lowerNameHasExtension = function (extension) { - return _.endsWith(lowerName, extension); - }; - - return ( - name !== undefined && !_.any(allowedFileExtensions, lowerNameHasExtension) - ); + return name !== undefined && !self.hasExtension(name, allowedFileExtensions); }); self.enableFileInstall = ko.pureComputed(function () { @@ -468,18 +473,44 @@ $(function () { return false; } - self.uploadFilename(data.files[0].name); + var name = data.files[0].name; + self.uploadFilename(name); + var isJsonFile = + name !== undefined && + self.hasExtension(name, self.supportedJsonExtensions()); self.uploadButton.unbind("click"); self.uploadButton.bind("click", function () { - self._markWorking( - gettext("Installing plugin..."), - gettext("Installing plugin from uploaded file...") - ); - data.formData = { - dependency_links: self.followDependencyLinks() + const proceed = () => { + self._markWorking( + isJsonFile + ? gettext("Installing plugins...") + : gettext("Installing plugin..."), + isJsonFile + ? gettext("Installing plugins from uploaded file...") + : gettext("Installing plugin from uploaded file...") + ); + data.formData = { + dependency_links: self.followDependencyLinks() + }; + data.submit(); }; - data.submit(); + + if (isJsonFile) { + showConfirmationDialog({ + title: gettext("Confirm installation of multiple plugins"), + message: gettext( + "Please confirm you want to perform all plugins specified in the json file." + ), + cancel: gettext("Cancel"), + proceed: gettext("Install"), + proceedClass: "primary", + onproceed: proceed + }); + } else { + proceed(); + } + return false; }); }, @@ -736,6 +767,7 @@ $(function () { if (!data) return; self.supportedArchiveExtensions(data.archive || []); self.supportedPythonExtensions(data.python || []); + self.supportedJsonExtensions(data.json || []); }; self.dataPluginsDeferred = undefined; @@ -1617,35 +1649,77 @@ $(function () { }; self._processPluginManagementResult = function (response, action, plugin) { - if (response.result) { - if (self.queuedInstalls().length > 0 && action === "install") { - var plugin_dequeue = ko.utils.arrayFirst( - self.queuedInstalls(), - function (item) { - return item.url === response.source; - } - ); - if (plugin_dequeue) { - self.queuedInstalls.remove(plugin_dequeue); + if (response.type == "partial_result") { + if (!response.result) { + self.loglines.push({line: gettext("Error!"), stream: "error"}); + self.loglines.push({line: response.reason, stream: "error"}); + if (response.faq) { + self.loglines.push({ + line: _.sprintf( + gettext( + "You can find more info on this issue in the FAQ at %(url)s" + ), + {url: faq} + ), + stream: "error" + }); } - if (self.queuedInstalls().length === 0) { - self.multiInstallRunning(false); + } + + self.loglines.push({line: "", stream: "separator"}); + self.loglines.push({ + line: _.repeat("+", 50), + stream: "separator" + }); + self.loglines.push({line: "", stream: "separator"}); + } else { + if (response.result) { + if (self.queuedInstalls().length > 0 && action === "install") { + var plugin_dequeue = ko.utils.arrayFirst( + self.queuedInstalls(), + function (item) { + return item.url === response.source; + } + ); + if (plugin_dequeue) { + self.queuedInstalls.remove(plugin_dequeue); + } + if (self.queuedInstalls().length === 0) { + self.multiInstallRunning(false); + self._markDone(); + } + } else if (self.multiInstallRunning() && action === "install") { + // A MultiInstall job has finished + self.alertMultiInstallJobDone(response); + } else { self._markDone(); } - } else if (self.multiInstallRunning() && action === "install") { - // A MultiInstall job has finished - self.alertMultiInstallJobDone(response); } else { - self._markDone(); + self._markDone(response.reason, response.faq); } - } else { - self._markDone(response.reason, response.faq); } - self._displayPluginManagementNotification(response, action, plugin); + self._addPluginManagementLog(response, action, plugin); + self._displayPluginManagementNotification(); }; - self._displayPluginManagementNotification = function (response, action, plugin) { + self._extractActionAndNameFromResult = function (result) { + var action = result.action; + var name = "Unknown"; + if (result.hasOwnProperty("plugin")) { + if (result.plugin !== "unknown") { + if (_.isPlainObject(result.plugin)) { + name = result.plugin.name; + } else { + name = result.plugin; + } + } + } + + return {action: action, name: name}; + }; + + self._addPluginManagementLog = function (response, action, plugin) { self.logContents.action.restart = self.logContents.action.restart || response.needs_restart; self.logContents.action.refresh = @@ -1658,7 +1732,9 @@ $(function () { result: response.result, faq: response.faq }); + }; + self._displayPluginManagementNotification = function () { var title = gettext("Plugin management log"); var text = "