mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-18 20:31:29 +00:00
* common.py: New functions: checkReleaseExists() and checkSourceExists().
* buildd and pull-lp-source: Adapt code to use new functions above.
This commit is contained in:
parent
01db3cd8aa
commit
70fc6fa3c7
20
buildd
20
buildd
@ -91,22 +91,12 @@ if os.environ.has_key('https_proxy'):
|
|||||||
launchpadCookie = common.prepareLaunchpadCookie()
|
launchpadCookie = common.prepareLaunchpadCookie()
|
||||||
urlopener = common.setupLaunchpadUrlOpener(launchpadCookie)
|
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.
|
# Find out the version in given release.
|
||||||
try:
|
(page, version) = common.checkSourceExists(package, release)
|
||||||
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)
|
|
||||||
|
|
||||||
# Output details.
|
# Output details.
|
||||||
print "The source version for '%s' in %s is at %s." % (package,
|
print "The source version for '%s' in %s is at %s." % (package,
|
||||||
|
49
common.py
49
common.py
@ -27,6 +27,7 @@
|
|||||||
import cookielib
|
import cookielib
|
||||||
import glob
|
import glob
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
@ -61,6 +62,54 @@ def readlist(filename, uniq=True):
|
|||||||
|
|
||||||
return items
|
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():
|
def prepareLaunchpadCookie():
|
||||||
""" Search for a cookie file in the places as defined by try_globs.
|
""" Search for a cookie file in the places as defined by try_globs.
|
||||||
We shall use this cookie for authentication with Launchpad. """
|
We shall use this cookie for authentication with Launchpad. """
|
||||||
|
2
debian/changelog
vendored
2
debian/changelog
vendored
@ -3,6 +3,8 @@ ubuntu-dev-tools (0.42ubuntu1) intrepid; urgency=low
|
|||||||
[Jonathan Patrick Davies]
|
[Jonathan Patrick Davies]
|
||||||
* requestsync: Exit when connecting to Launchpad fails.
|
* requestsync: Exit when connecting to Launchpad fails.
|
||||||
* doc/requestsync.1: Document new -d flag.
|
* 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 ]
|
[ Jelmer Vernooij ]
|
||||||
* requestsync: Add -d option to allow overriding the Debian distro to sync
|
* requestsync: Add -d option to allow overriding the Debian distro to sync
|
||||||
|
@ -32,6 +32,10 @@ import sys
|
|||||||
import urllib2
|
import urllib2
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
# Ubuntu-dev-tools modules.
|
||||||
|
sys.path.append("/usr/share/ubuntu-dev-tools")
|
||||||
|
import common
|
||||||
|
|
||||||
class BackportFromLP:
|
class BackportFromLP:
|
||||||
|
|
||||||
def __getitem__(self, name):
|
def __getitem__(self, name):
|
||||||
@ -67,54 +71,19 @@ if __name__ == '__main__':
|
|||||||
optParser.print_help()
|
optParser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
package = args[0]
|
package = str(args[0]).lower()
|
||||||
|
|
||||||
if len(args) == 2: # Custom distribution specified.
|
if len(args) == 2: # Custom distribution specified.
|
||||||
release = args[1]
|
release = str(args[1]).lower()
|
||||||
else:
|
else:
|
||||||
release = os.getenv('DIST') or default_release
|
release = os.getenv('DIST') or default_release
|
||||||
|
|
||||||
# Correct-ish args, can proceed.
|
# Correct-ish args, can proceed.
|
||||||
# Check release by checking if Launchpad page exists
|
# Check release by checking if Launchpad page exists
|
||||||
try:
|
common.checkReleaseExists(release)
|
||||||
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)
|
|
||||||
|
|
||||||
# Check package exists.
|
# Check package exists.
|
||||||
try:
|
common.checkSourceExists(package, release)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
# All good - start downloading...
|
# All good - start downloading...
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user