Merge branch 'maintenance' into devel
# Conflicts: # .pre-commit-config.yaml # setup.py # src/octoprint/plugins/pluginmanager/__init__.py # src/octoprint/server/api/printer.py # src/octoprint/server/api/printer_profiles.py # src/octoprint/server/api/settings.py # src/octoprint/util/commandline.py
This commit is contained in:
commit
a71f6fcd40
59 files changed
+962
-839
No files matched your search
@@ -19,7 +19,7 @@ import filetype
|
||||
import pkg_resources
|
||||
import requests
|
||||
import sarge
|
||||
from flask import jsonify, make_response
|
||||
from flask import Response, abort, jsonify, request
|
||||
from flask_babel import gettext
|
||||
|
||||
import octoprint.plugin
|
||||
@@ -27,13 +27,14 @@ import octoprint.plugin.core
|
||||
from octoprint.access import ADMIN_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.events import Events
|
||||
from octoprint.server import safe_mode
|
||||
from octoprint.server.util.flask import (
|
||||
check_etag,
|
||||
no_firstrun_access,
|
||||
with_revalidation_checking,
|
||||
)
|
||||
from octoprint.settings import valid_boolean_trues
|
||||
from octoprint.util import TemporaryDirectory, to_bytes
|
||||
from octoprint.util import TemporaryDirectory, deprecated, to_bytes
|
||||
from octoprint.util.net import download_file
|
||||
from octoprint.util.pip import create_pip_caller
|
||||
from octoprint.util.platform import get_os, is_os_compatible
|
||||
@@ -358,7 +359,7 @@ class PluginManagerPlugin(
|
||||
input_upload_path not in flask.request.values
|
||||
or input_upload_name not in flask.request.values
|
||||
):
|
||||
return flask.make_response("No file included", 400)
|
||||
abort(400, description="No file included")
|
||||
upload_path = flask.request.values[input_upload_path]
|
||||
upload_name = flask.request.values[input_upload_name]
|
||||
|
||||
@@ -369,9 +370,9 @@ class PluginManagerPlugin(
|
||||
)
|
||||
)
|
||||
if not len(exts):
|
||||
return flask.make_response(
|
||||
"File doesn't have a valid extension for a plugin archive or a single file plugin",
|
||||
abort(
|
||||
400,
|
||||
description="File doesn't have a valid extension for a plugin archive or a single file plugin",
|
||||
)
|
||||
|
||||
ext = exts[0]
|
||||
@@ -398,7 +399,7 @@ class PluginManagerPlugin(
|
||||
|
||||
with self._install_lock:
|
||||
if self._install_task is not None:
|
||||
return make_response("There's already a plugin being installed", 409)
|
||||
abort(409, description="There's already a plugin being installed")
|
||||
|
||||
self._install_task = threading.Thread(
|
||||
target=perform_install,
|
||||
@@ -419,16 +420,159 @@ class PluginManagerPlugin(
|
||||
def export_plugin_list(self):
|
||||
import json
|
||||
|
||||
import flask
|
||||
|
||||
plugins = self.generate_plugins_json(self._settings, self._plugin_manager)
|
||||
|
||||
return flask.Response(
|
||||
return Response(
|
||||
json.dumps(plugins),
|
||||
mimetype="text/plain",
|
||||
headers={"Content-Disposition": 'attachment; filename="plugin_list.json"'},
|
||||
)
|
||||
|
||||
def _plugin_response(self):
|
||||
return {
|
||||
"plugins": self._get_plugins(),
|
||||
"os": get_os(),
|
||||
"octoprint": get_octoprint_version_string(),
|
||||
"pip": {
|
||||
"available": self._pip_caller.available,
|
||||
"version": self._pip_caller.version_string,
|
||||
"install_dir": self._pip_caller.install_dir,
|
||||
"use_user": self._pip_caller.use_user,
|
||||
"virtual_env": self._pip_caller.virtual_env,
|
||||
"additional_args": self._settings.get(["pip_args"]),
|
||||
"python": sys.executable,
|
||||
},
|
||||
"safe_mode": safe_mode,
|
||||
"online": self._connectivity_checker.online,
|
||||
}
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/plugins")
|
||||
@Permissions.PLUGIN_PLUGINMANAGER_MANAGE.require(403)
|
||||
def retrieve_plugins(self):
|
||||
refresh = request.values.get("refresh", "false") in valid_boolean_trues
|
||||
if refresh or not self._is_notices_cache_valid():
|
||||
self._notices_available = self._refresh_notices()
|
||||
|
||||
def view():
|
||||
return jsonify(**self._plugin_response())
|
||||
|
||||
def etag():
|
||||
import hashlib
|
||||
|
||||
hash = hashlib.sha1()
|
||||
|
||||
def hash_update(value):
|
||||
value = value.encode("utf-8")
|
||||
hash.update(value)
|
||||
|
||||
hash_update(repr(self._get_plugins()))
|
||||
hash_update(str(self._notices_available))
|
||||
hash_update(repr(self._notices))
|
||||
hash_update(repr(safe_mode))
|
||||
hash_update(repr(self._connectivity_checker.online))
|
||||
hash_update(repr(_DATA_FORMAT_VERSION))
|
||||
return hash.hexdigest()
|
||||
|
||||
def condition():
|
||||
return check_etag(etag())
|
||||
|
||||
return with_revalidation_checking(
|
||||
etag_factory=lambda *args, **kwargs: etag(),
|
||||
condition=lambda *args, **kwargs: condition(),
|
||||
unless=lambda: refresh,
|
||||
)(view)()
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/plugins/<string:key>")
|
||||
@Permissions.PLUGIN_PLUGINMANAGER_MANAGE.require(403)
|
||||
def retrieve_specific_plugin(self, key):
|
||||
plugin = self._plugin_manager.get_plugin_info(key, require_enabled=False)
|
||||
if plugin is None:
|
||||
return abort(404)
|
||||
|
||||
return jsonify(plugin=self._to_external_plugin(plugin))
|
||||
|
||||
def _orphan_response(self):
|
||||
return {"orphan_data": self._get_orphans()}
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/orphans")
|
||||
@Permissions.PLUGIN_PLUGINMANAGER_MANAGE.require(403)
|
||||
def retrieve_plugin_orphans(self):
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_MANAGE.can():
|
||||
abort(403)
|
||||
|
||||
refresh = request.values.get("refresh", "false") in valid_boolean_trues
|
||||
if refresh:
|
||||
self._get_orphans(refresh=True)
|
||||
|
||||
def view():
|
||||
return jsonify(**self._orphan_response())
|
||||
|
||||
def etag():
|
||||
import hashlib
|
||||
|
||||
hash = hashlib.sha1()
|
||||
|
||||
def hash_update(value):
|
||||
value = value.encode("utf-8")
|
||||
hash.update(value)
|
||||
|
||||
hash_update(repr(self._get_orphans()))
|
||||
hash_update(repr(_DATA_FORMAT_VERSION))
|
||||
return hash.hexdigest()
|
||||
|
||||
def condition():
|
||||
return check_etag(etag())
|
||||
|
||||
return with_revalidation_checking(
|
||||
etag_factory=lambda *args, **kwargs: etag(),
|
||||
condition=lambda *args, **kwargs: condition(),
|
||||
unless=lambda: refresh,
|
||||
)(view)()
|
||||
|
||||
def _repository_response(self):
|
||||
return {
|
||||
"repository": {
|
||||
"available": self._repository_available,
|
||||
"plugins": self._repository_plugins,
|
||||
}
|
||||
}
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/repository")
|
||||
@Permissions.PLUGIN_PLUGINMANAGER_MANAGE.require(403)
|
||||
def retrieve_plugin_repository(self):
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_MANAGE.can():
|
||||
abort(403)
|
||||
|
||||
refresh = request.values.get("refresh", "false") in valid_boolean_trues
|
||||
if refresh or not self._is_repository_cache_valid():
|
||||
self._repository_available = self._refresh_repository()
|
||||
|
||||
def view():
|
||||
return jsonify(**self._repository_response())
|
||||
|
||||
def etag():
|
||||
import hashlib
|
||||
|
||||
hash = hashlib.sha1()
|
||||
|
||||
def hash_update(value):
|
||||
value = value.encode("utf-8")
|
||||
hash.update(value)
|
||||
|
||||
hash_update(str(self._repository_available))
|
||||
hash_update(repr(self._repository_plugins))
|
||||
hash_update(repr(_DATA_FORMAT_VERSION))
|
||||
return hash.hexdigest()
|
||||
|
||||
def condition():
|
||||
return check_etag(etag())
|
||||
|
||||
return with_revalidation_checking(
|
||||
etag_factory=lambda *args, **kwargs: etag(),
|
||||
condition=lambda *args, **kwargs: condition(),
|
||||
unless=lambda: refresh,
|
||||
)(view)()
|
||||
|
||||
def is_blueprint_protected(self):
|
||||
return False
|
||||
|
||||
@@ -458,97 +602,23 @@ class PluginManagerPlugin(
|
||||
"refresh_repository": [],
|
||||
}
|
||||
|
||||
def on_api_get(self, request):
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_MANAGE.can():
|
||||
return make_response("Insufficient rights", 403)
|
||||
|
||||
from octoprint.server import safe_mode
|
||||
|
||||
refresh_repository = (
|
||||
request.values.get("refresh_repository", "false") in valid_boolean_trues
|
||||
)
|
||||
if refresh_repository or not self._is_repository_cache_valid():
|
||||
self._repository_available = self._refresh_repository()
|
||||
|
||||
refresh_notices = (
|
||||
request.values.get("refresh_notices", "false") in valid_boolean_trues
|
||||
)
|
||||
if refresh_notices or not self._is_notices_cache_valid():
|
||||
self._notices_available = self._refresh_notices()
|
||||
|
||||
refresh_orphan = (
|
||||
request.values.get("refresh_orphans", "false") in valid_boolean_trues
|
||||
)
|
||||
|
||||
def view():
|
||||
return jsonify(
|
||||
plugins=self._get_plugins(),
|
||||
repository={
|
||||
"available": self._repository_available,
|
||||
"plugins": self._repository_plugins,
|
||||
},
|
||||
orphan_data=self._get_orphans(refresh=refresh_orphan),
|
||||
os=get_os(),
|
||||
octoprint=get_octoprint_version_string(),
|
||||
pip={
|
||||
"available": self._pip_caller.available,
|
||||
"version": self._pip_caller.version_string,
|
||||
"install_dir": self._pip_caller.install_dir,
|
||||
"use_user": self._pip_caller.use_user,
|
||||
"virtual_env": self._pip_caller.virtual_env,
|
||||
"additional_args": self._settings.get(["pip_args"]),
|
||||
"python": sys.executable,
|
||||
},
|
||||
safe_mode=safe_mode,
|
||||
online=self._connectivity_checker.online,
|
||||
)
|
||||
|
||||
def etag():
|
||||
import hashlib
|
||||
|
||||
hash = hashlib.sha1()
|
||||
|
||||
def hash_update(value):
|
||||
value = value.encode("utf-8")
|
||||
hash.update(value)
|
||||
|
||||
hash_update(repr(self._get_plugins()))
|
||||
hash_update(str(self._repository_available))
|
||||
hash_update(repr(self._repository_plugins))
|
||||
hash_update(str(self._notices_available))
|
||||
hash_update(repr(self._notices))
|
||||
hash_update(repr(self._get_orphans()))
|
||||
hash_update(repr(safe_mode))
|
||||
hash_update(repr(self._connectivity_checker.online))
|
||||
hash_update(repr(_DATA_FORMAT_VERSION))
|
||||
return hash.hexdigest()
|
||||
|
||||
def condition():
|
||||
return check_etag(etag())
|
||||
|
||||
return with_revalidation_checking(
|
||||
etag_factory=lambda *args, **kwargs: etag(),
|
||||
condition=lambda *args, **kwargs: condition(),
|
||||
unless=lambda: refresh_repository or refresh_notices or refresh_orphan,
|
||||
)(view)()
|
||||
|
||||
def on_api_command(self, command, data):
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_MANAGE.can():
|
||||
return make_response("Insufficient rights", 403)
|
||||
abort(403)
|
||||
|
||||
if self._printer.is_printing() or self._printer.is_paused():
|
||||
# do not update while a print job is running
|
||||
return make_response("Printer is currently printing or paused", 409)
|
||||
abort(409, description="Printer is currently printing or paused")
|
||||
|
||||
if command == "install":
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_INSTALL.can():
|
||||
return make_response("Insufficient rights", 403)
|
||||
abort(403)
|
||||
url = data["url"]
|
||||
plugin_name = data["plugin"] if "plugin" in data else None
|
||||
|
||||
with self._install_lock:
|
||||
if self._install_task is not None:
|
||||
return make_response("There's already a plugin being installed", 409)
|
||||
abort(409, description="There's already a plugin being installed")
|
||||
|
||||
self._install_task = threading.Thread(
|
||||
target=self.command_install,
|
||||
@@ -568,7 +638,7 @@ class PluginManagerPlugin(
|
||||
elif command == "uninstall":
|
||||
plugin_name = data["plugin"]
|
||||
if plugin_name not in self._plugin_manager.plugins:
|
||||
return make_response("Unknown plugin: %s" % plugin_name, 404)
|
||||
abort(404, description="Unknown plugin")
|
||||
|
||||
plugin = self._plugin_manager.plugins[plugin_name]
|
||||
return self.command_uninstall(plugin, cleanup=data.get("cleanup", False))
|
||||
@@ -589,11 +659,44 @@ class PluginManagerPlugin(
|
||||
elif command == "enable" or command == "disable":
|
||||
plugin_name = data["plugin"]
|
||||
if plugin_name not in self._plugin_manager.plugins:
|
||||
return make_response("Unknown plugin: %s" % plugin_name, 404)
|
||||
abort(404, description="Unknown plugin")
|
||||
|
||||
plugin = self._plugin_manager.plugins[plugin_name]
|
||||
return self.command_toggle(plugin, command)
|
||||
|
||||
@deprecated(
|
||||
"Deprecated API endpoint api/plugin/pluginmanager used. "
|
||||
"Please switch clients to plugin/pluginmanager/*",
|
||||
since="1.6.0",
|
||||
)
|
||||
def on_api_get(self, r):
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_MANAGE.can():
|
||||
abort(403)
|
||||
|
||||
refresh_repository = (
|
||||
request.values.get("refresh_repository", "false") in valid_boolean_trues
|
||||
)
|
||||
if refresh_repository or not self._is_repository_cache_valid():
|
||||
self._repository_available = self._refresh_repository()
|
||||
|
||||
refresh_notices = (
|
||||
request.values.get("refresh_notices", "false") in valid_boolean_trues
|
||||
)
|
||||
if refresh_notices or not self._is_notices_cache_valid():
|
||||
self._notices_available = self._refresh_notices()
|
||||
|
||||
refresh_orphan = (
|
||||
request.values.get("refresh_orphans", "false") in valid_boolean_trues
|
||||
)
|
||||
if refresh_orphan:
|
||||
self._get_orphans(refresh=True)
|
||||
|
||||
result = {}
|
||||
result.update(**self._plugin_response())
|
||||
result.update(**self._orphan_response())
|
||||
result.update(**self._repository_response())
|
||||
return jsonify(**result)
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
def _is_archive(self, path):
|
||||
_, ext = os.path.splitext(path)
|
||||
@@ -1076,15 +1179,15 @@ class PluginManagerPlugin(
|
||||
|
||||
def command_uninstall(self, plugin, cleanup=False):
|
||||
if plugin.key == "pluginmanager":
|
||||
return make_response("Can't uninstall Plugin Manager", 403)
|
||||
abort(403, description="Can't uninstall Plugin Manager")
|
||||
|
||||
if not plugin.managable:
|
||||
return make_response(
|
||||
"Plugin is not managable and hence cannot be uninstalled", 403
|
||||
abort(
|
||||
403, description="Plugin is not managable and hence cannot be uninstalled"
|
||||
)
|
||||
|
||||
if plugin.bundled:
|
||||
return make_response("Bundled plugins cannot be uninstalled", 403)
|
||||
abort(403, description="Bundled plugins cannot be uninstalled")
|
||||
|
||||
if plugin.origin is None:
|
||||
self._logger.warning(
|
||||
@@ -1092,7 +1195,7 @@ class PluginManagerPlugin(
|
||||
**locals()
|
||||
)
|
||||
)
|
||||
return make_response("Could not uninstall plugin, its origin is unknown")
|
||||
abort(500, description="Could not uninstall plugin, its origin is unknown")
|
||||
|
||||
if plugin.origin.type == "entry_point":
|
||||
# plugin is installed through entry point, need to use pip to uninstall it
|
||||
@@ -1105,9 +1208,9 @@ class PluginManagerPlugin(
|
||||
self._call_pip(pip_args)
|
||||
except Exception:
|
||||
self._logger.exception("Could not uninstall plugin via pip")
|
||||
return make_response(
|
||||
"Could not uninstall plugin via pip, see the log for more details",
|
||||
abort(
|
||||
500,
|
||||
description="Could not uninstall plugin via pip, see the log for more details",
|
||||
)
|
||||
|
||||
elif plugin.origin.type == "folder":
|
||||
@@ -1142,7 +1245,7 @@ class PluginManagerPlugin(
|
||||
**locals()
|
||||
)
|
||||
)
|
||||
return make_response("Could not uninstall plugin, its origin is unknown")
|
||||
abort(500, description="Could not uninstall plugin, its origin is unknown")
|
||||
|
||||
needs_restart = self._plugin_manager.is_restart_needing_plugin(plugin) or cleanup
|
||||
needs_refresh = plugin.implementation and isinstance(
|
||||
@@ -1330,7 +1433,7 @@ class PluginManagerPlugin(
|
||||
|
||||
def command_toggle(self, plugin, command):
|
||||
if plugin.key == "pluginmanager" or (plugin.hidden and plugin.bundled):
|
||||
return make_response("Can't enable/disable Plugin Manager", 400)
|
||||
abort(400, description="Can't enable/disable Plugin Manager")
|
||||
|
||||
pending = (command == "disable" and plugin.key in self._pending_enable) or (
|
||||
command == "enable" and plugin.key in self._pending_disable
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.get = function (refresh, opts) {
|
||||
console.log(
|
||||
"Deprecated endpoint OctoPrint.plugin.pluginmanager.get, " +
|
||||
"please use OctoPrint.plugin.pluginmanager.get*"
|
||||
);
|
||||
var refresh_repo, refresh_notices, refresh_orphans;
|
||||
if (_.isPlainObject(refresh)) {
|
||||
refresh_repo = refresh.repo || false;
|
||||
@@ -34,13 +38,41 @@
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.getWithRefresh = function (opts) {
|
||||
console.log(
|
||||
"Deprecated endpoint OctoPrint.plugin.pluginmanager.getWithRefresh, " +
|
||||
"please use OctoPrint.plugin.pluginmanager.get*"
|
||||
);
|
||||
return this.get(true, opts);
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.getWithoutRefresh = function (opts) {
|
||||
console.log(
|
||||
"Deprecated endpoint OctoPrint.plugin.pluginmanager.getWithoutRefresh, " +
|
||||
"please use OctoPrint.plugin.pluginmanager.get*"
|
||||
);
|
||||
return this.get(false, opts);
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.getPlugins = function (refresh, opts) {
|
||||
var url = this.base.getBlueprintUrl("pluginmanager") + "plugins";
|
||||
return this.base.get(url + (refresh ? "?refresh=true" : ""), opts);
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.getPlugin = function (plugin, opts) {
|
||||
var url = this.base.getBlueprintUrl("pluginmanager") + "plugins/" + plugin;
|
||||
return this.base.get(url, opts);
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.getOrphans = function (refresh, opts) {
|
||||
var url = this.base.getBlueprintUrl("pluginmanager") + "orphans";
|
||||
return this.base.get(url + (refresh ? "?refresh=true" : ""), opts);
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.getRepository = function (refresh, opts) {
|
||||
var url = this.base.getBlueprintUrl("pluginmanager") + "repository";
|
||||
return this.base.get(url + (refresh ? "?refresh=true" : ""), opts);
|
||||
};
|
||||
|
||||
OctoPrintPluginManagerClient.prototype.install = function (
|
||||
pluginUrl,
|
||||
dependencyLinks,
|
||||
|
||||
@@ -50,7 +50,7 @@ $(function () {
|
||||
return !item.enabled;
|
||||
}
|
||||
},
|
||||
"name",
|
||||
"popularity",
|
||||
[],
|
||||
[
|
||||
["bundled", "3rdparty"],
|
||||
@@ -174,7 +174,7 @@ $(function () {
|
||||
"#settings_plugin_pluginmanager_repositorydialog_upload_start"
|
||||
);
|
||||
|
||||
self.repositoryAvailable = ko.observable(false);
|
||||
self.repositoryAvailable = ko.observable(undefined);
|
||||
|
||||
self.repositorySearchQuery = ko.observable();
|
||||
self.repositorySearchQuery.subscribe(function () {
|
||||
@@ -499,17 +499,7 @@ $(function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
self.fromResponse = function (data, options) {
|
||||
self._fromPluginsResponse(data.plugins, options);
|
||||
self._fromOrphanResponse(data.orphan_data, options);
|
||||
self._fromRepositoryResponse(data.repository, options);
|
||||
self._fromPipResponse(data.pip, options);
|
||||
|
||||
self.safeMode(data.safe_mode || false);
|
||||
self.online(data.online !== undefined ? data.online : true);
|
||||
};
|
||||
|
||||
self._fromPluginsResponse = function (data, options) {
|
||||
self.fromPluginsResponse = function (data, options) {
|
||||
var evalNotices = options.eval_notices || false;
|
||||
var ignoreNoticeHidden = options.ignore_notice_hidden || false;
|
||||
var ignoreNoticeIgnored = options.ignore_notice_ignored || false;
|
||||
@@ -549,7 +539,7 @@ $(function () {
|
||||
self.plugins.updateItems(data);
|
||||
};
|
||||
|
||||
self._fromOrphanResponse = function (data) {
|
||||
self.fromOrphanResponse = function (data) {
|
||||
var orphans = [];
|
||||
_.each(data, function (value, key) {
|
||||
orphans.push({
|
||||
@@ -561,7 +551,7 @@ $(function () {
|
||||
self.orphans.updateItems(orphans);
|
||||
};
|
||||
|
||||
self._fromRepositoryResponse = function (data) {
|
||||
self.fromRepositoryResponse = function (data) {
|
||||
self.repositoryAvailable(data.available);
|
||||
if (data.available) {
|
||||
self.repositoryplugins.updateItems(data.plugins);
|
||||
@@ -570,7 +560,7 @@ $(function () {
|
||||
}
|
||||
};
|
||||
|
||||
self._fromPipResponse = function (data) {
|
||||
self.fromPipResponse = function (data) {
|
||||
self.pipAvailable(data.available);
|
||||
if (data.available) {
|
||||
self.pipVersion(data.version);
|
||||
@@ -588,41 +578,23 @@ $(function () {
|
||||
}
|
||||
};
|
||||
|
||||
self.dataDeferred = undefined;
|
||||
self.requestData = function (options) {
|
||||
self.dataPluginsDeferred = undefined;
|
||||
self.requestPluginData = function (options) {
|
||||
if (!_.isPlainObject(options)) {
|
||||
options = {
|
||||
refresh_repo: options,
|
||||
refresh_orphans: false,
|
||||
refresh_notices: false,
|
||||
eval_notices: false
|
||||
};
|
||||
options = {};
|
||||
}
|
||||
|
||||
options.refresh_repo = options.refresh_repo || false;
|
||||
options.refresh_orphans = options.refresh_orphans || false;
|
||||
options.refresh_notices = options.refresh_notices || false;
|
||||
options.eval_notices = options.eval_notices || false;
|
||||
|
||||
if (
|
||||
self.dataDeferred &&
|
||||
self.dataDeferred.state() === "pending" &&
|
||||
!options.refresh_repo &&
|
||||
!options.refresh_orphans &&
|
||||
!options.refresh_notices &&
|
||||
!options.eval_notices
|
||||
self.dataPluginsDeferred &&
|
||||
self.dataPluginsDeferred.state() === "pending" &&
|
||||
!!!options.refresh
|
||||
) {
|
||||
return self.dataDeferred.promise();
|
||||
return self.dataPluginsDeferred.promise();
|
||||
}
|
||||
|
||||
var deferred = new $.Deferred();
|
||||
if (
|
||||
!options.refresh_repo &&
|
||||
!options.refresh_orphans &&
|
||||
!options.refresh_notices &&
|
||||
!options.eval_notices
|
||||
) {
|
||||
self.dataDeferred = deferred;
|
||||
if (!!!options.refresh) {
|
||||
self.dataPluginsDeferred = deferred;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -635,18 +607,99 @@ $(function () {
|
||||
}
|
||||
|
||||
OctoPrint.plugins.pluginmanager
|
||||
.get({
|
||||
repo: options.refresh_repo,
|
||||
notices: options.refresh_notices,
|
||||
orphans: options.refresh_orphans
|
||||
})
|
||||
.getPlugins(!!options.refresh)
|
||||
.fail(function () {
|
||||
self.requestError(true);
|
||||
deferred.reject();
|
||||
})
|
||||
.done(function (data) {
|
||||
self.requestError(false);
|
||||
self.fromResponse(data, options);
|
||||
self.fromPluginsResponse(data.plugins, options);
|
||||
self.fromPipResponse(data.pip);
|
||||
self.safeMode(data.safe_mode || false);
|
||||
deferred.resolveWith(data);
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
self.dataOrphansDeferred = undefined;
|
||||
self.requestOrphanData = function (options) {
|
||||
if (!_.isPlainObject(options)) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (
|
||||
self.dataOrphansDeferred &&
|
||||
self.dataOrphansDeferred.state() === "pending" &&
|
||||
!!!options.refresh
|
||||
) {
|
||||
return self.dataOrphansDeferred.promise();
|
||||
}
|
||||
|
||||
var deferred = new $.Deferred();
|
||||
if (!!!options.refresh) {
|
||||
self.dataOrphansDeferred = deferred;
|
||||
}
|
||||
|
||||
if (
|
||||
!self.loginState.hasPermission(
|
||||
self.access.permissions.PLUGIN_PLUGINMANAGER_MANAGE
|
||||
)
|
||||
) {
|
||||
deferred.fail();
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
OctoPrint.plugins.pluginmanager
|
||||
.getOrphans(!!options.refresh)
|
||||
.fail(function () {
|
||||
deferred.reject();
|
||||
})
|
||||
.done(function (data) {
|
||||
self.fromOrphanResponse(data.orphans);
|
||||
deferred.resolveWith(data);
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
self.dataRepositoryDeferred = undefined;
|
||||
self.requestRepositoryData = function (options) {
|
||||
if (!_.isPlainObject(options)) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (
|
||||
self.dataRepositoryDeferred &&
|
||||
self.dataRepositoryDeferred.state() === "pending" &&
|
||||
!!!options.refresh
|
||||
) {
|
||||
return self.dataRepositoryDeferred.promise();
|
||||
}
|
||||
|
||||
var deferred = new $.Deferred();
|
||||
if (!!!options.refresh) {
|
||||
self.dataRepositoryDeferred = deferred;
|
||||
}
|
||||
|
||||
if (
|
||||
!self.loginState.hasPermission(
|
||||
self.access.permissions.PLUGIN_PLUGINMANAGER_MANAGE
|
||||
)
|
||||
) {
|
||||
deferred.fail();
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
OctoPrint.plugins.pluginmanager
|
||||
.getRepository(!!options.refresh)
|
||||
.fail(function () {
|
||||
deferred.reject();
|
||||
})
|
||||
.done(function (data) {
|
||||
self.fromRepositoryResponse(data.repository);
|
||||
self.online(data.online !== undefined ? data.online : true);
|
||||
deferred.resolveWith(data);
|
||||
});
|
||||
|
||||
@@ -669,7 +722,7 @@ $(function () {
|
||||
if (data.key === "pluginmanager") return;
|
||||
|
||||
var onSuccess = function () {
|
||||
self.requestData().always(function () {
|
||||
self.requestPluginData().always(function () {
|
||||
self.toggling(false);
|
||||
});
|
||||
},
|
||||
@@ -891,7 +944,7 @@ $(function () {
|
||||
OctoPrint.plugins.pluginmanager
|
||||
.uninstall(data.key, cleanup)
|
||||
.done(function () {
|
||||
self.requestData();
|
||||
self.requestPluginData();
|
||||
})
|
||||
.fail(function () {
|
||||
new PNotify({
|
||||
@@ -947,7 +1000,7 @@ $(function () {
|
||||
OctoPrint.plugins.pluginmanager
|
||||
.cleanup(key)
|
||||
.done(function () {
|
||||
self.requestData();
|
||||
self.requestOrphanData();
|
||||
})
|
||||
.fail(function () {
|
||||
new PNotify({
|
||||
@@ -1019,7 +1072,7 @@ $(function () {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
self.requestData({refresh_repo: true});
|
||||
self.requestRepositoryData({refresh: true});
|
||||
};
|
||||
|
||||
self.refreshNotices = function () {
|
||||
@@ -1027,8 +1080,8 @@ $(function () {
|
||||
return;
|
||||
}
|
||||
|
||||
self.requestData({
|
||||
refresh_notices: true,
|
||||
self.requestPluginData({
|
||||
refresh: true,
|
||||
eval_notices: true,
|
||||
ignore_notice_hidden: true,
|
||||
ignore_notice_ignored: true
|
||||
@@ -1040,7 +1093,7 @@ $(function () {
|
||||
return;
|
||||
}
|
||||
|
||||
self.requestData({
|
||||
self.requestPluginData({
|
||||
eval_notices: true,
|
||||
ignore_notice_hidden: true,
|
||||
ignore_notice_ignored: true
|
||||
@@ -1098,11 +1151,15 @@ $(function () {
|
||||
self.settingsViewModel.saveData(data, function () {
|
||||
self.configurationDialog.modal("hide");
|
||||
self._copyConfig();
|
||||
self.requestData({
|
||||
refresh_repo: true,
|
||||
refresh_notices: true,
|
||||
self.requestPluginData({
|
||||
refresh: true,
|
||||
eval_notices: true
|
||||
});
|
||||
if (self.repositoryAvailable() !== undefined) {
|
||||
self.requestRepositoryData({
|
||||
refresh: true
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1601,7 +1658,7 @@ $(function () {
|
||||
if (!self.hiddenNoticeNotifications[key]) return false;
|
||||
return _.any(
|
||||
_.map(self.hiddenNoticeNotifications[key], function (d) {
|
||||
return date == d;
|
||||
return date === d;
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -1656,14 +1713,25 @@ $(function () {
|
||||
self.access.permissions.PLUGIN_PLUGINMANAGER_MANAGE
|
||||
)
|
||||
) {
|
||||
self.requestData({eval_notices: true});
|
||||
self.requestPluginData({eval_notices: true});
|
||||
} else {
|
||||
self._resetNotifications();
|
||||
}
|
||||
};
|
||||
|
||||
self.onSettingsShown = function () {
|
||||
if (
|
||||
self.loginState.hasPermission(
|
||||
self.access.permissions.PLUGIN_PLUGINMANAGER_MANAGE
|
||||
)
|
||||
) {
|
||||
self.requestRepositoryData();
|
||||
self.requestOrphanData();
|
||||
}
|
||||
};
|
||||
|
||||
self.onEventConnectivityChanged = function (payload) {
|
||||
self.requestData({eval_notices: true});
|
||||
self.requestPluginData({eval_notices: true});
|
||||
};
|
||||
|
||||
self._resetNotifications = function () {
|
||||
@@ -1727,7 +1795,7 @@ $(function () {
|
||||
}
|
||||
|
||||
self._processPluginManagementResult(data, action, name);
|
||||
self.requestData();
|
||||
self.requestPluginData();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
</div>
|
||||
<div class="tab-pane" id="settings_plugin_pluginmanager_cleanup">
|
||||
<div class="pull-right">
|
||||
<button class="btn btn-small" data-bind="click: function() { $root.requestData({refresh_orphans: true}) }" title="{{ _('Refresh')|edq }}"><i class="fas fa-sync"></i></button>
|
||||
<button class="btn btn-small" data-bind="click: function() { $root.requestOrphanData({refresh: true}) }" title="{{ _('Refresh')|edq }}"><i class="fas fa-sync"></i></button>
|
||||
</div>
|
||||
|
||||
<h3>{{ _('Cleanup') }}</h3>
|
||||
|
||||
Reference in new issue
Block a user