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):
global MOODLE_PATH, OUTPUT_PATH
output_name = f"course_{courseid}_{categoryid}_{datetime.now().timestamp()}"
subprocess.run([MOOSH_PATH, "-p", MOODLE_PATH, "course-backup",
"-p", OUTPUT_PATH, "-f", output_name, "--template", courseid])
output_name = f"course_{courseid}_{categoryid}_{int(datetime.now().timestamp())}.mbz"
result = subprocess.run([MOOSH_PATH, "-p", MOODLE_PATH, "course-backup",
"-p", OUTPUT_PATH, "-f", output_name, "--template", courseid],
capture_output=True)
for line in str(result.stdout).splitlines():
logger.debug(line)
return output_name
@ -48,7 +51,7 @@ def main():
size = Path(OUTPUT_PATH / output_name).stat().st_size
f.unlink()
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:
logger.error(
f"Export of course {f.name.split('.')[0].split('-')[0]} failed: {e}")
@ -57,4 +60,4 @@ def main():
if __name__ == "__main__":
main()
main()