From dab328527a20bf74dd89e977243ca47cbb5a283c Mon Sep 17 00:00:00 2001 From: Nicanor Romero Venier Date: Thu, 16 Jul 2015 16:01:47 +0200 Subject: [PATCH 1/8] Added settings to specify server commands. Added commands for system shutdown and restart and for server restart. --- src/octoprint/server/api/settings.py | 13 ++++++++++++ src/octoprint/server/views.py | 1 + src/octoprint/settings.py | 11 +++++++--- .../static/js/app/viewmodels/settings.js | 15 ++++++++++++++ .../templates/dialogs/settings/server.jinja2 | 20 +++++++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/octoprint/templates/dialogs/settings/server.jinja2 diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 31e5235f..91728c1c 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -112,6 +112,13 @@ def getSettings(): "afterPrintResumed": None, "snippets": dict() } + }, + "server": { + "commands": { + "systemShutdownCommand": s.get(["server", "commands", "systemShutdownCommand"]), + "systemRestartCommand": s.get(["server", "commands", "systemRestartCommand"]), + "serverRestartCommand": s.get(["server", "commands", "serverRestartCommand"]) + } } } @@ -250,6 +257,12 @@ def setSettings(): continue s.saveScript("gcode", name, script.replace("\r\n", "\n").replace("\r", "\n")) + if "server" in data: + if "commands" in data["server"]: + if "systemShutdownCommand" in data["server"]["commands"].keys(): s.set(["server", "commands", "systemShutdownCommand"], data["server"]["commands"]["systemShutdownCommand"]) + if "systemRestartCommand" in data["server"]["commands"].keys(): s.set(["server", "commands", "systemRestartCommand"], data["server"]["commands"]["systemRestartCommand"]) + if "serverRestartCommand" in data["server"]["commands"].keys(): s.set(["server", "commands", "serverRestartCommand"], data["server"]["commands"]["serverRestartCommand"]) + if "plugins" in data: for plugin in octoprint.plugin.plugin_manager().get_implementations(octoprint.plugin.SettingsPlugin): plugin_id = plugin._identifier diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 4df458bb..dc278060 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -150,6 +150,7 @@ def index(): folders=(gettext("Folders"), dict(template="dialogs/settings/folders.jinja2", _div="settings_folders", custom_bindings=False)), appearance=(gettext("Appearance"), dict(template="dialogs/settings/appearance.jinja2", _div="settings_appearance", custom_bindings=False)), logs=(gettext("Logs"), dict(template="dialogs/settings/logs.jinja2", _div="settings_logs")), + server=(gettext("Server"), dict(template="dialogs/settings/server.jinja2", _div="settings_server", custom_bindings=False)), ) if enable_accesscontrol: templates["settings"]["entries"]["accesscontrol"] = (gettext("Access Control"), dict(template="dialogs/settings/accesscontrol.jinja2", _div="settings_users", custom_bindings=False)) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index f5fd85a2..4d4d58e6 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -104,6 +104,11 @@ default_settings = { "pathSuffix": "path" }, "maxSize": 100 * 1024, # 100 KB + "commands": { + "systemShutdownCommand": None, + "systemRestartCommand": None, + "serverRestartCommand": None + } }, "webcam": { "stream": None, @@ -188,7 +193,7 @@ default_settings = { "settings": [ "section_printer", "serial", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts", "section_features", "features", "webcam", "accesscontrol", "api", - "section_octoprint", "folders", "appearance", "logs", "plugin_pluginmanager", "plugin_softwareupdate" + "section_octoprint", "server", "folders", "appearance", "logs", "plugin_pluginmanager", "plugin_softwareupdate" ], "usersettings": ["access", "interface"], "generic": [] @@ -321,14 +326,14 @@ class Settings(object): "/dev/ttyACM0" - ``["serial", "timeouts"]`` :: + ``["serial", "timeout"]`` :: communication: 20.0 temperature: 5.0 sdStatus: 1.0 connection: 10.0 - ``["serial", "timeouts", "temperature"]`` :: + ``["serial", "timeout", "temperature"]`` :: 5.0 diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index c860402f..9b33f313 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -149,6 +149,10 @@ $(function() { self.terminalFilters = ko.observableArray([]); + self.server_commands_systemShutdownCommand = ko.observable(undefined); + self.server_commands_systemRestartCommand = ko.observable(undefined); + self.server_commands_serverRestartCommand = ko.observable(undefined); + self.settings = undefined; self.addTemperatureProfile = function() { @@ -415,6 +419,10 @@ $(function() { self.system_actions(response.system.actions); self.terminalFilters(response.terminalFilters); + + self.server_commands_systemShutdownCommand(response.server.commands.systemShutdownCommand); + self.server_commands_systemRestartCommand(response.server.commands.systemRestartCommand); + self.server_commands_serverRestartCommand(response.server.commands.serverRestartCommand); }; self.saveData = function (data, successCallback) { @@ -499,6 +507,13 @@ $(function() { "beforePrintResumed": self.scripts_gcode_beforePrintResumed(), "afterPrinterConnected": self.scripts_gcode_afterPrinterConnected() } + }, + "server": { + "commands": { + "systemShutdownCommand": self.server_commands_systemShutdownCommand(), + "systemRestartCommand": self.server_commands_systemRestartCommand(), + "serverRestartCommand": self.server_commands_serverRestartCommand() + } } }); } diff --git a/src/octoprint/templates/dialogs/settings/server.jinja2 b/src/octoprint/templates/dialogs/settings/server.jinja2 new file mode 100644 index 00000000..09bee222 --- /dev/null +++ b/src/octoprint/templates/dialogs/settings/server.jinja2 @@ -0,0 +1,20 @@ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
From 1cdd61fcbf662e90db71822ef59faa4d24683429 Mon Sep 17 00:00:00 2001 From: Nicanor Romero Venier Date: Mon, 20 Jul 2015 19:21:45 +0200 Subject: [PATCH 2/8] Added migration step for new settings. --- .../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 5a0da551..8bb68311 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -150,9 +150,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, "restart": "octoprint" }, }, - - "octoprint_restart_command": None, - "environment_restart_command": None, "pip_command": None, "cache_ttl": 24 * 60, @@ -177,10 +174,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 @@ -496,7 +502,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 1e192fe8..6e5f2295 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -84,8 +84,6 @@ $(function() { var data = { plugins: { softwareupdate: { - octoprint_restart_command: self.config_restartCommand(), - environment_restart_command: self.config_rebootCommand(), cache_ttl: parseInt(self.config_cacheTtl()) } } @@ -94,8 +92,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 cee30242..d649099d 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -55,18 +55,6 @@