~launchpad-pqm/launchpad/devel

3944.1.1 by Francis J. Lacoste
Use system version python2.4 for scripts.
1
#!/usr/bin/python2.4
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
2
# Copyright 2007 Canonical Ltd.  All rights reserved.
3
4284.5.6 by Tom Haddon
Code refactoring following review comments
4
__metaclass__ = type
5
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
6
import logging
2263 by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless]
7
import sys
8
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
9
import _pythonpath
10
11
from canonical.config import config
12
2263 by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless]
13
from canonical.launchpad.scripts import execute_zcml_for_scripts
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
14
from canonical.launchpad.scripts.base import LaunchpadScript
15
from canonical.launchpad.scripts.listteammembers import process_team, NoSuchTeamError
16
17
18
class ListTeamMembersScript(LaunchpadScript):
19
20
    description = "Create a list of members of a team."
21
    usage = "usage: %s [-e|--email-only|-f|--full-details] team-name [team-name-2] .. [team-name-n]" % sys.argv[0]
22
    loglevel = logging.INFO
23
24
    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
25
        self.parser.set_defaults(format='simple')
4284.5.6 by Tom Haddon
Code refactoring following review comments
26
        self.parser.add_option(
27
            '-e', '--email-only', action='store_const', const='email',
28
            help='Only print email addresses', dest='format')
29
        self.parser.add_option(
30
            '-f', '--full-details', action='store_const', const='full',
31
            help='Print full details', dest='format')
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
32
33
    def main(self):
34
4284.5.6 by Tom Haddon
Code refactoring following review comments
35
        display_option = self.options.format
36
        teamnames = self.args
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
37
4284.5.6 by Tom Haddon
Code refactoring following review comments
38
        if not teamnames:
39
            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
40
4284.5.7 by Tom Haddon
Better variable names, trimming some whitespace and more elegantly handling argument parsing by setting default "format" variable
41
        member_details = []
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
42
        for teamname in teamnames:
43
            try:
4284.5.7 by Tom Haddon
Better variable names, trimming some whitespace and more elegantly handling argument parsing by setting default "format" variable
44
                member_details.extend(process_team(teamname, display_option))
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
45
            except NoSuchTeamError:
46
                print "Error, no such team: %s" % teamname
4284.5.6 by Tom Haddon
Code refactoring following review comments
47
                return 1
4284.5.7 by Tom Haddon
Better variable names, trimming some whitespace and more elegantly handling argument parsing by setting default "format" variable
48
        # We don't want duplicates, so use "set" get unique only
49
        print "\n".join(sorted(list(set(member_details))))
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
50
        return 0
2263 by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless]
51
52
if __name__ == '__main__':
4953.5.1 by Tom Haddon
Hard coding a unique db user for the list-team-members script
53
    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
54
    script.run()