~launchpad-pqm/launchpad/devel

3944.1.1 by Francis J. Lacoste
Use system version python2.4 for scripts.
1
#!/usr/bin/python2.4
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
4284.5.7 by Tom Haddon
Better variable names, trimming some whitespace and more elegantly handling argument parsing by setting default "format" variable
47
        member_details = []
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
48
        for teamname in teamnames:
49
            try:
4284.5.7 by Tom Haddon
Better variable names, trimming some whitespace and more elegantly handling argument parsing by setting default "format" variable
50
                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
51
            except NoSuchTeamError:
52
                print "Error, no such team: %s" % teamname
4284.5.6 by Tom Haddon
Code refactoring following review comments
53
                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
54
        # We don't want duplicates, so use "set" get unique only
55
        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
56
        return 0
2263 by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless]
57
58
if __name__ == '__main__':
4953.5.1 by Tom Haddon
Hard coding a unique db user for the list-team-members script
59
    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
60
    script.run()