Lets make ubuntutools.mirrors return filenames

This commit is contained in:
Stefano Rivera 2010-12-28 00:42:35 +02:00
parent 2c27cf68a6
commit be79f00dff
3 changed files with 41 additions and 39 deletions

View File

@ -32,7 +32,7 @@ import lsb_release
from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.builder import get_builder from ubuntutools.builder import get_builder
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.mirrors import dsc_name, pull_source_pkg from ubuntutools.mirrors import pull_source_pkg
from ubuntutools.question import YesNoQuestion from ubuntutools.question import YesNoQuestion
def error(msg): def error(msg):
@ -200,9 +200,8 @@ def fetch_package(launchpad, mirror, workdir, package, version, source_release):
srcpkg = find_version_package(launchpad, package, version) srcpkg = find_version_package(launchpad, package, version)
version = srcpkg.source_package_version version = srcpkg.source_package_version
pull_source_pkg('UBUNTU', mirror, srcpkg.component_name, package, version, return pull_source_pkg('UBUNTU', mirror, srcpkg.component_name, package,
workdir=workdir, unpack=False) version, workdir=workdir, unpack=False)
return dsc_name(package, version)
def get_backport_version(version, suffix, upload, release): def get_backport_version(version, suffix, upload, release):
backport_version = version + ('~%s1' % release) backport_version = version + ('~%s1' % release)

View File

@ -25,7 +25,7 @@ import debian.changelog
from ubuntutools.config import UDTConfig from ubuntutools.config import UDTConfig
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.mirrors import dsc_name, pull_source_pkg from ubuntutools.mirrors import pull_source_pkg
def previous_version(package, version, distance): def previous_version(package, version, distance):
"Given an (extracted) package, determine the version distance versions ago" "Given an (extracted) package, determine the version distance versions ago"
@ -83,10 +83,10 @@ def main():
# TODO: Not all packages are main, but snapshot.debian.org should save # TODO: Not all packages are main, but snapshot.debian.org should save
# the day, as it doesn't care about component. # the day, as it doesn't care about component.
pull_source_pkg(('DEBSEC', 'DEBIAN'), newdsc = pull_source_pkg(('DEBSEC', 'DEBIAN'),
{'DEBSEC': opts.debsec_mirror, {'DEBSEC': opts.debsec_mirror,
'DEBIAN': opts.debian_mirror}, 'DEBIAN': opts.debian_mirror},
'main', package, version, unpack=True) 'main', package, version, unpack=True)
if opts.fetch_only: if opts.fetch_only:
sys.exit(0) sys.exit(0)
@ -96,14 +96,14 @@ def main():
Logger.error('No previous version could be found') Logger.error('No previous version could be found')
sys.exit(1) sys.exit(1)
Logger.normal('Downloading %s %s', package, oldversion) Logger.normal('Downloading %s %s', package, oldversion)
pull_source_pkg(('DEBSEC', 'DEBIAN'), olddsc = pull_source_pkg(('DEBSEC', 'DEBIAN'),
{'DEBSEC': opts.debsec_mirror, {'DEBSEC': opts.debsec_mirror,
'DEBIAN': opts.debian_mirror}, 'DEBIAN': opts.debian_mirror},
'main', package, oldversion, unpack=True) 'main', package, oldversion, unpack=True)
cmd = ('debdiff', dsc_name(package, oldversion), dsc_name(package, version)) cmd = ('debdiff', olddsc, newdsc)
Logger.command(cmd) Logger.command(cmd)
difffn = dsc_name(package, version)[:-3] + 'debdiff' difffn = newdsc[:-3] + 'debdiff'
debdiff_file = open(difffn, 'w') debdiff_file = open(difffn, 'w')
if subprocess.call(cmd, stdout=debdiff_file) > 2: if subprocess.call(cmd, stdout=debdiff_file) > 2:
Logger.error('Debdiff failed.') Logger.error('Debdiff failed.')

View File

