lms.cli.courses.quizzes.remove

Remove a quiz.

usage: python3 -m lms.cli.courses.quizzes.remove [-h] [--version]
                                                 [--server SERVER]
                                                 [--server-type {blackboard,canvas,moodle}]
                                                 [--auth-user AUTH_USER]
                                                 [--auth-password AUTH_PASSWORD]
                                                 [--auth-token AUTH_TOKEN]
                                                 [--course COURSE]
                                                 [QUIZ_QUERY ...]

Remove a quiz.

positional arguments:
    QUIZ_QUERY          A query for a quiz 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.

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"""
 2Remove a quiz.
 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    queries = backend.parse_assignment_queries(args.quizzes)
24
25    removed_quizzes = backend.courses_quizzes_resolve_and_remove(course_query, queries)
26
27    if (len(removed_quizzes) == 0):
28        print('Found no quizzes to remove.')
29        return 0
30
31    for removed_quiz in removed_quizzes:
32        print(f"Removed quiz: '{removed_quiz.to_query()}'.")
33
34    return 0
35
36def main() -> int:
37    """ Get a parser, parse the args, and call run. """
38    return run_cli(_get_parser().parse_args())
39
40def _get_parser() -> argparse.ArgumentParser:
41    """ Get the parser. """
42
43    parser = lms.cli.parser.get_parser(__doc__.strip(),
44            include_course = True,
45    )
46
47    parser.add_argument('quizzes', metavar = 'QUIZ_QUERY',
48        type = str, nargs = '*',
49        help = 'A query for a quiz to get.')
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    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    queries = backend.parse_assignment_queries(args.quizzes)
25
26    removed_quizzes = backend.courses_quizzes_resolve_and_remove(course_query, queries)
27
28    if (len(removed_quizzes) == 0):
29        print('Found no quizzes to remove.')
30        return 0
31
32    for removed_quiz in removed_quizzes:
33        print(f"Removed quiz: '{removed_quiz.to_query()}'.")
34
35    return 0

Run the CLI.

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

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