-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmembers-get.py
executable file
·75 lines (55 loc) · 2.06 KB
/
members-get.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
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
#!/usr/bin/env python3
import sys, codecs, locale
from optparse import OptionParser
# Ensure Unicode output
if sys.version_info < (3,1):
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
else:
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout.detach())
team = "ubuntu-irc-members" # default team
usage = 'Usage: %prog [options]'
description = 'Print the members of a team.'
parser = OptionParser(usage=usage, description=description, add_help_option=False)
parser.add_option('-t', '--team', help='Specify team.')
parser.add_option('-m', '--markdown', action='store_true', default=False,
help='Print as Markdown.')
parser.add_option('-h', '--help', action='help', help='Print this help text.')
opts, args = parser.parse_args()
if opts.team:
team = opts.team
cachedir = "~/.cache/launchpadlib"
from launchpadlib.launchpad import Launchpad
launchpad = Launchpad.login_with('Ubuntu IRC Lister', 'production',
cachedir, version='devel')
try:
team = launchpad.people[team]
except KeyError:
print("The team '{}' does not exist on Launchpad.".format(team))
sys.exit(1)
if not opts.markdown:
print(u'=== {} ==='.format(team.display_name))
print(u'++ {} ++'.format(team.web_link))
else:
print(u'== link:{}[{}] =='.format(team.web_link, team.display_name))
members = {}
for member in team.members:
if not member.is_team:
members[member.name] = member
for member in sorted(members):
member = members[member]
if not opts.markdown:
output = u' * {} - {}'.format(member.web_link, member.display_name)
else:
output = u' * link:{}[{}]'.format(member.web_link, member.display_name)
# Check if they're active.
if member.name.endswith('-deactivatedaccount'):
output += "'"
if opts.markdown:
output = output.replace(' * ', " * '", 1)
try:
email = member.preferred_email_address.email
except ValueError:
email = None
if email:
output += ' <{}>'.format(email)
print(output)