@ -48,25 +48,29 @@ def pull_source_pkg(archives, mirrors, component, package, version, workdir='.',
assert all(x in ('DEBIAN', 'DEBSEC', 'UBUNTU') for x in archives) assert all(x in ('DEBIAN', 'DEBSEC', 'UBUNTU') for x in archives)
for archive in archives: for archive in archives:
if try_pull_from_archive(archive, mirrors.get(archive), component, filename = try_pull_from_archive(archive, mirrors.get(archive),
package, version, workdir, unpack): component, package, version,
return workdir, unpack)
if filename:
return filename
if 'DEBIAN' in archives or 'DEBSEC' in archives: if 'DEBIAN' in archives or 'DEBSEC' in archives:
Logger.info('Trying snapshot.debian.org') Logger.info('Trying snapshot.debian.org')
if try_pull_from_snapshot(package, version, workdir, unpack): filename = try_pull_from_snapshot(package, version, workdir, unpack)
return if filename:
return filename
if 'UBUNTU' in archives: if 'UBUNTU' in archives:
Logger.info('Trying Launchpad') Logger.info('Trying Launchpad')
if try_pull_from_lp(package, 'ubuntu', version, workdir, unpack): filename = try_pull_from_lp(package, 'ubuntu', version, workdir, unpack)
return if filename:
return filename
raise Exception('Unable to locate %s/%s %s' % (package, component, version)) raise Exception('Unable to locate %s/%s %s' % (package, component, version))
def try_pull_from_archive(archive, mirror, component, package, version, def try_pull_from_archive(archive, mirror, component, package, version,
workdir='.', unpack=False): workdir='.', unpack=False):
"""Download a source package from the specified source or return False. """Download a source package from the specified source, return filename.
Try mirror first, then master. Try mirror first, then master.
""" """
assert archive in ('DEBIAN', 'DEBSEC', 'UBUNTU') assert archive in ('DEBIAN', 'DEBSEC', 'UBUNTU')
@ -81,13 +85,11 @@ def try_pull_from_archive(archive, mirror, component, package, version,
Logger.command(cmd) Logger.command(cmd)
return_code = subprocess.call(cmd, cwd=workdir) return_code = subprocess.call(cmd, cwd=workdir)
if return_code == 0: if return_code == 0:
return True return os.path.basename(url)
return False
def try_pull_from_snapshot(package, version, workdir='.', unpack=False): def try_pull_from_snapshot(package, version, workdir='.', unpack=False):
"""Download Debian source package version version from snapshot.debian.org """Download Debian source package version version from snapshot.debian.org.
or return False Return filename.
""" """
try: try:
import json import json
@ -104,7 +106,7 @@ def try_pull_from_snapshot(package, version, workdir='.', unpack=False):
except urllib2.HTTPError: except urllib2.HTTPError:
Logger.error('Version %s of %s not found on snapshot.debian.org', Logger.error('Version %s of %s not found on snapshot.debian.org',
version, package) version, package)
return False return
for hash_ in srcfiles['result']: for hash_ in srcfiles['result']:
hash_ = hash_['hash'] hash_ = hash_['hash']
@ -114,12 +116,12 @@ def try_pull_from_snapshot(package, version, workdir='.', unpack=False):
'http://snapshot.debian.org/mr/file/%s/info' % hash_)) 'http://snapshot.debian.org/mr/file/%s/info' % hash_))
except urllib2.URLError: except urllib2.URLError:
Logger.error('Unable to dowload info for hash.') Logger.error('Unable to dowload info for hash.')
return False return
filename = info['result'][0]['name'] filename = info['result'][0]['name']
if '/' in filename: if '/' in filename:
Logger.error('Unacceptable file name: %s', filename) Logger.error('Unacceptable file name: %s', filename)
return False return
pathname = os.path.join(workdir, filename) pathname = os.path.join(workdir, filename)
if os.path.exists(pathname): if os.path.exists(pathname):
@ -148,23 +150,24 @@ def try_pull_from_snapshot(package, version, workdir='.', unpack=False):
out.close() out.close()
except urllib2.URLError: except urllib2.URLError:
Logger.error('Error downloading %s', filename) Logger.error('Error downloading %s', filename)
return False return
filename = dsc_name(package, version)
if unpack: if unpack:
cmd = ('dpkg-source', '--no-check', '-x', dsc_name(package, version)) cmd = ('dpkg-source', '--no-check', '-x', filename)
Logger.command(cmd) Logger.command(cmd)
subprocess.check_call(cmd) subprocess.check_call(cmd)
return True return filename
def try_pull_from_lp(package, distro, version, workdir='.', unpack=False): def try_pull_from_lp(package, distro, version, workdir='.', unpack=False):
"""Try to download the specified version of a source package from Launchpad """Try to download the specified version of a source package from Launchpad.
or return False Return filename.
""" """
filename = dsc_name(package, version)
url = ('https://launchpad.net/%s/+archive/primary/+files/%s' url = ('https://launchpad.net/%s/+archive/primary/+files/%s'
% (distro, dsc_name(package, version))) % (distro, filename))
cmd = ('dget', '-u' + ('x' if unpack else 'd'), url) cmd = ('dget', '-u' + ('x' if unpack else 'd'), url)
Logger.command(cmd) Logger.command(cmd)
return_code = subprocess.call(cmd, cwd=workdir) return_code = subprocess.call(cmd, cwd=workdir)
if return_code == 0: if return_code == 0:
return True return filename
return False