quizcomp .cli .qti .create
Parse a quiz and upload the quiz to Canvas.
usage: python3 -m quizcomp.cli.qti.create [-h] [--version] [--canvas]
[--out OUT]
PATH
Parse a quiz and upload the quiz to Canvas.
positional arguments:
PATH The path to a quiz JSON file.
options:
-h, --help show this help message and exit
--version show program's version number and exit
--canvas Create the QTI with Canvas-specific tweaks (default: False).
--out OUT The path specifying where to put the output. If the path
points to an existing dir, the result will be written to
`/.qti.zip`. If the path point to an existing file,
the file will be overwritten with the result. If the path
points to a non-existing dir (denoted with a trailing path
separator (e.g., slash)), the dir will be created and the
output will be written as it is to an existing dir. Finally if
the path does not exist, the result will be written to the
full path (creating any parent directories along the way).
(default: .).
1""" 2Parse a quiz and upload the quiz to Canvas. 3""" 4 5import argparse 6import os 7import sys 8 9import quizcomp.cli.parser 10import quizcomp.converter.qti 11import quizcomp.model.quiz 12 13def run_cli(args: argparse.Namespace) -> int: 14 """ Run the CLI. """ 15 16 if (not os.path.exists(args.path)): 17 raise ValueError(f"Provided path '{args.path}' does not exist.") 18 19 if (not os.path.isfile(args.path)): 20 raise ValueError(f"Provided path '{args.path}' is not a file.") 21 22 quiz = quizcomp.model.quiz.Quiz.from_path(args.path) 23 24 out_path = quizcomp.cli.parser.resolve_out_arg(args.out, f'{quiz.get_name()}.qti.zip') # pylint: disable=no-member 25 26 converter = quizcomp.converter.qti.QTITemplateConverter(out_path = out_path, canvas = args.canvas) 27 converter.convert_quiz(quiz) 28 29 return 0 30 31def main() -> int: 32 """ Get a parser, parse the args, and call run. """ 33 34 return run_cli(_get_parser().parse_args()) 35 36def _get_parser() -> argparse.ArgumentParser: 37 """ Get the parser. """ 38 39 parser = quizcomp.cli.parser.get_parser(__doc__.strip()) 40 41 parser.add_argument('--canvas', dest = 'canvas', 42 action = 'store_true', default = False, 43 help = 'Create the QTI with Canvas-specific tweaks (default: %(default)s).') 44 45 quizcomp.cli.parser.add_out_arg(parser, '<name>.qti.zip') 46 47 parser.add_argument('path', metavar = 'PATH', 48 type = str, 49 help = 'The path to a quiz JSON file.') 50 51 return parser 52 53if (__name__ == '__main__'): 54 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
14def run_cli(args: argparse.Namespace) -> int: 15 """ Run the CLI. """ 16 17 if (not os.path.exists(args.path)): 18 raise ValueError(f"Provided path '{args.path}' does not exist.") 19 20 if (not os.path.isfile(args.path)): 21 raise ValueError(f"Provided path '{args.path}' is not a file.") 22 23 quiz = quizcomp.model.quiz.Quiz.from_path(args.path) 24 25 out_path = quizcomp.cli.parser.resolve_out_arg(args.out, f'{quiz.get_name()}.qti.zip') # pylint: disable=no-member 26 27 converter = quizcomp.converter.qti.QTITemplateConverter(out_path = out_path, canvas = args.canvas) 28 converter.convert_quiz(quiz) 29 30 return 0
Run the CLI.
def
main() -> int:
32def main() -> int: 33 """ Get a parser, parse the args, and call run. """ 34 35 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.