lms.cli.courses.assignments.scores.get

Get specific scores for an assignment.

usage: python3 -m lms.cli.courses.assignments.scores.get [-h] [--version]
                                                         [--server SERVER]
                                                         [--server-type {blackboard,canvas,moodle}]
                                                         [--auth-user AUTH_USER]
                                                         [--auth-password AUTH_PASSWORD]
                                                         [--auth-token AUTH_TOKEN]
                                                         [--course COURSE]
                                                         [--assignment ASSIGNMENT]
                                                         [--format {json,table,text}]
                                                         [--include-extra-fields]
                                                         [--pretty-headers]
                                                         [--skip-headers]
                                                         [--strict]
                                                         [USER_QUERY ...]

Get specific scores for an assignment.

positional arguments:
    USER_QUERY          A query for an users to get.

options:
    -h, --help          show this help message and exit
    --version           show program's version number and exit
    --course COURSE     The course to target for this operation.
    --assignment ASSIGNMENT
                        The assignment to target for this operation.
    --strict            Enable strict mode, which is stricter about what
                        counts as an error (default: False).

server options:
    --server SERVER     The address of the LMS server to connect to.
    --server-type {blackboard,canvas,moodle}
                        The type of LMS being connected to (this can normally
                        be guessed from the server address).

authentication options:
    --auth-user AUTH_USER
                        The user to authenticate with.
    --auth-password AUTH_PASSWORD
                        The password to authenticate with.
    --auth-token AUTH_TOKEN
                        The token to authenticate with.

output formatting options:
    --format {json,table,text}
                        The format to display the output as (default: text).
    --include-extra-fields
                        Include non-common (usually LMS-specific) fields in
                        results (default: False).
    --pretty-headers    When displaying headers, try to make them look
                        "pretty" (default: False).
    --skip-headers      Skip headers when outputting results, will not apply
                        to all formats (default: False).
 1"""
 2Get specific scores for an assignment.
 3"""
 4
 5import argparse
 6import sys
 7
 8import lms.backend.instance
 9import lms.cli.common
10import lms.cli.parser
11import lms.model.base
12
13def run_cli(args: argparse.Namespace) -> int:
14    """ Run the CLI. """
15
16    config = args._config_info.application_config
17    backend = lms.backend.instance.get_backend(config)
18
19    course_query = lms.cli.common.check_required_course(backend, config)
20    if (course_query is None):
21        return 1
22
23    assignment_query = lms.cli.common.check_required_assignment(backend, config)
24    if (assignment_query is None):
25        return 2
26
27    user_queries = backend.parse_user_queries(args.users)
28
29    scores = backend.courses_assignments_scores_get(course_query, assignment_query, user_queries)
30
31    output = lms.model.base.base_list_to_output_format(scores, config.output_format,
32            skip_headers = args.skip_headers,
33            pretty_headers = args.pretty_headers,
34            include_extra_fields = args.include_extra_fields,
35    )
36
37    print(output)
38
39    return lms.cli.common.strict_check(config, (len(scores) != len(user_queries)),
40        f"Expected to find {len(user_queries)} scores, but found {len(scores)}.", 3)
41
42def main() -> int:
43    """ Get a parser, parse the args, and call run. """
44    return run_cli(_get_parser().parse_args())
45
46def _get_parser() -> argparse.ArgumentParser:
47    """ Get the parser. """
48
49    parser = lms.cli.parser.get_parser(__doc__.strip(),
50            include_output_format = True,
51            include_course = True,
52            include_assignment = True,
53            include_strict = True,
54    )
55
56    parser.add_argument('users', metavar = 'USER_QUERY',
57        type = str, nargs = '*',
58        help = 'A query for an users to get.')
59
60    return parser
61
62if (__name__ == '__main__'):
63    sys.exit(main())
def run_cli(args: argparse.Namespace) -> int:
14def run_cli(args: argparse.Namespace) -> int:
15    """ Run the CLI. """
16
17    config = args._config_info.application_config
18    backend = lms.backend.instance.get_backend(config)
19
20    course_query = lms.cli.common.check_required_course(backend, config)
21    if (course_query is None):
22        return 1
23
24    assignment_query = lms.cli.common.check_required_assignment(backend, config)
25    if (assignment_query is None):
26        return 2
27
28    user_queries = backend.parse_user_queries(args.users)
29
30    scores = backend.courses_assignments_scores_get(course_query, assignment_query, user_queries)
31
32    output = lms.model.base.base_list_to_output_format(scores, config.output_format,
33            skip_headers = args.skip_headers,
34            pretty_headers = args.pretty_headers,
35            include_extra_fields = args.include_extra_fields,
36    )
37
38    print(output)
39
40    return lms.cli.common.strict_check(config, (len(scores) != len(user_queries)),
41        f"Expected to find {len(user_queries)} scores, but found {len(scores)}.", 3)

Run the CLI.

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

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