autograder .cli .grading .pre-docker
Take any necessary steps before performing a standard docker-based grading. This script is used as part of the standard docker grading procedure for Python.
usage: python3 -m autograder.cli.grading.pre-docker [-h] [-c CONFIG]
[-bd BASEDIR]
[-id INPUTDIR]
[-od OUTPUTDIR]
[-wd WORKDIR]
Take any necessary steps before performing a standard docker-based grading.
This script is used as part of the standard docker grading procedure for
Python.
options:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
The path to a JSON file describing grading
configurations (default: /autograder/config.json).
-bd BASEDIR, --basedir BASEDIR
The path to the base dir (where file operations are
run) (default: /autograder).
-id INPUTDIR, --inputdir INPUTDIR
The path to the grading input directory (default:
/autograder/input).
-od OUTPUTDIR, --outputdir OUTPUTDIR
The path to the grading output directory (default:
/autograder/output).
-wd WORKDIR, --workdir WORKDIR
The path to the grading work directory (default:
/autograder/work).
1# pylint: disable=invalid-name 2 3""" 4Take any necessary steps before performing a standard docker-based grading. 5This script is used as part of the standard docker grading procedure for Python. 6""" 7 8import argparse 9import os 10import sys 11 12import edq.util.dirent 13import edq.util.json 14 15import autograder.fileop 16import autograder.submission 17 18DEFAULT_BASE_DIR: str = os.path.join('/', 'autograder') 19 20DEFAULT_CONFIG_PATH: str = os.path.join(DEFAULT_BASE_DIR, 'config.json') 21 22DEFAULT_INPUT_DIR: str = os.path.join(DEFAULT_BASE_DIR, 'input') 23DEFAULT_OUTPUT_DIR: str = os.path.join(DEFAULT_BASE_DIR, 'output') 24DEFAULT_WORK_DIR: str = os.path.join(DEFAULT_BASE_DIR, 'work') 25 26def run_cli(args: argparse.Namespace) -> int: 27 """ Run the CLI. """ 28 29 if (not os.path.exists(args.config)): 30 # No config, there's nothing to do. 31 return 0 32 33 config = edq.util.json.load_path(args.config) 34 35 edq.util.dirent.mkdir(args.basedir) 36 edq.util.dirent.mkdir(args.inputdir) 37 edq.util.dirent.mkdir(args.outputdir) 38 edq.util.dirent.mkdir(args.workdir) 39 40 # Do post-submission file operations. 41 # There are no pre-sub file ops and Docker has already copied over the submission files 42 # into the input directory. 43 operations = config.get(autograder.submission.CONFIG_KEY_POST_SUB_OPS, []) 44 autograder.fileop.exec_file_operations(operations, args.basedir) 45 46 return 0 47 48def main() -> int: 49 """ Get a parser, parse the args, and call run. """ 50 51 args, _ = _get_parser().parse_known_args() 52 return run_cli(args) 53 54def _get_parser() -> argparse.ArgumentParser: 55 """ Get a parser for this operation. """ 56 57 parser = argparse.ArgumentParser(description = __doc__.strip()) 58 59 parser.add_argument('-c', '--config', 60 action = 'store', type = str, default = DEFAULT_CONFIG_PATH, 61 help = 'The path to a JSON file describing grading configurations (default: %(default)s).') 62 63 parser.add_argument('-bd', '--basedir', 64 action = 'store', type = str, default = DEFAULT_BASE_DIR, 65 help = 'The path to the base dir (where file operations are run) (default: %(default)s).') 66 67 parser.add_argument('-id', '--inputdir', 68 action = 'store', type = str, default = DEFAULT_INPUT_DIR, 69 help = 'The path to the grading input directory (default: %(default)s).') 70 71 parser.add_argument('-od', '--outputdir', 72 action = 'store', type = str, default = DEFAULT_OUTPUT_DIR, 73 help = 'The path to the grading output directory (default: %(default)s).') 74 75 parser.add_argument('-wd', '--workdir', 76 action = 'store', type = str, default = DEFAULT_WORK_DIR, 77 help = 'The path to the grading work directory (default: %(default)s).') 78 79 return parser 80 81if (__name__ == '__main__'): 82 sys.exit(main())
DEFAULT_BASE_DIR: str =
'/autograder'
DEFAULT_CONFIG_PATH: str =
'/autograder/config.json'
DEFAULT_INPUT_DIR: str =
'/autograder/input'
DEFAULT_OUTPUT_DIR: str =
'/autograder/output'
DEFAULT_WORK_DIR: str =
'/autograder/work'
def
run_cli(args: argparse.Namespace) -> int:
27def run_cli(args: argparse.Namespace) -> int: 28 """ Run the CLI. """ 29 30 if (not os.path.exists(args.config)): 31 # No config, there's nothing to do. 32 return 0 33 34 config = edq.util.json.load_path(args.config) 35 36 edq.util.dirent.mkdir(args.basedir) 37 edq.util.dirent.mkdir(args.inputdir) 38 edq.util.dirent.mkdir(args.outputdir) 39 edq.util.dirent.mkdir(args.workdir) 40 41 # Do post-submission file operations. 42 # There are no pre-sub file ops and Docker has already copied over the submission files 43 # into the input directory. 44 operations = config.get(autograder.submission.CONFIG_KEY_POST_SUB_OPS, []) 45 autograder.fileop.exec_file_operations(operations, args.basedir) 46 47 return 0
Run the CLI.
def
main() -> int:
49def main() -> int: 50 """ Get a parser, parse the args, and call run. """ 51 52 args, _ = _get_parser().parse_known_args() 53 return run_cli(args)
Get a parser, parse the args, and call run.