lms .cli .courses .quizzes .upload
Upload a quiz.
usage: python3 -m lms.cli.courses.quizzes.upload [-h] [--version]
[--server SERVER]
[--server-type {blackboard,canvas,moodle}]
[--auth-user AUTH_USER]
[--auth-password AUTH_PASSWORD]
[--auth-token AUTH_TOKEN]
[--course COURSE]
[--format {json,table,text}]
[--include-extra-fields]
[--pretty-headers]
[--skip-headers] [--force]
QUIZ_PATH
Upload a quiz.
positional arguments:
QUIZ_PATH Path to a Quiz Composer quiz (JSON file).
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.
--force Delete any existing quiz with a matching name
(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""" 2Upload a quiz. 3""" 4 5import argparse 6import sys 7 8import quizcomp.model.quiz 9 10import lms.backend.instance 11import lms.cli.common 12import lms.cli.parser 13import lms.model.base 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 quiz = quizcomp.model.quiz.Quiz.from_path(args.path) 26 27 quiz_metadata = backend.courses_quizzes_resolve_and_upload(course_query, quiz, force = args.force) 28 29 output = lms.model.base.base_list_to_output_format([quiz_metadata], config.output_format, 30 skip_headers = args.skip_headers, 31 pretty_headers = args.pretty_headers, 32 include_extra_fields = args.include_extra_fields, 33 ) 34 35 print(output) 36 37 return 0 38 39def main() -> int: 40 """ Get a parser, parse the args, and call run. """ 41 return run_cli(_get_parser().parse_args()) 42 43def _get_parser() -> argparse.ArgumentParser: 44 """ Get the parser. """ 45 46 parser = lms.cli.parser.get_parser(__doc__.strip(), 47 include_output_format = True, 48 include_course = True, 49 ) 50 51 parser.add_argument('--force', dest = 'force', 52 action = 'store_true', default = False, 53 help = "Delete any existing quiz with a matching name (default: %(default)s).") 54 55 parser.add_argument('path', metavar = 'QUIZ_PATH', 56 type = str, 57 help = "Path to a Quiz Composer quiz (JSON file).") 58 59 return parser 60 61if (__name__ == '__main__'): 62 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 quiz = quizcomp.model.quiz.Quiz.from_path(args.path) 27 28 quiz_metadata = backend.courses_quizzes_resolve_and_upload(course_query, quiz, force = args.force) 29 30 output = lms.model.base.base_list_to_output_format([quiz_metadata], config.output_format, 31 skip_headers = args.skip_headers, 32 pretty_headers = args.pretty_headers, 33 include_extra_fields = args.include_extra_fields, 34 ) 35 36 print(output) 37 38 return 0
Run the CLI.
def
main() -> int:
40def main() -> int: 41 """ Get a parser, parse the args, and call run. """ 42 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.