From cce7389a42cdf1a8ef40072bd6d4ba401d3449dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 6 Oct 2019 18:32:19 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20SWU:=20More=20configuration=20optio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to select github_commit tracking, branch and pip target via UI. Closes #3295 --- .../plugins/softwareupdate/__init__.py | 33 +++++++++++++++++++ .../static/js/softwareupdate.js | 15 +++++++-- .../plugins/softwareupdate/pipTarget.jinja2 | 7 ++++ .../softwareupdate/trackedBranch.jinja2 | 6 ++++ .../templates/softwareupdate_settings.jinja2 | 2 ++ .../templates/softwareupdate_wizard.jinja2 | 8 +++-- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/pipTarget.jinja2 create mode 100644 src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/trackedBranch.jinja2 diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 533342b6b..eb5035777 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -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"] diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index bf67d2d9a..8fae05e5f 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -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() { diff --git a/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/pipTarget.jinja2 b/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/pipTarget.jinja2 new file mode 100644 index 000000000..2e68965d0 --- /dev/null +++ b/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/pipTarget.jinja2 @@ -0,0 +1,7 @@ +
+ +
+ + {{ _('You should normally not have to change this.') }} +
+
diff --git a/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/trackedBranch.jinja2 b/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/trackedBranch.jinja2 new file mode 100644 index 000000000..63ef78743 --- /dev/null +++ b/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/trackedBranch.jinja2 @@ -0,0 +1,6 @@ +
+ +
+ +
+
diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 5ffbebf02..9eb99ec75 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -101,8 +101,10 @@