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