autograder.cli.courses.assignments.submissions.fetch.user.attempts

Get all submission attempts made by a user along with all grading information.

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

Get all submission attempts made by a user along with all grading information.

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.
    --target-email TARGET_EMAIL
                        The email of the user that is the target of this
                        request (defaults to you). (default: None)
    --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"""
 2Get all submission attempts made by a user along with all grading information.
 3"""
 4
 5import argparse
 6import os
 7import sys
 8
 9import autograder.api.courses.assignments.submissions.fetch.user.attempts
10import autograder.cli.common
11import autograder.cli.parser
12import autograder.util.grading
13
14def run_cli(args: argparse.Namespace) -> int:
15    """ Run the CLI. """
16
17    config = args._config_info.application_config
18
19    found_user, grading_results = autograder.api.courses.assignments.submissions.fetch.user.attempts.send(config, exit_on_error = True)
20
21    if (not found_user):
22        autograder.cli.common.print_no_match('user', config.target_email)
23        return 1
24
25    if (grading_results is None):
26        raise ValueError("Existing submissions were not provided by API.")
27
28    if (len(grading_results) == 0):
29        print("No attempts found.")
30        return 0
31
32    assignment = grading_results[0]['info']['assignment-id']
33    user = grading_results[0]['info']['user']
34    out_dir = os.path.join(config.out_dir, assignment, user)
35
36    for grading_result in grading_results:
37        autograder.util.grading.output_grading_result(grading_result, base_dir = out_dir, short_id = True)
38
39    print(f"Wrote {len(grading_results)} attempts to '{out_dir}'.")
40
41    return 0
42
43def main() -> int:
44    """ Get a parser, parse the args, and call run. """
45
46    return run_cli(_get_parser().parse_args())
47
48def _get_parser() -> argparse.ArgumentParser:
49    """ Get a parser for this operation. """
50
51    parser = autograder.cli.parser.get_parser(
52        __doc__.strip(),
53        autograder.api.courses.assignments.submissions.fetch.user.attempts.API_PARAMS)
54
55    return parser
56
57if (__name__ == '__main__'):
58    sys.exit(main())
def run_cli(args: argparse.Namespace) -> int:
15def run_cli(args: argparse.Namespace) -> int:
16    """ Run the CLI. """
17
18    config = args._config_info.application_config
19
20    found_user, grading_results = autograder.api.courses.assignments.submissions.fetch.user.attempts.send(config, exit_on_error = True)
21
22    if (not found_user):
23        autograder.cli.common.print_no_match('user', config.target_email)
24        return 1
25
26    if (grading_results is None):
27        raise ValueError("Existing submissions were not provided by API.")
28
29    if (len(grading_results) == 0):
30        print("No attempts found.")
31        return 0
32
33    assignment = grading_results[0]['info']['assignment-id']
34    user = grading_results[0]['info']['user']
35    out_dir = os.path.join(config.out_dir, assignment, user)
36
37    for grading_result in grading_results:
38        autograder.util.grading.output_grading_result(grading_result, base_dir = out_dir, short_id = True)
39
40    print(f"Wrote {len(grading_results)} attempts to '{out_dir}'.")
41
42    return 0

Run the CLI.

def main() -> int:
44def main() -> int:
45    """ Get a parser, parse the args, and call run. """
46
47    return run_cli(_get_parser().parse_args())

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