Some debug and decoding of raw strings

This commit is contained in:
Marcel Otte 2021-05-20 20:24:46 +02:00
parent fed1984e81
commit ef57d1e447
5 changed files with 12 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -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())

View File

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