From 7709150a2b8801698fba00dc472a1ed0c6e367a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 18 Nov 2016 13:39:31 +0100 Subject: [PATCH] Make backup of config before system command migration --- src/octoprint/settings.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 427d92c4..3da346d1 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -1100,8 +1100,27 @@ class Settings(object): self._logger.info("Deleted {} action from configured system commands, superseeded by server.commands.{}".format(action, migrate_to)) changed = True + + if changed: + # let's make a backup of our current config, in case someone wants to roll back to an + # earlier version and needs to recover the former system commands for that + backup_path = self.backup("system_command_migration") + self._logger.info("Made a copy of the current config at {} to allow recovery of manual system command configuration".format(backup_path)) + return changed + def backup(self, suffix, path=None): + import shutil + + if path is None: + path = os.path.dirname(self._configfile) + basename = os.path.basename(self._configfile) + name, ext = os.path.splitext(basename) + + backup = os.path.join(path, "{}.{}{}".format(name, suffix, ext)) + shutil.copy(self._configfile, backup) + return backup + def save(self, force=False): if not self._dirty and not force: return False