-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist-groups.py
executable file
·36 lines (29 loc) · 1.61 KB
/
list-groups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import json
from getpass import getpass
from devilryrestfullib import RestfulFactory
from devilrycliscriptslib.argparsewrapper import ArgumentParser
from devilrycliscriptslib.login import login_using_args
from devilrycliscriptslib.commonargs import add_common_args
from devilrycliscriptslib.queries import find_groups_in_assignment
from devilrycliscriptslib.queries import find_assignment_id_by_shortnames
from devilrycliscriptslib.utils import split_path
argparser = ArgumentParser(description='List groups on an assignment as json encoded data.')
add_common_args(argparser)
argparser.add_argument('--assignment', required=True,
help='Path to assignment. E.g: "duck1010.spring2010.assignment1"')
args = argparser.parse_args()
logincookie = login_using_args(args, getpass())
restful_factory = RestfulFactory(args.url)
AssignmentGroupApi = restful_factory.make('/administrator/restfulsimplifiedassignmentgroup/')
AssignmentApi = restful_factory.make('/administrator/restfulsimplifiedassignment/')
DeadlineApi = restful_factory.make('/administrator/restfulsimplifieddeadline/')
try:
path = split_path(args.assignment, '--assignment', 3)
source_assignment_id = find_assignment_id_by_shortnames(AssignmentApi, logincookie,
*path)
except LookupError:
raise SystemExit('Assignment {0} not found.'.format(args.assignment))
groups = find_groups_in_assignment(AssignmentGroupApi, logincookie, source_assignment_id,
result_fieldgroups=['feedback', 'users', 'tags'])
print json.dumps(groups, indent=2)