diff --git a/check.py b/check.py index c96e48f..b78b8eb 100755 --- a/check.py +++ b/check.py @@ -4,6 +4,7 @@ from datetime import datetime import email import email.policy import os +from os.path import exists import sys import stat import subprocess @@ -24,6 +25,7 @@ import late import login import signature from test import MailTest +import tests def signcheck(data): yield MailTest("Those tests are limited to signature checking. THIS IS NOT THE SUBMISSION INTERFACE.", 2) @@ -54,6 +56,8 @@ def gen_checks(gpgmail, submissions_dir, check_content=False, check_submission_h yield ( archive.hash_archive, [submissions_dir, check_submission_hash] ) yield archive.guess_mime yield ( archive.extract, [submissions_dir] ) + if exists(submissions_dir + ".sh"): + yield ( tests.run_script, [submissions_dir + ".sh"] ) def respondissueemail(to, subject, ref, initial_to=None): diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..581a8c0 --- /dev/null +++ b/tests.py @@ -0,0 +1,23 @@ +import subprocess + +from test import MailTest + +def run_script(dest, script): + with subprocess.Popen( + ["/bin/sh", script], + cwd=dest, + env={"LANG": 'C'}, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) as p: + p.wait() + err = p.stdout.read().decode('utf-8', 'replace') + err += p.stderr.read().decode('utf-8', 'replace') + if p.returncode == 0: + yield MailTest("Preliminary tests:", details=err.replace(dest, "/rendu/")) + yield dest + elif p.returncode == 124 or p.returncode == 137: + yield MailTest("Preliminary tests aborted for too long execution:", 1, details=err.replace(dest, "/rendu/")) + else: + yield MailTest("An error occured during preliminary tests:", 2, details=err.replace(dest, "/rendu/")) + yield dest