Only migrate server commands when not already set
Also migrate for any config version < 4 (incl. None) and make sure the other migrations may happen on top of that if necessary. Added some comments to explain necessary migrations.
This commit is contained in:
parent
b04da70ce6
commit
f1075f648c
1 changed files with 25 additions and 9 deletions
|
|
@ -178,18 +178,31 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||||
|
|
||||||
def on_settings_migrate(self, target, current=None):
|
def on_settings_migrate(self, target, current=None):
|
||||||
|
|
||||||
if current is None or current == 3:
|
if current is None or current < 4:
|
||||||
self._settings.global_set(["server", "commands", "systemRestartCommand"], self._settings.get(["environment_restart_command"]))
|
# config version 4 and higher moves octoprint_restart_command and
|
||||||
self._settings.global_set(["server", "commands", "serverRestartCommand"], self._settings.get(["octoprint_restart_command"]))
|
# 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(["environment_restart_command"], None)
|
||||||
self._settings.set(["octoprint_restart_command"], None)
|
self._settings.set(["octoprint_restart_command"], None)
|
||||||
self._settings.save()
|
|
||||||
|
|
||||||
elif current == 2:
|
if current is None or current == 2:
|
||||||
# there might be some left over data from the time we still persisted everything to settings,
|
# No config version and config version 2 need the same fix, stripping
|
||||||
# even the stuff that shouldn't be persisted but always provided by the hook - let's
|
# accidentally persisted data off the checks
|
||||||
# clean up
|
|
||||||
|
|
||||||
configured_checks = self._settings.get(["checks"], incl_defaults=False)
|
configured_checks = self._settings.get(["checks"], incl_defaults=False)
|
||||||
if configured_checks is None:
|
if configured_checks is None:
|
||||||
|
|
@ -235,6 +248,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||||
self._settings.set(["checks", key], None, defaults=dummy_defaults)
|
self._settings.set(["checks", key], None, defaults=dummy_defaults)
|
||||||
|
|
||||||
elif current == 1:
|
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)
|
configured_checks = self._settings.get(["checks"], incl_defaults=False)
|
||||||
if configured_checks is None:
|
if configured_checks is None:
|
||||||
return
|
return
|
||||||
|
|
@ -245,7 +262,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||||
dummy_defaults["plugins"][self._identifier] = dict(checks=dict())
|
dummy_defaults["plugins"][self._identifier] = dict(checks=dict())
|
||||||
dummy_defaults["plugins"][self._identifier]["checks"]["octoprint"] = None
|
dummy_defaults["plugins"][self._identifier]["checks"]["octoprint"] = None
|
||||||
self._settings.set(["checks", "octoprint"], None, defaults=dummy_defaults)
|
self._settings.set(["checks", "octoprint"], None, defaults=dummy_defaults)
|
||||||
self._settings.save()
|
|
||||||
|
|
||||||
def _clean_settings_check(self, key, data, defaults, delete=None, save=True):
|
def _clean_settings_check(self, key, data, defaults, delete=None, save=True):
|
||||||
if delete is None:
|
if delete is None:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue