autograder.cli.courses.assignments.images.fetch

Fetch an assignment's Docker image.

usage: python3 -m autograder.cli.courses.assignments.images.fetch
       [-h] [--version] [--server SERVER] [--user USER] [--pass PASS]
       [--course COURSE] [--assignment ASSIGNMENT] [--out-dir OUT_DIR]
       [--testing-mode]

Fetch an assignment's Docker image.

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.
    --course COURSE     The ID of the course to make this request to.
    --assignment ASSIGNMENT
                        The ID of the assignment to make this request to.
    --out-dir OUT_DIR   A directory to write output in. (default: .)

testing options:
    --testing-mode      Run as if a test is being run (default: False).
 1"""
 2Fetch an assignment's Docker image.
 3"""
 4
 5import argparse
 6import os
 7import sys
 8
 9import edq.util.dirent
10import edq.util.encoding
11import edq.util.json
12
13import autograder.api.courses.assignments.images.fetch
14import autograder.cli.parser
15
16def run_cli(args: argparse.Namespace) -> int:
17    """ Run the CLI. """
18
19    config = args._config_info.application_config
20
21    result = autograder.api.courses.assignments.images.fetch.send(config, exit_on_error = True)
22
23    print(edq.util.json.dumps(result['image-info'], indent = 4))
24    print('---')
25
26    if (not result['image-info']['built']):
27        print("Image has not been built, nothing to write to disk.")
28        return 1
29
30    edq.util.dirent.mkdir(args.out_dir)
31    out_path = os.path.abspath(os.path.join(args.out_dir, result['image-info']['name'] + '.tar.gz'))
32
33    gzip_bytes = edq.util.encoding.from_base64(result['bytes'])
34    edq.util.dirent.write_file_bytes(out_path, gzip_bytes)
35    print(f"Wrote image '{result['image-info']['name']}' to '{out_path}'.")
36
37    return 0
38
39def main() -> int:
40    """ Get a parser, parse the args, and call run. """
41
42    return run_cli(_get_parser().parse_args())
43
44def _get_parser() -> argparse.ArgumentParser:
45    """ Get a parser for this operation. """
46
47    parser = autograder.cli.parser.get_parser(
48        __doc__.strip(),
49        autograder.api.courses.assignments.images.fetch.API_PARAMS)
50
51    return parser
52
53if (__name__ == '__main__'):
54    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    result = autograder.api.courses.assignments.images.fetch.send(config, exit_on_error = True)
23
24    print(edq.util.json.dumps(result['image-info'], indent = 4))
25    print('---')
26
27    if (not result['image-info']['built']):
28        print("Image has not been built, nothing to write to disk.")
29        return 1
30
31    edq.util.dirent.mkdir(args.out_dir)
32    out_path = os.path.abspath(os.path.join(args.out_dir, result['image-info']['name'] + '.tar.gz'))
33
34    gzip_bytes = edq.util.encoding.from_base64(result['bytes'])
35    edq.util.dirent.write_file_bytes(out_path, gzip_bytes)
36    print(f"Wrote image '{result['image-info']['name']}' to '{out_path}'.")
37
38    return 0

Run the CLI.

def main() -> int:
40def main() -> int:
41    """ Get a parser, parse the args, and call run. """
42
43    return run_cli(_get_parser().parse_args())

Get a parser, parse the args, and call run.