diff --git a/src/octoprint/plugins/softwareupdate/util.py b/src/octoprint/plugins/softwareupdate/util.py index 0adf55ba0..69fbc566c 100644 --- a/src/octoprint/plugins/softwareupdate/util.py +++ b/src/octoprint/plugins/softwareupdate/util.py @@ -8,6 +8,8 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms from .exceptions import ScriptError +import logging + def execute(command, cwd=None, evaluate_returncode=True, **kwargs): do_async = kwargs.get("do_async", kwargs.get("async", False)) @@ -16,8 +18,9 @@ def execute(command, cwd=None, evaluate_returncode=True, **kwargs): p = None try: - p = sarge.run(command, cwd=cwd, stdout=sarge.Capture(), stderr=sarge.Capture(), async_=do_async) + p = sarge.run(command, cwd=cwd, stdout=sarge.Capture(), stderr=sarge.Capture(), async=do_async) except: + logging.getLogger(__name__).exception("Error while executing command: {}".format(command)) returncode = p.returncode if p is not None else None stdout = p.stdout.text if p is not None and p.stdout is not None else "" stderr = p.stderr.text if p is not None and p.stderr is not None else "" diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 9c7926bc9..fd7e3ecdc 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -711,6 +711,9 @@ class Server(object): self._settings.setBoolean(["server", "startOnceInSafeMode"], False) self._settings.save() + # make a backup of the current config + self._settings.backup(ext="backup") + # now this is somewhat ugly, but the issue is the following: startup plugins might want to do things for # which they need the server to be already alive (e.g. for being able to resolve urls, such as favicons # or service xmls or the like). While they are working though the ioloop would block. Therefore we'll diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index df8f56e9a..aa1f6339a 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -1309,15 +1309,25 @@ class Settings(object): return True return False - def backup(self, suffix, path=None): + def backup(self, suffix=None, path=None, ext=None, hidden=False): 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)) + basename = os.path.basename(self._configfile) + name, default_ext = os.path.splitext(basename) + + if ext is None: + ext = default_ext + + if suffix is None and ext == default_ext: + raise ValueError("Need a suffix or a different extension") + + if suffix is None: + suffix = "" + + backup = os.path.join(path, "{}{}.{}{}".format("." if hidden else "", name, suffix, ext)) shutil.copy(self._configfile, backup) return backup