~launchpad-pqm/launchpad/devel

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
14612.2.7 by William Grant
scripts
8
import _pythonpath
9
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
10
import logging
2263 by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless]
11
import sys
12
14612.2.7 by William Grant
scripts
13
from lp.registry.scripts.listteammembers import (
14
    NoSuchTeamError,
15
    process_team,
16
    )
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
17
from lp.services.config import config
14565.2.15 by Curtis Hovey
Moved canonical.launchpad.scripts __init__ to lp.services.scripts.
18
from lp.services.scripts import execute_zcml_for_scripts
8356.1.10 by Leonard Richardson
Fix test failures.
19
from lp.services.scripts.base import LaunchpadScript
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
20
21
22
class ListTeamMembersScript(LaunchpadScript):
23
24
    description = "Create a list of members of a team."
8137.17.24 by Barry Warsaw
thread merge
25
    usage = "usage: %s [-e|--email-only|-f|--full-details|-s|--ssh-keys] " \
26
        "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
27
    loglevel = logging.INFO
28
29
    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
30
        self.parser.set_defaults(format='simple')
4284.5.6 by Tom Haddon
Code refactoring following review comments
31
        self.parser.add_option(
32
            '-e', '--email-only', action='store_const', const='email',
33
            help='Only print email addresses', dest='format')
34
        self.parser.add_option(
35
            '-f', '--full-details', action='store_const', const='full',
36
            help='Print full details', dest='format')
8137.17.24 by Barry Warsaw
thread merge
37
        self.parser.add_option(
38
            '-s', '--ssh-keys', action='store_const', const='sshkeys',
39
            help='Print sshkeys', dest='format')
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
40
41
    def main(self):
42
4284.5.6 by Tom Haddon
Code refactoring following review comments
43
        display_option = self.options.format
44
        teamnames = self.args
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
45
4284.5.6 by Tom Haddon
Code refactoring following review comments
46
        if not teamnames:
47
            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
48
9983.2.2 by Gary Poster
clean up further based on review feedback
49
        # We don't want duplicates, so use a set to enforce uniqueness.
50
        member_details = set()
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
51
        for teamname in teamnames:
52
            try:
9983.2.2 by Gary Poster
clean up further based on review feedback
53
                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
54
            except NoSuchTeamError:
55
                print "Error, no such team: %s" % teamname
4284.5.6 by Tom Haddon
Code refactoring following review comments
56
                return 1
9983.2.1 by Gary Poster
commit cowboyed change to list-team-members script to handle unicode by explicitly encoding to utf8
57
        print "\n".join(detail.encode('utf-8') for detail in
9983.2.2 by Gary Poster
clean up further based on review feedback
58
                        sorted(member_details))
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
59
        return 0
2263 by Canonical.com Patch Queue Manager
po translation page location fixes, and new-style cve support [r=spiv,lifeless]
60
61
if __name__ == '__main__':
14565.2.15 by Curtis Hovey
Moved canonical.launchpad.scripts __init__ to lp.services.scripts.
62
    script = ListTeamMembersScript('lp.services.scripts.listteammembers', dbuser='listteammembers')
4284.5.2 by Tom Haddon
Optionally give it -e or -f options for email only or full details
63
    script.run()