-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgroup_audit.py
More file actions
77 lines (61 loc) · 1.94 KB
/
Copy pathgroup_audit.py
File metadata and controls
77 lines (61 loc) · 1.94 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/python
"""
Scan through a dump of google groups and locate those with one
member, where the member is not another group.
"""
import httplib2
import argparse
import pprint
import sys
import pickle
import os.path
def find_empty_groups(groupdir):
for email in groupdir:
group = groupdir[email]
if group['members'] is None:
print email, group['directMembersCount']
def find_single_user_groups(groupdir):
for email in groupdir:
group = groupdir[email]
members = group['members']
if members is not None:
if group['directMembersCount'] == '1' and members[0]['type'] == 'USER':
print email, '->', members[0]['email']
def main(argv):
# Declare command-line flags.
# addHelp=False here because it's added downstream in the sample_init
argparser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
argparser.add_argument(
'-i',
'--input',
default='./group_dump.pickle',
help='filename of group dump file'
)
argparser.add_argument(
'-v',
'--verbose',
help='Verbose output',
action='store_true')
argparser.add_argument(
'command',
choices=['empty', 'single_user_member'],
help='Action to be taken')
flags = argparser.parse_args(argv[1:])
with open(flags.input, 'rb') as f:
group_dump = pickle.load(f)
if flags.verbose:
dumpdate = group_dump['dumpdate']
print 'Group Dump Date (UTC):',\
dumpdate.strftime("%A, %d %B %Y %I:%M%p")
groupdir = group_dump['groupdir']
if flags.command == 'empty':
find_empty_groups(groupdir)
elif flags.command == 'single_user_member':
find_single_user_groups(groupdir)
else:
print 'invalid command'
# pprint.pprint(groupdir)
if __name__ == '__main__':
main(sys.argv)