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:
Gina Häußge 2015-07-21 17:55:08 +02:00
parent b04da70ce6
commit f1075f648c

View file

@ -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: