autograder .cli .courses .upsert .zip
Upsert a course using a zip file or directory.
usage: python3 -m autograder.cli.courses.upsert.zip [-h] [--version]
[--server SERVER]
[--user USER]
[--pass PASS] [--dry-run]
[--skip-emails]
[--skip-source-sync]
[--skip-lms-sync]
[--skip-build-images]
[--skip-template-files]
[--testing-mode]
PATH
Upsert a course using a zip file or directory.
options:
-h, --help show this help message and exit
--version show program's version number and exit
command-specific options:
--server SERVER The URL of the autograder server to communicate with.
--user USER The email of the user making this request.
--pass PASS The password of the user making this request.
--dry-run Do not commit/finalize the operation, just do all the
steps and state what the result would look like.
--skip-emails Skip sending any emails.
--skip-source-sync Skip syncing (updating with) the course source.
--skip-lms-sync Skip syncing with the LMS.
--skip-build-images
Skip building assignment Docker images.
--skip-template-files
Skip fetching assignment template files.
PATH The path to your course material. Either a zip file
(with .zip extension) or directory (that will get
zipped).
testing options:
--testing-mode Run as if a test is being run (default: False).
1""" 2Upsert a course using a zip file or directory. 3""" 4 5import argparse 6import os 7import sys 8 9import edq.util.json 10 11import autograder.api.courses.upsert.zip 12import autograder.cli.parser 13import autograder.error 14import autograder.util.zip 15 16def run_cli(args: argparse.Namespace) -> int: 17 """ Run the CLI. """ 18 19 config = args._config_info.application_config 20 21 try: 22 zip_path = _prep_zip(args.path) 23 except autograder.error.AutograderError as ex: 24 print(str(ex)) 25 return 10 26 27 result = autograder.api.courses.upsert.zip.send(config, post_paths = [zip_path], exit_on_error = True) 28 print(edq.util.json.dumps(result, indent = 4)) 29 30 return 0 31 32def _prep_zip(path: str) -> str: 33 """ 34 Ensure that a zip file is ready for upload. 35 If the path is already a zip, just return the existing path. 36 If the path is a dir, zip it and return the new path. 37 """ 38 39 if (not os.path.exists(path)): 40 raise autograder.error.AutograderError(f"Path does not exist: '{path}'.") 41 42 if (os.path.isfile(path)): 43 extension = os.path.splitext(path)[1] 44 if (extension != '.zip'): 45 raise autograder.error.AutograderError(f"Expecting '.zip' extension, found '{extension}': '{path}'.") 46 47 return path 48 49 return autograder.util.zip.archive_dir(path) 50 51def main() -> int: 52 """ Get a parser, parse the args, and call run. """ 53 54 return run_cli(_get_parser().parse_args()) 55 56def _get_parser() -> argparse.ArgumentParser: 57 """ Get a parser for this operation. """ 58 59 parser = autograder.cli.parser.get_parser( 60 __doc__.strip(), 61 autograder.api.courses.upsert.zip.API_PARAMS) 62 63 return parser 64 65if (__name__ == '__main__'): 66 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
17def run_cli(args: argparse.Namespace) -> int: 18 """ Run the CLI. """ 19 20 config = args._config_info.application_config 21 22 try: 23 zip_path = _prep_zip(args.path) 24 except autograder.error.AutograderError as ex: 25 print(str(ex)) 26 return 10 27 28 result = autograder.api.courses.upsert.zip.send(config, post_paths = [zip_path], exit_on_error = True) 29 print(edq.util.json.dumps(result, indent = 4)) 30 31 return 0
Run the CLI.
def
main() -> int:
52def main() -> int: 53 """ Get a parser, parse the args, and call run. """ 54 55 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.