diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 8a1259f7a..221007443 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -116,6 +116,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._console_logger = None + self._get_throttled = lambda: False + def initialize(self): self._console_logger = logging.getLogger("octoprint.plugins.pluginmanager.console") self._repository_cache_path = os.path.join(self.get_plugin_data_folder(), "plugins.json") @@ -148,6 +150,10 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._console_logger.setLevel(logging.DEBUG) self._console_logger.propagate = False + helpers = self._plugin_manager.get_helpers("pi_support", "get_throttled") + if helpers and "get_throttled" in helpers: + self._get_throttled = helpers["get_throttled"] + # decouple repository fetching from server startup self._fetch_all_data(do_async=True) @@ -352,6 +358,12 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, return self.command_toggle(plugin, command) def command_install(self, url=None, path=None, force=False, reinstall=None, dependency_links=False): + throttled = self._get_throttled() + if throttled and isinstance(throttled, dict) and throttled.get("current_issue", False): + # currently throttled, we refuse to run + return make_response("System is currently throttled, refusing to install " + "anything due to possible stability issues", 409) + if url is not None: if not any(map(lambda scheme: url.startswith(scheme + "://"), self.URL_SCHEMES)): raise ValueError("Invalid URL to pip install from") diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index e23043c0a..0cff5d58b 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -7,6 +7,9 @@ $(function() { self.printerState = parameters[2]; self.systemViewModel = parameters[3]; + // optional + self.piSupport = parameters[4]; + self.config_repositoryUrl = ko.observable(); self.config_repositoryTtl = ko.observable(); self.config_noticesUrl = ko.observable(); @@ -166,9 +169,13 @@ $(function() { }; self.enableRepoInstall = function(data) { - return self.enableManagement() && self.pipAvailable() && !self.safeMode() && self.online() && self.isCompatible(data); + return self.enableManagement() && self.pipAvailable() && !self.safeMode() && !self.throttled() && self.online() && self.isCompatible(data); }; + self.throttled = ko.pureComputed(function() { + return self.piSupport && self.piSupport.currentIssue(); + }); + self.invalidUrl = ko.pureComputed(function() { // supported pip install URL schemes, according to https://pip.pypa.io/en/stable/reference/pip_install/ var allowedUrlSchemes = ["http", "https", @@ -193,6 +200,7 @@ $(function() { return self.enableManagement() && self.pipAvailable() && !self.safeMode() + && !self.throttled() && self.online() && url !== undefined && url.trim() !== "" @@ -218,6 +226,7 @@ $(function() { return self.enableManagement() && self.pipAvailable() && !self.safeMode() + && !self.throttled() && name !== undefined && name.trim() !== "" && !self.invalidArchive(); @@ -460,6 +469,10 @@ $(function() { return; } + if (self.throttled()) { + return; + } + if (url === undefined) { url = self.installUrl(); } @@ -1119,7 +1132,8 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: PluginManagerViewModel, - dependencies: ["loginStateViewModel", "settingsViewModel", "printerStateViewModel", "systemViewModel"], + dependencies: ["loginStateViewModel", "settingsViewModel", "printerStateViewModel", "systemViewModel", "piSupportViewModel"], + optional: ["piSupportViewModel"], elements: ["#settings_plugin_pluginmanager"] }); }); diff --git a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 index 9d0ee36ff..5c3e8a772 100644 --- a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 +++ b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 @@ -20,6 +20,13 @@ {% endtrans %} {% endmacro %} +{% macro pluginmanager_throttled() %} +