2009-01-25 10:04:06 +00:00
|
|
|
#
|
|
|
|
# functions.py - various Launchpad-related functions for the Ubuntu Developer
|
|
|
|
# Tools package
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008, 2009 Jonathan Davies <jpds@ubuntu.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 3
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# Please see the /usr/share/common-licenses/GPL file for the full text of
|
|
|
|
# the GNU General Public License license.
|
|
|
|
#
|
|
|
|
|
2009-01-19 22:37:27 +00:00
|
|
|
import cookie
|
2009-01-25 01:05:02 +00:00
|
|
|
import urlopener as lp_urlopener
|
2009-01-19 17:55:00 +00:00
|
|
|
|
|
|
|
def isLPTeamMember(team):
|
|
|
|
""" Checks if the user is a member of a certain team on Launchpad.
|
|
|
|
|
|
|
|
We do this by opening the team page on Launchpad and checking if the
|
|
|
|
text "You are not a member of this team" is present using the
|
|
|
|
user's cookie file for authentication.
|
|
|
|
|
|
|
|
If the user is a member of the team: return True.
|
|
|
|
If the user is not a member of the team: return False.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO: Check if launchpadlib may be a better way of doing this.
|
|
|
|
|
|
|
|
# Prepare cookie.
|
2009-01-19 22:37:27 +00:00
|
|
|
cookieFile = cookie.prepareLaunchpadCookie()
|
2009-01-19 17:55:00 +00:00
|
|
|
# Prepare URL opener.
|
2009-01-25 01:05:02 +00:00
|
|
|
urlopener = lp_urlopener.setupLaunchpadUrlOpener(cookieFile)
|
2009-01-19 17:55:00 +00:00
|
|
|
|
|
|
|
# Try to open the Launchpad team page:
|
|
|
|
try:
|
|
|
|
lpTeamPage = urlopener.open("https://launchpad.net/~%s" % team).read()
|
|
|
|
except urllib2.HTTPError, error:
|
|
|
|
print >> sys.stderr, "Unable to connect to Launchpad. Received a %s." % error.code
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Check if text is present in page.
|
|
|
|
if ("You are not a member of this team") in lpTeamPage:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|