Fix strings, pretty-print subprocess output

This commit is contained in:
Kumi 2022-01-13 17:19:32 +01:00
parent 0c97d3a748
commit eeb4580f99

View file

@ -14,9 +14,12 @@ logger = Logger()
def trigger_export(courseid, categoryid): def trigger_export(courseid, categoryid):
global MOODLE_PATH, OUTPUT_PATH global MOODLE_PATH, OUTPUT_PATH
output_name = f"course_{courseid}_{categoryid}_{datetime.now().timestamp()}" output_name = f"course_{courseid}_{categoryid}_{int(datetime.now().timestamp())}.mbz"
subprocess.run([MOOSH_PATH, "-p", MOODLE_PATH, "course-backup", result = subprocess.run([MOOSH_PATH, "-p", MOODLE_PATH, "course-backup",
"-p", OUTPUT_PATH, "-f", output_name, "--template", courseid]) "-p", OUTPUT_PATH, "-f", output_name, "--template", courseid],
capture_output=True)
for line in str(result.stdout).splitlines():
logger.debug(line)
return output_name return output_name
@ -48,7 +51,7 @@ def main():
size = Path(OUTPUT_PATH / output_name).stat().st_size size = Path(OUTPUT_PATH / output_name).stat().st_size
f.unlink() f.unlink()
logger.debug( logger.debug(
f"Created file {output_name} ({size} bytes) in {dur.seconds}") f"Created file {output_name} ({size} bytes) in {dur.seconds} seconds")
except Exception as e: except Exception as e:
logger.error( logger.error(
f"Export of course {f.name.split('.')[0].split('-')[0]} failed: {e}") f"Export of course {f.name.split('.')[0].split('-')[0]} failed: {e}")