lms.cli.courses.assignments.scores.upload-score

Upload a single score (and optional comment) for an assignment.

usage: python3 -m lms.cli.courses.assignments.scores.upload-score
       [-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] [--user USER] [--strict]
       SCORE [COMMENT]

Upload a single score (and optional comment) for an assignment.

positional arguments:
    SCORE               Score to upload.
    COMMENT             Optional comment.

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.
    --user USER         The user 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.
 1# pylint: disable=invalid-name
 2
 3"""
 4Upload a single score (and optional comment) for an assignment.
 5"""
 6
 7import argparse
 8import sys
 9
10import lms.backend.instance
11import lms.cli.common
12import lms.cli.parser
13import lms.model.scores
14
15def run_cli(args: argparse.Namespace) -> int:
16    """ Run the CLI. """
17
18    config = args._config_info.application_config
19    backend = lms.backend.instance.get_backend(config)
20
21    course_query = lms.cli.common.check_required_course(backend, config)
22    if (course_query is None):
23        return 1
24
25    assignment_query = lms.cli.common.check_required_assignment(backend, config)
26    if (assignment_query is None):
27        return 2
28
29    user_query = lms.cli.common.check_required_user(backend, config)
30    if (user_query is None):
31        return 3
32
33    scores = {
34        user_query: lms.model.scores.ScoreFragment(score = args.score, comment = args.comment),
35    }
36
37    count = backend.courses_assignments_scores_resolve_and_upload(course_query, assignment_query, scores)
38
39    print(f"Uploaded {count} Scores")
40
41    return lms.cli.common.strict_check(config, (count != len(scores)),
42        f"Expected to upload {len(scores)} scores, but uploaded {count}.", 4)
43
44def main() -> int:
45    """ Get a parser, parse the args, and call run. """
46    return run_cli(_get_parser().parse_args())
47
48def _get_parser() -> argparse.ArgumentParser:
49    """ Get the parser. """
50
51    parser = lms.cli.parser.get_parser(__doc__.strip(),
52            include_course = True,
53            include_assignment = True,
54            include_user = True,
55            include_strict = True,
56    )
57
58    parser.add_argument('score', metavar = 'SCORE',
59        action = 'store', type = float,
60        help = 'Score to upload.')
61
62    parser.add_argument('comment', metavar = 'COMMENT',
63        action = 'store', type = str, nargs = '?', default = None,
64        help = 'Optional comment.')
65
66    return parser
67
68if (__name__ == '__main__'):
69    sys.exit(main())
def run_cli(args: argparse.Namespace) -> int:
16def run_cli(args: argparse.Namespace) -> int:
17    """ Run the CLI. """
18
19    config = args._config_info.application_config
20    backend = lms.backend.instance.get_backend(config)
21
22    course_query = lms.cli.common.check_required_course(backend, config)
23    if (course_query is None):
24        return 1
25
26    assignment_query = lms.cli.common.check_required_assignment(backend, config)
27    if (assignment_query is None):
28        return 2
29
30    user_query = lms.cli.common.check_required_user(backend, config)
31    if (user_query is None):
32        return 3
33
34    scores = {
35        user_query: lms.model.scores.ScoreFragment(score = args.score, comment = args.comment),
36    }
37
38    count = backend.courses_assignments_scores_resolve_and_upload(course_query, assignment_query, scores)
39
40    print(f"Uploaded {count} Scores")
41
42    return lms.cli.common.strict_check(config, (count != len(scores)),
43        f"Expected to upload {len(scores)} scores, but uploaded {count}.", 4)

Run the CLI.

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

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