✨ SWU: More configuration options

Allow to select github_commit tracking, branch and pip target via UI.

Closes #3295
This commit is contained in:
Gina Häußge committed 2019-10-06 18:32:19 +02:00
1 parent b138ea7a47
commit cce7389a42
6 files changed
+65 -6

No files matched your search

@@ -316,6 +316,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
checks = self._get_configured_checks()
if "octoprint" in checks:
data["octoprint_checkout_folder"] = self._get_octoprint_checkout_folder(checks=checks)
data["octoprint_tracked_branch"] = self._get_octoprint_tracked_branch(checks=checks)
data["octoprint_pip_target"] = self._get_octoprint_pip_target(checks=checks)
data["octoprint_type"] = checks["octoprint"].get("type", None)
try:
@@ -386,11 +388,24 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._settings.set(["checks", "octoprint", "method"], "pip", defaults=defaults)
updated_octoprint_check_config = True
elif octoprint_type == "github_commit":
self._settings.set(["checks", "octoprint", "type"], octoprint_type, defaults=defaults)
self._settings.set(["checks", "octoprint", "method"], "pip", defaults=defaults)
updated_octoprint_check_config = True
elif octoprint_type == "git_commit":
self._settings.set(["checks", "octoprint", "type"], octoprint_type, defaults=defaults)
self._settings.set(["checks", "octoprint", "method"], "update_script", defaults=defaults)
updated_octoprint_check_config = True
if "octoprint_tracked_branch" in data:
self._settings.set(["checks", "octoprint", "branch"], data["octoprint_tracked_branch"], defaults=defaults, force=True)
updated_octoprint_check_config = True
if "octoprint_pip_target" in data:
self._settings.set(["checks", "octoprint", "pip"], data["octoprint_pip_target"], defaults=defaults)
updated_octoprint_check_config = True
if "octoprint_release_channel" in data:
prerelease_branches = self._settings.get(["checks", "octoprint", "prerelease_branches"])
if prerelease_branches and data["octoprint_release_channel"] in [x["branch"] for x in prerelease_branches]:
@@ -1245,6 +1260,24 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
return None
def _get_octoprint_tracked_branch(self, checks=None):
if checks is None:
checks = self._get_configured_checks()
if not "octoprint" in checks:
return None
return checks["octoprint"].get("branch")
def _get_octoprint_pip_target(self, checks=None):
if checks is None:
checks = self._get_configured_checks()
if not "octoprint" in checks:
return None
return checks["octoprint"].get("pip")
def _register_custom_events(*args, **kwargs):
return ["update_succeeded", "update_failed"]
@@ -30,7 +30,8 @@ $(function() {
self.octoprintReleasedVersion = ko.observable();
self.octoprintUnconfigured = ko.pureComputed(function() {
return self.error_checkoutFolder();
return self.settings.settings.plugins.softwareupdate.octoprint_type() === "git_commit"
&& self.error_checkoutFolder();
});
self.octoprintUnreleased = ko.pureComputed(function() {
return self.settings.settings.plugins.softwareupdate.octoprint_type() === "github_release"
@@ -47,7 +48,9 @@ $(function() {
self.config_cacheTtl = ko.observable();
self.config_notifyUsers = ko.observable();
self.config_trackedBranch = ko.observable();
self.config_checkoutFolder = ko.observable();
self.config_pipTarget = ko.observable();
self.config_checkType = ko.observable();
self.config_releaseChannel = ko.observable();
@@ -62,6 +65,7 @@ $(function() {
self.enable_configSave = ko.pureComputed(function() {
return self.config_checkType() === "github_release"
|| self.config_checkType() === "github_commit"
|| (self.config_checkType() === "git_commit" && !self.error_checkoutFolder());
});
@@ -158,7 +162,9 @@ $(function() {
notify_users: self.config_notifyUsers(),
octoprint_type: self.config_checkType(),
octoprint_release_channel: self.config_releaseChannel(),
octoprint_checkout_folder: self.config_checkoutFolder()
octoprint_checkout_folder: self.config_checkoutFolder(),
octoprint_tracked_branch: self.config_trackedBranch(),
octoprint_pip_target: self.config_pipTarget()
}
}
};
@@ -177,7 +183,8 @@ $(function() {
self._copyConfig = function() {
var availableCheckTypes = [{"key": "github_release", "name": gettext("Release")},
{"key": "git_commit", "name": gettext("Commit")}];
{"key": "github_commit", "name": gettext("Github Commit")},
{"key": "git_commit", "name": gettext("Local checkout")}];
self.config_availableCheckTypes(availableCheckTypes);
var availableReleaseChannels = [];
@@ -192,6 +199,8 @@ $(function() {
self.config_checkType(self.settings.settings.plugins.softwareupdate.octoprint_type());
self.config_releaseChannel(self.settings.settings.plugins.softwareupdate.octoprint_release_channel());
self.config_checkoutFolder(self.settings.settings.plugins.softwareupdate.octoprint_checkout_folder());
self.config_trackedBranch(self.settings.settings.plugins.softwareupdate.octoprint_tracked_branch());
self.config_pipTarget(self.settings.settings.plugins.softwareupdate.octoprint_pip_target());
};
self._copyConfigBack = function() {
@@ -0,0 +1,7 @@
<div class="control-group" data-bind="visible: config_checkType() === 'github_release' || config_checkType() === 'github_commit'">
<label class="control-label">{{ _('<code>pip</code> target') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: config_pipTarget">
<span class="help-block">{{ _('You should normally not have to change this.') }}</span>
</div>
</div>
@@ -0,0 +1,6 @@
<div class="control-group" data-bind="visible: config_checkType() === 'github_commit'">
<label class="control-label">{{ _('Tracked branch') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: config_trackedBranch" placeholder="master">
</div>
</div>
@@ -101,8 +101,10 @@
<div class="modal-body">
<form class="form-horizontal">
{% include "snippets/plugins/softwareupdate/versionTracking.jinja2" %}
{% include "snippets/plugins/softwareupdate/trackedBranch.jinja2" %}
{% include "snippets/plugins/softwareupdate/checkoutFolder.jinja2" %}
{% include "snippets/plugins/softwareupdate/releaseChannel.jinja2" %}
{% include "snippets/plugins/softwareupdate/pipTarget.jinja2" %}
<div class="control-group">
<label class="control-label">{{ _('Version cache TTL') }}</label>
<div class="controls">
@@ -1,17 +1,19 @@
<h3>{{ _('Software Update') }}</h3>
{% trans %}<p>
By default, OctoPrint will update itself via <code>pip</code> to published releases. OctoPrint can
also update itself via <code>git</code> to arbitrary development branches you need to check out manually.
By default, OctoPrint will update itself via <code>pip</code> to published releases or commits pushed
to Github. OctoPrint can also update itself via <code>git</code> to arbitrary development branches you need to check out manually.
If you want to do that though it needs to know its checkout folder. You can configure that here.
</p>{% endtrans %}
<form class="form-horizontal">
{% include "snippets/plugins/softwareupdate/versionTracking.jinja2" %}
{% include "snippets/plugins/softwareupdate/checkoutFolder.jinja2" %}
{% include "snippets/plugins/softwareupdate/trackedBranch.jinja2" %}
</form>
{% trans %}<p>
If you are running a release version of OctoPrint, leave at "Release" tracking. If you are running a different
branch however, you should setup "Commit" tracking.
branch however on a manual checkout, you should setup "Local Checkout" tracking. For more special cases you might
want to select "Github Commit" tracking - you normally shouldn't need to however.
</p>{% endtrans %}