✨ pmgr: Support .whl uploads as well
Also refactored API & view model to share list of supported archive and python extensions for easier maintenance.
This commit is contained in:
1 parent
da90edd124
commit
6a10e94bde
3 files changed
+52
-3
No files matched your search
@@ -119,7 +119,7 @@ class PluginManagerPlugin(
|
||||
octoprint.plugin.EventHandlerPlugin,
|
||||
):
|
||||
|
||||
ARCHIVE_EXTENSIONS = (".zip", ".tar.gz", ".tgz", ".tar", ".gz")
|
||||
ARCHIVE_EXTENSIONS = (".zip", ".tar.gz", ".tgz", ".tar", ".gz", ".whl")
|
||||
PYTHON_EXTENSIONS = (".py",)
|
||||
|
||||
# valid pip install URL schemes according to https://pip.pypa.io/en/stable/reference/pip_install/
|
||||
@@ -463,6 +463,10 @@ class PluginManagerPlugin(
|
||||
},
|
||||
"safe_mode": safe_mode,
|
||||
"online": self._connectivity_checker.online,
|
||||
"supported_extensions": {
|
||||
"archive": self.ARCHIVE_EXTENSIONS,
|
||||
"python": self.PYTHON_EXTENSIONS,
|
||||
},
|
||||
}
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/plugins")
|
||||
@@ -489,6 +493,8 @@ class PluginManagerPlugin(
|
||||
hash_update(repr(self._notices))
|
||||
hash_update(repr(safe_mode))
|
||||
hash_update(repr(self._connectivity_checker.online))
|
||||
hash_update(repr(self.ARCHIVE_EXTENSIONS))
|
||||
hash_update(repr(self.PYTHON_EXTENSIONS))
|
||||
hash_update(repr(_DATA_FORMAT_VERSION))
|
||||
return hash.hexdigest()
|
||||
|
||||
|
||||
@@ -210,6 +210,40 @@ $(function () {
|
||||
|
||||
self.safeMode = ko.observable();
|
||||
self.online = ko.observable();
|
||||
self.supportedArchiveExtensions = ko.observableArray([]);
|
||||
self.supportedPythonExtensions = ko.observableArray([]);
|
||||
|
||||
var createExtensionsHelp = function (extensions) {
|
||||
return _.reduce(
|
||||
extensions,
|
||||
function (result, ext, index) {
|
||||
return (
|
||||
result +
|
||||
'"' +
|
||||
ext +
|
||||
'"' +
|
||||
(index < extensions.length - 2
|
||||
? ", "
|
||||
: index == extensions.length - 2
|
||||
? " " + gettext("and") + " "
|
||||
: "")
|
||||
);
|
||||
},
|
||||
""
|
||||
);
|
||||
};
|
||||
self.supportedExtensionsHelp = ko.pureComputed(function () {
|
||||
var archiveExts = createExtensionsHelp(self.supportedArchiveExtensions());
|
||||
var pythonExts = createExtensionsHelp(self.supportedPythonExtensions());
|
||||
|
||||
return _.sprintf(
|
||||
"This does not look like a valid plugin. Valid plugins should be " +
|
||||
"either archives installable via <code>pip</code> that " +
|
||||
"have the extension %(archiveExtensions)s, or single file python " +
|
||||
"plugins with the extension %(pythonExtensions)s.",
|
||||
{archiveExtensions: archiveExts, pythonExtensions: pythonExts}
|
||||
);
|
||||
});
|
||||
|
||||
self.requestError = ko.observable(false);
|
||||
|
||||
@@ -395,7 +429,9 @@ $(function () {
|
||||
});
|
||||
|
||||
self.invalidFile = ko.pureComputed(function () {
|
||||
var allowedFileExtensions = [".zip", ".tar.gz", ".tgz", ".tar", ".py"];
|
||||
var allowedFileExtensions = self
|
||||
.supportedArchiveExtensions()
|
||||
.concat(self.supportedPythonExtensions());
|
||||
|
||||
var name = self.uploadFilename();
|
||||
var lowerName = name !== undefined ? name.toLocaleLowerCase() : undefined;
|
||||
@@ -594,6 +630,12 @@ $(function () {
|
||||
}
|
||||
};
|
||||
|
||||
self.fromSupportedExtensionsResponse = function (data) {
|
||||
if (!data) return;
|
||||
self.supportedArchiveExtensions(data.archive || []);
|
||||
self.supportedPythonExtensions(data.python || []);
|
||||
};
|
||||
|
||||
self.dataPluginsDeferred = undefined;
|
||||
self.requestPluginData = function (options) {
|
||||
if (!_.isPlainObject(options)) {
|
||||
@@ -632,6 +674,7 @@ $(function () {
|
||||
self.requestError(false);
|
||||
self.fromPluginsResponse(data.plugins, options);
|
||||
self.fromPipResponse(data.pip);
|
||||
self.fromSupportedExtensionsResponse(data.supported_extensions);
|
||||
self.safeMode(data.safe_mode || false);
|
||||
deferred.resolveWith(data);
|
||||
});
|
||||
|
||||
@@ -339,7 +339,7 @@
|
||||
</div>
|
||||
<button id="settings_plugin_pluginmanager_repositorydialog_upload_start" class="btn btn-primary span3" data-bind="enable: enableFileInstall, css: {disabled: !enableFileInstall()}, click: function(){}">{{ _('Install') }}</button>
|
||||
</div>
|
||||
<span class="help-block" data-bind="visible: invalidFile">{{ _('This does not look like a valid plugin. Valid plugins should be either zip files or tarballs installable via <code>pip</code> that have the extension ".zip", ".tar.gz", ".tgz" or ".tar", or single file python plugins with the extension ".py"') }}</span>
|
||||
<span class="help-block" data-bind="visible: invalidFile, html: supportedExtensionsHelp"></span>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in new issue
Block a user