From eeb4580f9950fd939629cd0839ecd4a38aadf9b1 Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 13 Jan 2022 17:19:32 +0100 Subject: [PATCH] Fix strings, pretty-print subprocess output --- worker.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/worker.py b/worker.py index ca47c33..341ddc4 100755 --- a/worker.py +++ b/worker.py @@ -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() \ No newline at end of file + main()