From ef57d1e447a6f7eb940080f1257bd4402535cb36 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Thu, 20 May 2021 20:24:46 +0200 Subject: [PATCH] Some debug and decoding of raw strings --- backive/backive_service | 3 ++- backive/config/config.py | 2 +- backive/core/backup.py | 2 +- backive/core/device.py | 6 +++--- backive/core/scheduler.py | 5 +++++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backive/backive_service b/backive/backive_service index 3304fcd..dcd997f 100755 --- a/backive/backive_service +++ b/backive/backive_service @@ -54,7 +54,7 @@ class Backive: if await self._scheduler.should_run(backup.name): logging.info("Running backup '%s'", backup.name) result = await backup.run() - logging.debug("Result: %s", str(result)) + logging.debug("Result: %s", result.decode()) await self._scheduler.register_run(backup.name) else: logging.info( @@ -73,6 +73,7 @@ class Backive: pass def __del__(self): + self._scheduler.save() del self._events diff --git a/backive/config/config.py b/backive/config/config.py index fdb660f..69a6211 100644 --- a/backive/config/config.py +++ b/backive/config/config.py @@ -57,7 +57,7 @@ class Config: ) with open(config_file, "r") as cfg: - self._config = YAML().load(cfg) + self._config = YAML.safe_load(cfg) logging.debug( "Found config: %s\n%s", config_file, diff --git a/backive/core/backup.py b/backive/core/backup.py index b35f657..034e42f 100644 --- a/backive/core/backup.py +++ b/backive/core/backup.py @@ -42,7 +42,7 @@ class Backup: stderr=asyncio.subprocess.PIPE, ) stdout, stderr = await proc.communicate() - logging.debug("stdout: %s", stdout) + logging.debug("stdout: %s", stdout.decode()) logging.debug("stderr: %s", stderr.decode()) user = self.config.get("user") proc = await asyncio.create_subprocess_shell( diff --git a/backive/core/device.py b/backive/core/device.py index 0e98f84..9abe7de 100644 --- a/backive/core/device.py +++ b/backive/core/device.py @@ -41,8 +41,8 @@ mount -v -o users,noexec {dev_path} {mountpoint}""".format( stderr=asyncio.subprocess.PIPE, ) stdout, stderr = await proc.communicate() - logging.debug("stdout: %s", stdout) - logging.debug("stderr: %s", stderr) + logging.debug("stdout: %s", stdout.decode()) + logging.debug("stderr: %s", stderr.decode()) # TODO: Also add a touch operation in the target mount if the correct # access rights are given! (when backive is run as user) return True # on success, False on failure @@ -58,4 +58,4 @@ sudo umount -v %s stderr=asyncio.subprocess.PIPE, ) stdout, stderr = await proc.communicate() - logging.debug("stdout: %s", stdout) + logging.debug("stdout: %s", stdout.decode()) diff --git a/backive/core/scheduler.py b/backive/core/scheduler.py index cf8fab2..7fffec1 100644 --- a/backive/core/scheduler.py +++ b/backive/core/scheduler.py @@ -30,10 +30,15 @@ class Scheduler(): self.load() def save(self): + logging.debug("Scheduler.save()") with open(self._data_file, "w") as stream: json.dump(self.__data, stream, indent=2) def load(self): + logging.debug("Scheduler.load()") + if not os.path.exists(os.path.dirname(self._data_file)): + os.makedirs(os.path.dirname(self._data_file)) + self.save() with open(self._data_file, "r") as stream: self.__data = json.load(stream)