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.builder import get_builder
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
def error(msg):
@ -200,9 +200,8 @@ def fetch_package(launchpad, mirror, workdir, package, version, source_release):
srcpkg = find_version_package(launchpad, package, version)
version = srcpkg.source_package_version
pull_source_pkg('UBUNTU', mirror, srcpkg.component_name, package, version,
workdir=workdir, unpack=False)
return dsc_name(package, version)
return pull_source_pkg('UBUNTU', mirror, srcpkg.component_name, package,
version, workdir=workdir, unpack=False)
def get_backport_version(version, suffix, upload, release):
backport_version = version + ('~%s1' % release)

View File

@ -25,7 +25,7 @@ import debian.changelog
from ubuntutools.config import UDTConfig
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):
"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
# the day, as it doesn't care about component.
pull_source_pkg(('DEBSEC', 'DEBIAN'),
{'DEBSEC': opts.debsec_mirror,
'DEBIAN': opts.debian_mirror},
'main', package, version, unpack=True)
newdsc = pull_source_pkg(('DEBSEC', 'DEBIAN'),
{'DEBSEC': opts.debsec_mirror,
'DEBIAN': opts.debian_mirror},
'main', package, version, unpack=True)
if opts.fetch_only:
sys.exit(0)
@ -96,14 +96,14 @@ def main():
Logger.error('No previous version could be found')
sys.exit(1)
Logger.normal('Downloading %s %s', package, oldversion)
pull_source_pkg(('DEBSEC', 'DEBIAN'),
{'DEBSEC': opts.debsec_mirror,
'DEBIAN': opts.debian_mirror},
'main', package, oldversion, unpack=True)
olddsc = pull_source_pkg(('DEBSEC', 'DEBIAN'),
{'DEBSEC': opts.debsec_mirror,
'DEBIAN': opts.debian_mirror},
'main', package, oldversion, unpack=True)
cmd = ('debdiff', dsc_name(package, oldversion), dsc_name(package, version))
cmd = ('debdiff', olddsc, newdsc)
Logger.command(cmd)
difffn = dsc_name(package, version)[:-3] + 'debdiff'
difffn = newdsc[:-3] + 'debdiff'
debdiff_file = open(difffn, 'w')
if subprocess.call(cmd, stdout=debdiff_file) > 2:
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)
for archive in archives:
if try_pull_from_archive(archive, mirrors.get(archive), component,
package, version, workdir, unpack):
return
filename = try_pull_from_archive(archive, mirrors.get(archive),
component, package, version,
workdir, unpack)
if filename:
return filename
if 'DEBIAN' in archives or 'DEBSEC' in archives:
Logger.info('Trying snapshot.debian.org')
if try_pull_from_snapshot(package, version, workdir, unpack):
return
filename = try_pull_from_snapshot(package, version, workdir, unpack)
if filename:
return filename
if 'UBUNTU' in archives:
Logger.info('Trying Launchpad')
if try_pull_from_lp(package, 'ubuntu', version, workdir, unpack):
return
filename = try_pull_from_lp(package, 'ubuntu', version, workdir, unpack)
if filename:
return filename
raise Exception('Unable to locate %s/%s %s' % (package, component, version))
def try_pull_from_archive(archive, mirror, component, package, version,
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.
"""
assert archive in ('DEBIAN', 'DEBSEC', 'UBUNTU')
@ -81,13 +85,11 @@ def try_pull_from_archive(archive, mirror, component, package, version,
Logger.command(cmd)
return_code = subprocess.call(cmd, cwd=workdir)
if return_code == 0:
return True
return False
return os.path.basename(url)
def try_pull_from_snapshot(package, version, workdir='.', unpack=False):
"""Download Debian source package version version from snapshot.debian.org
or return False
"""Download Debian source package version version from snapshot.debian.org.
Return filename.
"""
try:
import json
@ -104,7 +106,7 @@ def try_pull_from_snapshot(package, version, workdir='.', unpack=False):
except urllib2.HTTPError:
Logger.error('Version %s of %s not found on snapshot.debian.org',
version, package)
return False
return
for hash_ in srcfiles['result']:
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_))
except urllib2.URLError:
Logger.error('Unable to dowload info for hash.')
return False
return
filename = info['result'][0]['name']
if '/' in filename:
Logger.error('Unacceptable file name: %s', filename)
return False
return
pathname = os.path.join(workdir, filename)
if os.path.exists(pathname):
@ -148,23 +150,24 @@ def try_pull_from_snapshot(package, version, workdir='.', unpack=False):
out.close()
except urllib2.URLError:
Logger.error('Error downloading %s', filename)
return False
return
filename = dsc_name(package, version)
if unpack:
cmd = ('dpkg-source', '--no-check', '-x', dsc_name(package, version))
cmd = ('dpkg-source', '--no-check', '-x', filename)
Logger.command(cmd)
subprocess.check_call(cmd)
return True
return filename
def try_pull_from_lp(package, distro, version, workdir='.', unpack=False):
"""Try to download the specified version of a source package from Launchpad
or return False
"""Try to download the specified version of a source package from Launchpad.
Return filename.
"""
filename = dsc_name(package, version)
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)
Logger.command(cmd)
return_code = subprocess.call(cmd, cwd=workdir)
if return_code == 0:
return True
return False
return filename