~launchpad-pqm/launchpad/devel

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
#!/usr/bin/python2.5 -S
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

__metaclass__ = type

import logging
import sys

import _pythonpath

from canonical.config import config

from canonical.launchpad.scripts import execute_zcml_for_scripts
from lp.services.scripts.base import LaunchpadScript
from lp.registry.scripts.listteammembers import process_team, NoSuchTeamError


class ListTeamMembersScript(LaunchpadScript):

    description = "Create a list of members of a team."
    usage = "usage: %s [-e|--email-only|-f|--full-details|-s|--ssh-keys] " \
        "team-name [team-name-2] .. [team-name-n]" % sys.argv[0]
    loglevel = logging.INFO

    def add_my_options(self):
        self.parser.set_defaults(format='simple')
        self.parser.add_option(
            '-e', '--email-only', action='store_const', const='email',
            help='Only print email addresses', dest='format')
        self.parser.add_option(
            '-f', '--full-details', action='store_const', const='full',
            help='Print full details', dest='format')
        self.parser.add_option(
            '-s', '--ssh-keys', action='store_const', const='sshkeys',
            help='Print sshkeys', dest='format')

    def main(self):

        display_option = self.options.format
        teamnames = self.args

        if not teamnames:
            self.parser.error('No team specified')

        # We don't want duplicates, so use a set to enforce uniqueness.
        member_details = set()
        for teamname in teamnames:
            try:
                member_details.update(process_team(teamname, display_option))
            except NoSuchTeamError:
                print "Error, no such team: %s" % teamname
                return 1
        print "\n".join(detail.encode('utf-8') for detail in
                        sorted(member_details))
        return 0

if __name__ == '__main__':
    script = ListTeamMembersScript('canonical.launchpad.scripts.listteammembers', dbuser='listteammembers')
    script.run()