| 1 |
#! /usr/bin/python3 |
| 2 |
# |
| 3 |
# Copyright (C) 2009 Canonical Ltd |
| 4 |
|
| 5 |
# lp-check-membership is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by the |
| 7 |
# Free Software Foundation; either version 3, or (at your option) any |
| 8 |
# later version. |
| 9 |
# |
| 10 |
# lp-check-membership is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with lp-check-membership; see the file COPYING. If not, write to the Free |
| 17 |
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 |
# 02110-1301, USA. |
| 19 |
# |
| 20 |
# Authors: |
| 21 |
# Martin Pool |
| 22 |
|
| 23 |
"""lp-check-membership: Check whether a user is a member of a team. |
| 24 |
|
| 25 |
example: lp-check-membership mbp bzr |
| 26 |
|
| 27 |
Part of lptools <https://launchpad.net/lptools/> |
| 28 |
""" |
| 29 |
|
| 30 |
|
| 31 |
import optparse |
| 32 |
import sys |
| 33 |
|
| 34 |
from lptools import config |
| 35 |
|
| 36 |
|
| 37 |
def main(argv): |
| 38 |
parser = optparse.OptionParser('%prog [options] PERSON GROUP') |
| 39 |
opts, args = parser.parse_args() |
| 40 |
if len(args) != 2: |
| 41 |
print(__doc__) |
| 42 |
return 2 |
| 43 |
user_name = args[0] |
| 44 |
group_name = args[1] |
| 45 |
lp = config.get_launchpad("check-membership") |
| 46 |
user = lp.people[user_name] |
| 47 |
for user_team in user.super_teams: |
| 48 |
if user_team.name == group_name: |
| 49 |
print('%s is a member of %s' % (user_name, group_name)) |
| 50 |
return 0 |
| 51 |
else: |
| 52 |
print('%s is not a member of %s' % (user_name, group_name)) |
| 53 |
return 1 |
| 54 |
|
| 55 |
|
| 56 |
if __name__ == '__main__': |
| 57 |
sys.exit(main(sys.argv)) |