diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 8bb68311..985e8020 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -178,18 +178,31 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, def on_settings_migrate(self, target, current=None): - 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"])) + if current is None or current < 4: + # config version 4 and higher moves octoprint_restart_command and + # environment_restart_command to the core configuration + # current plugin commands + configured_octoprint_restart_command = self._settings.get(["octoprint_restart_command"]) + configured_environment_restart_command = self._settings.get(["environment_restart_command"]) + + # current global commands + configured_system_restart_command = self._settings.global_get(["server", "commands", "systemRestartCommand"]) + configured_server_restart_command = self._settings.global_get(["server", "commands", "serverRestartCommand"]) + + # only set global commands if they are not yet set + if configured_system_restart_command is None and configured_environment_restart_command is not None: + self._settings.global_set(["server", "commands", "systemRestartCommand"], configured_environment_restart_command) + if configured_server_restart_command is None and configured_octoprint_restart_command is not None: + self._settings.global_set(["server", "commands", "serverRestartCommand"], configured_octoprint_restart_command) + + # delete current plugin commands from config 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 + if current is None or current == 2: + # No config version and config version 2 need the same fix, stripping + # accidentally persisted data off the checks configured_checks = self._settings.get(["checks"], incl_defaults=False) if configured_checks is None: @@ -235,6 +248,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._settings.set(["checks", key], None, defaults=dummy_defaults) elif current == 1: + # config version 1 had the error that the octoprint check got accidentally + # included in checks["octoprint"], leading to recursion and hence to + # yaml parser errors + configured_checks = self._settings.get(["checks"], incl_defaults=False) if configured_checks is None: return @@ -245,7 +262,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, dummy_defaults["plugins"][self._identifier] = dict(checks=dict()) dummy_defaults["plugins"][self._identifier]["checks"]["octoprint"] = None self._settings.set(["checks", "octoprint"], None, defaults=dummy_defaults) - self._settings.save() def _clean_settings_check(self, key, data, defaults, delete=None, save=True): if delete is None: