10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.23
by Karl Fogel
Add the copyright header block to more files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
5 |
|
4284.5.6
by Tom Haddon
Code refactoring following review comments |
6 |
__metaclass__ = type |
7 |
||
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
8 |
import logging |
2263
by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless] |
9 |
import sys |
10 |
||
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
11 |
import _pythonpath |
12 |
||
13 |
from canonical.config import config |
|
14 |
||
2263
by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless] |
15 |
from canonical.launchpad.scripts import execute_zcml_for_scripts |
8356.1.10
by Leonard Richardson
Fix test failures. |
16 |
from lp.services.scripts.base import LaunchpadScript |
8137.17.24
by Barry Warsaw
thread merge |
17 |
from lp.registry.scripts.listteammembers import process_team, NoSuchTeamError |
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
18 |
|
19 |
||
20 |
class ListTeamMembersScript(LaunchpadScript): |
|
21 |
||
22 |
description = "Create a list of members of a team." |
|
8137.17.24
by Barry Warsaw
thread merge |
23 |
usage = "usage: %s [-e|--email-only|-f|--full-details|-s|--ssh-keys] " \ |
24 |
"team-name [team-name-2] .. [team-name-n]" % sys.argv[0] |
|
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
25 |
loglevel = logging.INFO |
26 |
||
27 |
def add_my_options(self): |
|
4284.5.7
by Tom Haddon
Better variable names, trimming some whitespace and more elegantly handling argument parsing by setting default "format" variable |
28 |
self.parser.set_defaults(format='simple') |
4284.5.6
by Tom Haddon
Code refactoring following review comments |
29 |
self.parser.add_option( |
30 |
'-e', '--email-only', action='store_const', const='email', |
|
31 |
help='Only print email addresses', dest='format') |
|
32 |
self.parser.add_option( |
|
33 |
'-f', '--full-details', action='store_const', const='full', |
|
34 |
help='Print full details', dest='format') |
|
8137.17.24
by Barry Warsaw
thread merge |
35 |
self.parser.add_option( |
36 |
'-s', '--ssh-keys', action='store_const', const='sshkeys', |
|
37 |
help='Print sshkeys', dest='format') |
|
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
38 |
|
39 |
def main(self): |
|
40 |
||
4284.5.6
by Tom Haddon
Code refactoring following review comments |
41 |
display_option = self.options.format |
42 |
teamnames = self.args |
|
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
43 |
|
4284.5.6
by Tom Haddon
Code refactoring following review comments |
44 |
if not teamnames: |
45 |
self.parser.error('No team specified') |
|
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
46 |
|
9983.2.2
by Gary Poster
clean up further based on review feedback |
47 |
# We don't want duplicates, so use a set to enforce uniqueness.
|
48 |
member_details = set() |
|
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
49 |
for teamname in teamnames: |
50 |
try: |
|
9983.2.2
by Gary Poster
clean up further based on review feedback |
51 |
member_details.update(process_team(teamname, display_option)) |
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
52 |
except NoSuchTeamError: |
53 |
print "Error, no such team: %s" % teamname |
|
4284.5.6
by Tom Haddon
Code refactoring following review comments |
54 |
return 1 |
9983.2.1
by Gary Poster
commit cowboyed change to list-team-members script to handle unicode by explicitly encoding to utf8 |
55 |
print "\n".join(detail.encode('utf-8') for detail in |
9983.2.2
by Gary Poster
clean up further based on review feedback |
56 |
sorted(member_details)) |
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
57 |
return 0 |
2263
by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless] |
58 |
|
59 |
if __name__ == '__main__': |
|
4953.5.1
by Tom Haddon
Hard coding a unique db user for the list-team-members script |
60 |
script = ListTeamMembersScript('canonical.launchpad.scripts.listteammembers', dbuser='listteammembers') |
4284.5.2
by Tom Haddon
Optionally give it -e or -f options for email only or full details |
61 |
script.run() |