syncpackage: Use Version class from python-debian to fix extraction of

upstream version for debian versions that contain more than one dash.
This commit is contained in:
Benjamin Drung 2010-07-30 00:58:26 +02:00
parent 309bf6d2a3
commit 71c25ec898
2 changed files with 48 additions and 57 deletions

6
debian/changelog vendored
View File

@ -13,8 +13,8 @@ ubuntu-dev-tools (0.101) UNRELEASED; urgency=low
[ Benjamin Drung ] [ Benjamin Drung ]
* Bump Standards-Version to 3.9.1 (no changes required). * Bump Standards-Version to 3.9.1 (no changes required).
* Switch to dpkg-source 3.0 (native) format. * Switch to dpkg-source 3.0 (native) format.
* syncpackage: Fix extraction of upstream version for debian versions that * syncpackage: Use Version class from python-debian to fix extraction of
contain more than one dash. upstream version for debian versions that contain more than one dash.
[ Michael Bienia ] [ Michael Bienia ]
* ubuntutools/lpapi/lpapicache.py: Use the new LP API method * ubuntutools/lpapi/lpapicache.py: Use the new LP API method
@ -24,7 +24,7 @@ ubuntu-dev-tools (0.101) UNRELEASED; urgency=low
* requestsync: Fix bug where the variable 'hasLP' is not always set * requestsync: Fix bug where the variable 'hasLP' is not always set
(lp: #607874). (lp: #607874).
-- Benjamin Drung <bdrung@ubuntu.com> Wed, 28 Jul 2010 16:23:58 +0200 -- Benjamin Drung <bdrung@ubuntu.com> Fri, 30 Jul 2010 00:44:55 +0200
ubuntu-dev-tools (0.100) maverick; urgency=low ubuntu-dev-tools (0.100) maverick; urgency=low

View File

@ -19,7 +19,7 @@
# #
# ################################################################## # ##################################################################
import apt_pkg import debian.debian_support
import hashlib import hashlib
import optparse import optparse
import os import os
@ -75,17 +75,31 @@ class File(object):
urllib.urlretrieve(self.url, self.name) urllib.urlretrieve(self.url, self.name)
def strip_epoch(version): class Version(debian.debian_support.Version):
def strip_epoch(self):
'''Removes the epoch from a Debian version string. '''Removes the epoch from a Debian version string.
strip_epoch(1:1.52-1) will return "1.52-1" and strip_epoch(1.1.3-1) will strip_epoch(1:1.52-1) will return "1.52-1" and strip_epoch(1.1.3-1) will
return "1.1.3-1".''' return "1.1.3-1".'''
parts = version.split(':') parts = self.full_version.split(':')
if len(parts) > 1: if len(parts) > 1:
del parts[0] del parts[0]
version = ':'.join(parts) version_without_epoch = ':'.join(parts)
return version return version_without_epoch
def get_related_debian_version(self):
related_debian_version = self.full_version
uidx = related_debian_version.find('ubuntu')
if uidx > 0:
related_debian_version = related_debian_version[:uidx]
uidx = related_debian_version.find('build')
if uidx > 0:
related_debian_version = related_debian_version[:uidx]
return Version(related_debian_version)
def is_modified_in_ubuntu(self):
return self.full_version.find('ubuntu') > 0
def remove_signature(dscname, verbose=False): def remove_signature(dscname, verbose=False):
'''Removes the signature from a .dsc file if the .dsc file is signed.''' '''Removes the signature from a .dsc file if the .dsc file is signed.'''
@ -151,21 +165,6 @@ def add_fixed_bugs(changes, bugs, verbose=False):
return "\n".join(changes + [""]) return "\n".join(changes + [""])
def extract_upstream_version(debian_version):
# remove last part separated by a dash (1.0-2 -> 1.0)
parts = debian_version.split('-')
if len(parts) > 1:
del parts[-1]
upstream_version = '-'.join(parts)
# remove epoch
parts = upstream_version.split(':')
if len(parts) > 1:
del parts[0]
upstream_version = ':'.join(parts)
return upstream_version
def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbose=False): def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbose=False):
assert dscurl.endswith(".dsc") assert dscurl.endswith(".dsc")
dscname = os.path.basename(dscurl) dscname = os.path.basename(dscurl)
@ -178,21 +177,20 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
else: else:
urllib.urlretrieve(dscurl, dscname) urllib.urlretrieve(dscurl, dscname)
dscfile = open(dscname).readlines() dscfile = open(dscname).readlines()
new_ver = filter(lambda l: l.startswith("Version:"), dscfile)[0][8:].strip() new_ver = Version(filter(lambda l: l.startswith("Version:"), dscfile)[0][8:].strip())
try: try:
ubuntu_source = getUbuntuSrcPkg(srcpkg, release) ubuntu_source = getUbuntuSrcPkg(srcpkg, release)
ubuntu_ver = ubuntu_source.getVersion() ubuntu_ver = Version(ubuntu_source.getVersion())
ubuntu_dsc = filter(lambda f: f.endswith(".dsc"), ubuntu_source.sourceFileUrls()) ubuntu_dsc = filter(lambda f: f.endswith(".dsc"), ubuntu_source.sourceFileUrls())
assert len(ubuntu_dsc) == 1 assert len(ubuntu_dsc) == 1
ubuntu_dsc = ubuntu_dsc[0] ubuntu_dsc = ubuntu_dsc[0]
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_ver = '~' ubuntu_ver = Version('~')
ubuntu_dsc = None ubuntu_dsc = None
# No need to continue if version is not greater than current one # No need to continue if version is not greater than current one
apt_pkg.init() if new_ver <= ubuntu_ver:
if not apt_pkg.check_dep(new_ver, '>', ubuntu_ver):
raise Exception('%s version %s is not greater than already available %s' % (srcpkg, new_ver, ubuntu_ver)) raise Exception('%s version %s is not greater than already available %s' % (srcpkg, new_ver, ubuntu_ver))
if verbose: if verbose:
print 'Source %s: current version %s, new version %s' % (srcpkg, ubuntu_ver, new_ver) print 'Source %s: current version %s, new version %s' % (srcpkg, ubuntu_ver, new_ver)
@ -212,8 +210,7 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
# do we need the orig.tar.gz? # do we need the orig.tar.gz?
need_orig = True need_orig = True
fakesync_files = [] fakesync_files = []
if ubuntu_ver.find('-') > 0 and new_ver.find('-') > 0 and \ if ubuntu_ver.upstream_version == new_ver.upstream_version:
ubuntu_ver.split('-')[0] == new_ver.split('-')[0]:
# We need to check if all .orig*.tar.* tarballs exist in Ubuntu # We need to check if all .orig*.tar.* tarballs exist in Ubuntu
need_orig = False need_orig = False
for source_file in source_files: for source_file in source_files:
@ -233,16 +230,9 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
if verbose: if verbose:
print 'needs orig.tar.gz', need_orig print 'needs orig.tar.gz', need_orig
uidx = ubuntu_ver.find('ubuntu') if ubuntu_ver.is_modified_in_ubuntu():
if uidx > 0:
cur_ver = ubuntu_ver[:uidx]
print 'WARNING! Overwriting modified Ubuntu version %s, setting current version to %s' % (ubuntu_ver, cur_ver) print 'WARNING! Overwriting modified Ubuntu version %s, setting current version to %s' % (ubuntu_ver, cur_ver)
else: cur_ver = ubuntu_ver.get_related_debian_version()
cur_ver = ubuntu_ver
uidx = cur_ver.find('build')
if uidx > 0:
cur_ver = cur_ver[:uidx]
# extract package # extract package
subprocess.check_call(['dpkg-source', '-x', dscname]) subprocess.check_call(['dpkg-source', '-x', dscname])
@ -253,7 +243,7 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
map(lambda f: f.download(verbose), fakesync_files) map(lambda f: f.download(verbose), fakesync_files)
# change into package directory # change into package directory
directory = srcpkg + '-' + extract_upstream_version(new_ver) directory = srcpkg + '-' + new_ver.upstream_version
if verbose: if verbose:
print "cd " + directory print "cd " + directory
os.chdir(directory) os.chdir(directory)
@ -265,8 +255,8 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
if len(fakesync_files) == 0: if len(fakesync_files) == 0:
# create the changes file # create the changes file
changes_file = "%s_%s_source.changes" % (srcpkg, strip_epoch(new_ver)) changes_file = "%s_%s_source.changes" % (srcpkg, new_ver.strip_epoch())
cmd = ["dpkg-genchanges", "-S", "-v" + cur_ver, cmd = ["dpkg-genchanges", "-S", "-v" + cur_ver.full_version,
"-DDistribution=" + release, "-DDistribution=" + release,
"-DOrigin=debian/" + debian_dist, "-DOrigin=debian/" + debian_dist,
"-e" + uploader] "-e" + uploader]
@ -301,14 +291,14 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
subprocess.check_call(cmd) subprocess.check_call(cmd)
else: else:
# Create fakesync changelog entry # Create fakesync changelog entry
new_ver += "fakesync1" new_ver = Version(new_version.full_version + "fakesync1")
changes_file = "%s_%s_source.changes" % (srcpkg, strip_epoch(new_ver)) changes_file = "%s_%s_source.changes" % (srcpkg, new_ver.strip_epoch())
if len(bugs) > 0: if len(bugs) > 0:
message = "Fake sync due to mismatching orig tarball (LP: %s)." % \ message = "Fake sync due to mismatching orig tarball (LP: %s)." % \
(", ".join(map(lambda b: "#" + str(b), bugs))) (", ".join(map(lambda b: "#" + str(b), bugs)))
else: else:
message = "Fake sync due to mismatching orig tarball." message = "Fake sync due to mismatching orig tarball."
cmd = ["dch", "-v", new_ver, "-D", release, message] cmd = ["dch", "-v", new_ver.full_version, "-D", release, message]
env = {"DEBFULLNAME": name, "DEBEMAIL": email} env = {"DEBFULLNAME": name, "DEBEMAIL": email}
# update the Maintainer field # update the Maintainer field
@ -316,7 +306,7 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
subprocess.check_call(["update-maintainer"]) subprocess.check_call(["update-maintainer"])
# Build source package # Build source package
cmd = ["debuild", "--no-lintian", "-S", "-v" + cur_ver] cmd = ["debuild", "--no-lintian", "-S", "-v" + cur_ver.full_version]
if need_orig: if need_orig:
cmd += ['-sa'] cmd += ['-sa']
if not keyid is None: if not keyid is None:
@ -330,20 +320,21 @@ def sync_dsc(dscurl, debian_dist, release, name, email, bugs, keyid=None, verbos
def get_debian_dscurl(package, dist, release, version=None, component=None): def get_debian_dscurl(package, dist, release, version=None, component=None):
if dist is None: if dist is None:
dist="unstable" dist="unstable"
if type(version) == str:
version = Version(version)
if version is None or component is None: if version is None or component is None:
debian_srcpkg = getDebianSrcPkg(package, dist) debian_srcpkg = getDebianSrcPkg(package, dist)
try: try:
ubuntu_version = getUbuntuSrcPkg(package, release).getVersion() ubuntu_version = Version(getUbuntuSrcPkg(package, release).getVersion())
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_version = '~' ubuntu_version = Version('~')
apt_pkg.init() if ubuntu_version >= Version(debian_srcpkg.getVersion()):
if apt_pkg.check_dep(ubuntu_version, ">=", debian_srcpkg.getVersion()):
# The LP importer is maybe out of date # The LP importer is maybe out of date
debian_srcpkg = ubuntutools_requestsync_mail_getDebianSrcPkg(package, dist) debian_srcpkg = ubuntutools_requestsync_mail_getDebianSrcPkg(package, dist)
if version is None: if version is None:
version = debian_srcpkg.getVersion() version = Version(debian_srcpkg.getVersion())
if component is None: if component is None:
component = debian_srcpkg.getComponent() component = debian_srcpkg.getComponent()
@ -354,7 +345,7 @@ def get_debian_dscurl(package, dist, release, version=None, component=None):
else: else:
group = package[0] group = package[0]
dsc_file = package + "_" + strip_epoch(version) + ".dsc" dsc_file = package + "_" + version.strip_epoch() + ".dsc"
dscurl = os.path.join("http://ftp.debian.org/debian/pool", component, group, package, dsc_file) dscurl = os.path.join("http://ftp.debian.org/debian/pool", component, group, package, dsc_file)
return dscurl return dscurl