* common.py: New functions: checkReleaseExists() and checkSourceExists().

* buildd and pull-lp-source: Adapt code to use new functions above.
This commit is contained in:
Jonathan Patrick Davies 2008-08-27 10:22:08 +01:00
parent 01db3cd8aa
commit 70fc6fa3c7
4 changed files with 64 additions and 54 deletions

20
buildd
View File

@ -91,22 +91,12 @@ if os.environ.has_key('https_proxy'):
launchpadCookie = common.prepareLaunchpadCookie()
urlopener = common.setupLaunchpadUrlOpener(launchpadCookie)
# Check the release exists.
# Check release by checking if Launchpad page exists
common.checkReleaseExists(release)
# Find out the version in given release.
try:
page = urlopener.open('https://launchpad.net/ubuntu/+source/' + package).read()
except urllib2.HTTPError:
print >> sys.stderr, "The source package (%s) does not appear to exist " \
"in Ubuntu." % package
sys.exit(1)
m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release,
package.replace('+', '\+')), page)
if not m:
print >> sys.stderr, "Unable to find this source package (%s) in this " \
"release (%s)." % (package, release.capitalize())
sys.exit(1)
version = m.group(1)
(page, version) = common.checkSourceExists(package, release)
# Output details.
print "The source version for '%s' in %s is at %s." % (package,

View File

@ -27,6 +27,7 @@
import cookielib
import glob
import os.path
import re
import sys
import urllib2
@ -61,6 +62,54 @@ def readlist(filename, uniq=True):
return items
def checkReleaseExists(release):
""" Check that an Ubuntu release exists by opening
https://launchpad.net/ubuntu/releaseName page on Launchpad.
If an error is returned; the release does not exist. """
try:
urllib2.urlopen("https://launchpad.net/ubuntu/%s" % release)
except urllib2.HTTPError:
print >> sys.stderr, "The '%s' release does not appear to exist on " \
"Launchpad." % release
sys.exit(1)
def checkSourceExists(package, release):
""" Check that a package exists by opening its
https://launchpad.net/ubuntu/+source/package page.
Return the page and version in release. """
try:
page = urllib2.urlopen('https://launchpad.net/ubuntu/+source/' + package).read()
m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release,
package.replace('+', '\+')), page)
if not m:
print >> sys.stderr, "Unable to find this source package (%s) in " \
"this release (%s)." % (package, release.capitalize())
sys.exit(1)
except urllib2.HTTPError, error: # Raised on 404.
if error.code == 404:
print >> sys.stderr, "The source package (%s) does not appear to " \
"exist in Ubuntu." % package
else: # Other error code, probably Launchpad malfunction.
print >> sys.stderr, "Error when checking Launchpad for package: " \
"%s." % error
sys.exit(1) # Exit. Error encountered.
except urllib2.URLError, error: # Other error (NXDOMAIN, ...)
(_, reason) = error.reason
print >> sys.stderr, "Error when checking Launchpad for package: %s." % \
reason
sys.exit(1)
# Get package version.
version = m.group(1)
return page, version
def prepareLaunchpadCookie():
""" Search for a cookie file in the places as defined by try_globs.
We shall use this cookie for authentication with Launchpad. """

2
debian/changelog vendored
View File

@ -3,6 +3,8 @@ ubuntu-dev-tools (0.42ubuntu1) intrepid; urgency=low
[Jonathan Patrick Davies]
* requestsync: Exit when connecting to Launchpad fails.
* doc/requestsync.1: Document new -d flag.
* common.py: New functions: checkReleaseExists() and checkSourceExists().
* buildd and pull-lp-source: Adapt code to use new functions above.
[ Jelmer Vernooij ]
* requestsync: Add -d option to allow overriding the Debian distro to sync

View File

@ -32,6 +32,10 @@ import sys
import urllib2
from optparse import OptionParser
# Ubuntu-dev-tools modules.
sys.path.append("/usr/share/ubuntu-dev-tools")
import common
class BackportFromLP:
def __getitem__(self, name):
@ -67,54 +71,19 @@ if __name__ == '__main__':
optParser.print_help()
sys.exit(1)
package = args[0]
package = str(args[0]).lower()
if len(args) == 2: # Custom distribution specified.
release = args[1]
release = str(args[1]).lower()
else:
release = os.getenv('DIST') or default_release
# Correct-ish args, can proceed.
# Check release by checking if Launchpad page exists
try:
urllib2.urlopen("https://launchpad.net/ubuntu/%s" % release)
except urllib2.HTTPError:
print >> sys.stderr, "The '%s' release does not appear to exist on " \
"Launchpad." % release
sys.exit(1)
common.checkReleaseExists(release)
# Check package exists.
try:
sourcePage = urllib2.urlopen("https://launchpad.net/ubuntu/%s/+source/%s" % \
(release, package)).read()
m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, \
package.replace('+', '\+')), sourcePage)
if not m:
print >> sys.stderr, "The '%s' package does not appear to exist in " \
"the '%s' release." % (package, release)
sys.exit(1)
except urllib2.HTTPError, e: # Raised on 404
if e.code == 404:
print >> sys.stderr, "The '%s' package does not appear to exist in " \
"the '%s' release." % (package, release)
else: # Other code, probably LP malfunction
print >> sys.stderr, "Error when checking Launchpad for package: %s " % e
sys.exit(1)
except urllib2.URLError, e: # Other error (NXDOMAIN, ...)
(_, reason) = e.reason
print >> sys.stderr, "Error when checking Launchpad for package: %s " % reason
sys.exit(1)
common.checkSourceExists(package, release)
# All good - start downloading...
try: