* requestsync: Use the functions in the common.py file above to authenticate

with Launchpad.
* common.py: Check that the file written has Launchpad entries.
* buildd: Use new functions in common.py.
This commit is contained in:
Jonathan Patrick Davies 2008-08-11 22:53:37 +01:00
parent 341f2a60b5
commit 0adea5faa0
4 changed files with 29 additions and 25 deletions

3
buildd
View File

@ -37,7 +37,8 @@ operation: status | retry | rescore [priority (default 5000)]''' % sys.argv[0]
sys.exit(1) sys.exit(1)
# Prepare Launchpad cookie. # Prepare Launchpad cookie.
urlopener = common.prepareLaunchpadCookie() launchpadCookie = common.prepareLaunchpadCookie()
urlopener = common.setupLaunchpadUrlOpener(launchpadCookie)
# Find out the version in given release. # Find out the version in given release.
try: try:

View File

@ -50,10 +50,10 @@ def prepareLaunchpadCookie():
# Unable to find an correct file. # Unable to find an correct file.
if launchpad_cookiefile == None: if launchpad_cookiefile == None:
print >> sys.stderr, 'Could not find cookie file for Launchpad " \ print >> sys.stderr, "Could not find cookie file for Launchpad. "
"(looked in " \ %s)' % ", ".join(try_globs) print >> sys.stderr, "Looked in: %s" % ", ".join(try_globs)
print >> sys.stderr, 'You should be able to create a valid file by " \ print >> sys.stderr, "You should be able to create a valid file by " \
"logging into Launchpad with Firefox' "logging into Launchpad with Firefox."
sys.exit(1) sys.exit(1)
# Found SQLite file. Parse information from it. # Found SQLite file. Parse information from it.
@ -78,13 +78,26 @@ def prepareLaunchpadCookie():
newLPCookie.write("\n") # New line. newLPCookie.write("\n") # New line.
newLPCookie.close() newLPCookie.close()
# Check what we have written.
checkCookie = open("%s/.lpcookie.txt" % os.environ.get('HOME')).read()
if checkCookie == "# HTTP Cookie File.\n\n":
print >> sys.stderr, "No Launchpad cookies were written to file. " \
"Please visit and log into Launchpad and run this script again."
os.remove("%s/.lpcookie.txt" % os.environ.get('HOME')) # Delete file.
sys.exit(1)
launchpad_cookiefile = "%s/.lpcookie.txt" % os.environ.get('HOME') launchpad_cookiefile = "%s/.lpcookie.txt" % os.environ.get('HOME')
print "Using cookie file at: %s." % launchpad_cookiefile print "Using cookie file at: %s." % launchpad_cookiefile
# Build HTML opener with cookie file. # Return the Launchpad cookie.
return launchpad_cookiefile
def setupLaunchpadUrlOpener(cookie):
""" Build HTML opener with cookie file. """
cj = cookielib.MozillaCookieJar() cj = cookielib.MozillaCookieJar()
cj.load(launchpad_cookiefile) cj.load(cookie)
urlopener = urllib2.build_opener() urlopener = urllib2.build_opener()
urlopener.add_handler(urllib2.HTTPCookieProcessor(cj)) urlopener.add_handler(urllib2.HTTPCookieProcessor(cj))

2
debian/changelog vendored
View File

@ -13,6 +13,8 @@ ubuntu-dev-tools (0.37ubuntu1) intrepid; urgency=low
to authenticate with Launchpad. to authenticate with Launchpad.
* debian/ubuntu-dev-tools.install: Added line to install common.py above to * debian/ubuntu-dev-tools.install: Added line to install common.py above to
the correct location. the correct location.
* requestsync: Use the functions in the common.py file above to authenticate
with Launchpad
[ Siegfried-Angel Gevatter Pujals ] [ Siegfried-Angel Gevatter Pujals ]
* Add the GNU General Public License header to all scripts. * Add the GNU General Public License header to all scripts.

View File

@ -255,23 +255,11 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext):
print >> sys.stderr, 'Importing launchpadbugs failed. Is python-launchpad-bugs installed?' print >> sys.stderr, 'Importing launchpadbugs failed. Is python-launchpad-bugs installed?'
return False return False
# Search cookiefile (for authentication to lp) # Use functions from ubuntu-dev-tools to create Launchpad cookie file.
if launchpad_cookiefile == None: sys.path.append('/usr/share/ubuntu-dev-tools/')
try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite', '~/.mozilla/*/*/cookies.txt') import common
for try_glob in try_globs:
try:
cookiefile = glob.glob(os.path.expanduser(try_glob))[0]
except IndexError:
continue
# Found:
launchpad_cookiefile = cookiefile
print "Using cookie file at «%s».\n" % launchpad_cookiefile
break
if launchpad_cookiefile == None: launchpad_cookiefile = common.prepareLaunchpadCookie()
print >> sys.stderr, 'Could not find cookie file for Launchpad (looked in %s)' % ", ".join(try_globs)
print >> sys.stderr, 'You should be able to create a valid file by logging into Launchpad with Firefox'
return False
if source_package: if source_package:
product = {'name': source_package, 'target': 'ubuntu'} product = {'name': source_package, 'target': 'ubuntu'}