diff --git a/dragon_runner/scripts/build.py b/dragon_runner/scripts/build.py index 23aa9e8..376c2cf 100644 --- a/dragon_runner/scripts/build.py +++ b/dragon_runner/scripts/build.py @@ -4,15 +4,11 @@ import argparse from pathlib import Path -def build(build_path:str, log_path: str, n_threads: str): - """ - Entry point for dragon-runner to run the script. - """ - print("[RUNNING] build script") - +def build(build_path: str, log_path: str, n_threads: str="2"): directories = [d for d in Path(build_path).iterdir() if d.is_dir() and d.name != '.'] + for dir_path in directories: - print(f"-- Building project: {dir_path.name}") + print(f"-- Building project: {dir_path.name}", end='') try: os.chdir(dir_path) @@ -28,26 +24,36 @@ def build(build_path:str, log_path: str, n_threads: str): os.chdir('build') try: - subprocess.run(['cmake', '..'], check=True) - subprocess.run(['make', '-j', n_threads], check=True) + with open(log_path, 'a') as log_file: + log_file.write(f"\n=== Building {dir_path.name} ===\n") + subprocess.run( + ['cmake', '..'], + stdout=log_file, + stderr=subprocess.STDOUT, + check=True + ) + subprocess.run( + ['make', '-j', n_threads], + stdout=log_file, + stderr=subprocess.STDOUT, + check=True + ) + print(" [SUCCESS]") except subprocess.CalledProcessError: + print(f" [FAILED]") with open(log_path, 'a') as f: f.write(f"{dir_path.name}: build failed\n") finally: os.chdir(build_path) - print(f"Build process completed. Check {log_path} for any failed builds.") + print(f"Build process completed. Check {log_path} for build output and errors.") if __name__ == '__main__': - - """ - An entry point to run the script manually - """ parser = argparse.ArgumentParser() parser.add_argument("build_path", type=Path, help="Path to build directory") - parser.add_argument("log_file", type=Path, help="Path to error log file") + parser.add_argument("log_file", type=Path, help="Path to log file") + args = parser.parse_args() + args.log_file.unlink(missing_ok=True) - args.error_file.unlink(missing_ok=True) - build(args.build_path, args.log_file) diff --git a/dragon_runner/scripts/gather.py b/dragon_runner/scripts/gather.py new file mode 100644 index 0000000..537263d --- /dev/null +++ b/dragon_runner/scripts/gather.py @@ -0,0 +1,46 @@ +import shutil +import argparse +from pathlib import Path + +def gather(ccids_file: str, + search_path: str, + project_name: str, + output_dir: str = "submitted-testfiles"): + """ + Gather all the testfiles in student directories. Look for directories in + @search_path that contain @project_name. Inside each project look for + tests/testfiles/TEAM_NAME and copy it out. + """ + search_dir = Path(search_path) + + if not search_dir.is_dir(): + error = "Could not create test directory." + print(error) + return 1 + + directories = [d for d in search_dir.iterdir() if d.is_dir() and project_name in d.name] + ccids = Path(ccids_file).read_text().splitlines() + + output_path = Path(output_dir) + output_path.mkdir(parents=True, exist_ok=True) + + for dir_path in directories: + for ccid in ccids: + if ccid in str(dir_path): + expected_test_dir = dir_path / "tests" / "testfiles" / ccid + if expected_test_dir.is_dir(): + print(f"-- Found properly formatted testfiles for {ccid}") + shutil.copytree(expected_test_dir, output_path / ccid, dirs_exist_ok=True) + else: + print(f"-- Could NOT find testfiles for {ccid}") + +if __name__ == '__main__': + + parser = argparse.ArgumentParser() + parser.add_argument("ccids_file", type=Path, help="File containing CCIDs") + parser.add_argument("search_path", type=Path, help="Path to search for test files") + parser.add_argument("project_name", type=Path, help="Path to search for test files") + args = parser.parse_args() + + gather(args.ccids_file, args.search_path, args.project_name) + diff --git a/dragon_runner/scripts/loader.py b/dragon_runner/scripts/loader.py index 1e45979..d44915f 100644 --- a/dragon_runner/scripts/loader.py +++ b/dragon_runner/scripts/loader.py @@ -1,23 +1,39 @@ + from typing import List -from pathlib import Path from dragon_runner.scripts.build import build -# from dragon_runner.scripts.gather import gather +from dragon_runner.scripts.gather import gather class Loader: + """ + Dragon runner allows grading scripts to be run through its CLI. + """ def __init__(self, script: str, args: List[str]): self.script = script self.args = args - + self.errors = [] + def run(self): - + """ + Select the script to run from the mode argument passed through + dragon-runner CLI. + """ + def unknown_script(): print(f"script: {self.script} did not match any registered script.") - print(f"Running: {self.script} with args {self.args}") - - { - "build": lambda: build(*self.args), - }.get(self.script, lambda: unknown_script)() - + script_dispatch = { + "build": lambda: build(*self.args), + "gather": lambda: gather(*self.args), + "anon-tests": lambda: print("TODO"), + "anon-csv": lambda: print("TODO"), + "preview": lambda: print("TODO") + } + + try: + print(f"Running: {self.script} with args {self.args}") + script_dispatch.get(self.script, lambda: unknown_script)() + + except Exception as e: + print(f"Failed to run script: {e}") diff --git a/dragon_runner/scripts/script_loader.py b/dragon_runner/scripts/script_loader.py deleted file mode 100644 index fd6b662..0000000 --- a/dragon_runner/scripts/script_loader.py +++ /dev/null @@ -1,20 +0,0 @@ -import subprocess -from typing import List - -from dragon_runner.scripts.build_script import build -from dragon_runner.scripts.gather_script import gather - -class Loader: - - def __init__(self, script: str, args: List[str]): - self.script = script - self.args = args - - def run(self): - - print(f"Running: {self.script} with args {self.cmd}") - - # if self.script == "build": - # cmd = ["python3", "build_script.py"] - # build_script - # subprocess.run(self.cmd, shell=True)