lms .cli .courses .groupsets .memberships .add
Add users to a group set.
usage: python3 -m lms.cli.courses.groupsets.memberships.add
[-h] [--version] [--server SERVER]
[--server-type {blackboard,canvas,moodle}] [--auth-user AUTH_USER]
[--auth-password AUTH_PASSWORD] [--auth-token AUTH_TOKEN]
[--course COURSE] [--groupset GROUPSET] [--group GROUP]
[--format {json,table,text}] [--include-extra-fields]
[--pretty-headers] [--skip-headers] [--skip-rows SKIP_ROWS] [--strict]
PATH
Add users to a group set.
positional arguments:
PATH Path to a TSV file where each row has 2 columns: group
query and user query.
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.
--groupset GROUPSET The group set to target for this operation.
--group GROUP The group to target for this operation.
--skip-rows SKIP_ROWS
The number of header rows to skip (default: 0).
--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.
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""" 2Add users to a group set. 3""" 4 5import argparse 6import sys 7 8import lms.backend.instance 9import lms.cli.common 10import lms.cli.courses.groupsets.memberships.common 11import lms.cli.parser 12import lms.model.base 13 14def run_cli(args: argparse.Namespace) -> int: 15 """ Run the CLI. """ 16 17 config = args._config 18 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 groupset_query = lms.cli.common.check_required_groupset(backend, config) 26 if (groupset_query is None): 27 return 2 28 29 memberships = lms.cli.courses.groupsets.memberships.common.load_group_memberships(backend, args.path, args.skip_rows) 30 31 created_groups, counts = backend.courses_groupsets_memberships_resolve_and_add(course_query, groupset_query, memberships) 32 33 if (len(created_groups) > 0): 34 display_groups = [str(group.to_query()) for group in created_groups] 35 print(f"Created {len(created_groups)} groups: {display_groups}.") 36 37 total_count = 0 38 for (group_query, count) in counts.items(): 39 print(f"Added {count} users to group {group_query}.") 40 total_count += count 41 42 return lms.cli.common.strict_check(args.strict, (total_count != len(memberships)), 43 f"Expected to add {len(memberships)} memberships to groupset, but added {total_count}.", 3) 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_output_format = True, 54 include_course = True, 55 include_groupset = True, 56 include_group = True, 57 include_skip_rows = True, 58 include_strict = True, 59 ) 60 61 parser.add_argument('path', metavar = 'PATH', 62 action = 'store', type = str, 63 help = 'Path to a TSV file where each row has 2 columns: group query and user query.') 64 65 return parser 66 67if (__name__ == '__main__'): 68 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
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 groupset_query = lms.cli.common.check_required_groupset(backend, config) 27 if (groupset_query is None): 28 return 2 29 30 memberships = lms.cli.courses.groupsets.memberships.common.load_group_memberships(backend, args.path, args.skip_rows) 31 32 created_groups, counts = backend.courses_groupsets_memberships_resolve_and_add(course_query, groupset_query, memberships) 33 34 if (len(created_groups) > 0): 35 display_groups = [str(group.to_query()) for group in created_groups] 36 print(f"Created {len(created_groups)} groups: {display_groups}.") 37 38 total_count = 0 39 for (group_query, count) in counts.items(): 40 print(f"Added {count} users to group {group_query}.") 41 total_count += count 42 43 return lms.cli.common.strict_check(args.strict, (total_count != len(memberships)), 44 f"Expected to add {len(memberships)} memberships to groupset, but added {total_count}.", 3)
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.