From 57161dd9c3b3a98a3f60bf4dc0b7b775f55d1ef9 Mon Sep 17 00:00:00 2001 From: Nicanor Romero Venier Date: Mon, 20 Jul 2015 19:21:45 +0200 Subject: [PATCH] Added migration step for new settings. (cherry picked from commit 1cdd61f) --- .../plugins/softwareupdate/__init__.py | 22 ++++++++++++++----- .../static/js/softwareupdate.js | 4 ---- .../templates/softwareupdate_settings.jinja2 | 12 ---------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 42639e13..bed119f3 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -134,9 +134,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, "restart": "octoprint" }, }, - - "octoprint_restart_command": None, - "environment_restart_command": None, "pip_command": None, "cache_ttl": 24 * 60, @@ -161,10 +158,19 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache_ttl = self._settings.get_int(["cache_ttl"]) * 60 def get_settings_version(self): - return 3 + return 4 def on_settings_migrate(self, target, current=None): - if current is None or current == 2: + + if current is None or current == 3: + self._settings.global_set(["server", "commands", "systemRestartCommand"], self._settings.get(["environment_restart_command"])) + self._settings.global_set(["server", "commands", "serverRestartCommand"], self._settings.get(["octoprint_restart_command"])) + + self._settings.set(["environment_restart_command"], None) + self._settings.set(["octoprint_restart_command"], None) + self._settings.save() + + elif current == 2: # there might be some left over data from the time we still persisted everything to settings, # even the stuff that shouldn't be persisted but always provided by the hook - let's # clean up @@ -483,7 +489,11 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, if restart_type is not None and restart_type in ("octoprint", "environment"): # one of our updates requires a restart of either type "octoprint" or "environment". Let's see if # we can actually perform that - restart_command = self._settings.get(["%s_restart_command" % restart_type]) + + if restart_type == "octoprint": + restart_command = self._settings.global_get(["server", "commands", "systemRestartCommand"]) + elif restart_type == "environment": + restart_command = self._settings.global_get(["server", "commands", "serverRestartCommand"]) if restart_command is not None: self._send_client_message("restarting", dict(restart_type=restart_type, results=target_results)) diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index dbd0579e..ce72aa29 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -78,8 +78,6 @@ $(function() { var data = { plugins: { softwareupdate: { - octoprint_restart_command: self.config_restartCommand(), - environment_restart_command: self.config_rebootCommand(), cache_ttl: parseInt(self.config_cacheTtl()) } } @@ -88,8 +86,6 @@ $(function() { }; self._copyConfig = function() { - self.config_restartCommand(self.settings.settings.plugins.softwareupdate.octoprint_restart_command()); - self.config_rebootCommand(self.settings.settings.plugins.softwareupdate.environment_restart_command()); self.config_cacheTtl(self.settings.settings.plugins.softwareupdate.cache_ttl()); }; diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 96f01713..4bc64d43 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -55,18 +55,6 @@