mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-28 09:11:38 +00:00
Use *SourcePackage in syncpackage
This commit is contained in:
parent
6c118ef1fe
commit
1fb2545712
179
syncpackage
179
syncpackage
@ -28,9 +28,8 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
|
||||||
import urlparse
|
|
||||||
|
|
||||||
|
from ubuntutools.archive import DebianSourcePackage, UbuntuSourcePackage
|
||||||
from ubuntutools.config import UDTConfig, ubu_email
|
from ubuntutools.config import UDTConfig, ubu_email
|
||||||
from ubuntutools.requestsync.mail import getDebianSrcPkg \
|
from ubuntutools.requestsync.mail import getDebianSrcPkg \
|
||||||
as requestsync_mail_getDebianSrcPkg
|
as requestsync_mail_getDebianSrcPkg
|
||||||
@ -38,28 +37,6 @@ from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg
|
|||||||
from ubuntutools.logger import Logger
|
from ubuntutools.logger import Logger
|
||||||
from ubuntutools.lp import udtexceptions
|
from ubuntutools.lp import udtexceptions
|
||||||
from ubuntutools.lp.lpapicache import Launchpad
|
from ubuntutools.lp.lpapicache import Launchpad
|
||||||
from ubuntutools.mirrors import pull_source_pkg
|
|
||||||
|
|
||||||
class File(object):
|
|
||||||
def __init__(self, url, checksum, size):
|
|
||||||
self.url = url
|
|
||||||
self.name = os.path.basename(url)
|
|
||||||
self.checksum = checksum
|
|
||||||
self.size = size
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.name + " (" + self.checksum + " " + self.size + \
|
|
||||||
") source " + str(bool(self.is_source_file()))
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return self.name == other.name and self.checksum == other.checksum and \
|
|
||||||
self.size == other.size
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def is_source_file(self):
|
|
||||||
return re.match(".*\.orig.*\.tar\..*", self.name)
|
|
||||||
|
|
||||||
|
|
||||||
class Version(debian.debian_support.Version):
|
class Version(debian.debian_support.Version):
|
||||||
@ -88,6 +65,7 @@ class Version(debian.debian_support.Version):
|
|||||||
def is_modified_in_ubuntu(self):
|
def is_modified_in_ubuntu(self):
|
||||||
return 'ubuntu' in self.full_version
|
return 'ubuntu' in self.full_version
|
||||||
|
|
||||||
|
|
||||||
def remove_signature(dscname):
|
def remove_signature(dscname):
|
||||||
'''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.'''
|
||||||
|
|
||||||
@ -110,24 +88,6 @@ def remove_signature(dscname):
|
|||||||
dsc_file.writelines(unsigned_file)
|
dsc_file.writelines(unsigned_file)
|
||||||
dsc_file.close()
|
dsc_file.close()
|
||||||
|
|
||||||
def dsc_getfiles(dscurl):
|
|
||||||
'''Return list of files in a .dsc file (excluding the .dsc file itself).'''
|
|
||||||
|
|
||||||
basepath = os.path.dirname(dscurl)
|
|
||||||
dsc = debian.deb822.Dsc(urllib.urlopen(dscurl))
|
|
||||||
|
|
||||||
if 'Files' not in dsc:
|
|
||||||
Logger.error('No Files field found in the dsc file. Please check %s!',
|
|
||||||
os.path.basename(dscurl))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
files = []
|
|
||||||
for source_file in dsc['Files']:
|
|
||||||
url = os.path.join(basepath, source_file['name'])
|
|
||||||
if not source_file['name'].endswith('.dsc'):
|
|
||||||
files.append(File(url, source_file['md5sum'], source_file['size']))
|
|
||||||
return files
|
|
||||||
|
|
||||||
def add_fixed_bugs(changes, bugs):
|
def add_fixed_bugs(changes, bugs):
|
||||||
'''Add additional Launchpad bugs to the list of fixed bugs in changes
|
'''Add additional Launchpad bugs to the list of fixed bugs in changes
|
||||||
file.'''
|
file.'''
|
||||||
@ -148,44 +108,26 @@ def add_fixed_bugs(changes, bugs):
|
|||||||
|
|
||||||
return "\n".join(changes + [""])
|
return "\n".join(changes + [""])
|
||||||
|
|
||||||
def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
||||||
keyid=None):
|
keyid=None):
|
||||||
assert dscname.endswith(".dsc")
|
|
||||||
assert os.path.exists(dscname)
|
|
||||||
assert '/' not in dscname
|
|
||||||
(srcpkg, new_ver) = dscname.split('_')
|
|
||||||
uploader = name + " <" + email + ">"
|
uploader = name + " <" + email + ">"
|
||||||
|
|
||||||
dscfile = debian.deb822.Dsc(file(dscname))
|
src_pkg.pull_dsc()
|
||||||
if "Version" not in dscfile:
|
new_ver = Version(src_pkg.dsc["Version"])
|
||||||
Logger.error('No Version field found in the dsc file. Please check %s!',
|
|
||||||
dscname)
|
|
||||||
sys.exit(1)
|
|
||||||
new_ver = Version(dscfile["Version"])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ubuntu_source = getUbuntuSrcPkg(srcpkg, release)
|
ubuntu_source = getUbuntuSrcPkg(src_pkg.source, release)
|
||||||
ubuntu_ver = Version(ubuntu_source.getVersion())
|
ubuntu_ver = Version(ubuntu_source.getVersion())
|
||||||
ubuntu_dsc = [f for f in ubuntu_source.sourceFileUrls()
|
ubu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_ver.full_version,
|
||||||
if f.endswith(".dsc")]
|
ubuntu_source.getComponent(),
|
||||||
assert len(ubuntu_dsc) == 1
|
mirrors=[ubuntu_mirror])
|
||||||
ubuntu_dsc = ubuntu_dsc[0]
|
ubu_pkg.pull_dsc()
|
||||||
except udtexceptions.PackageNotFoundException:
|
except udtexceptions.PackageNotFoundException:
|
||||||
ubuntu_ver = Version('~')
|
ubuntu_ver = Version('~')
|
||||||
ubuntu_dsc = None
|
ubu_pkg = None
|
||||||
|
|
||||||
Logger.debug('Source %s: current version %s, new version %s',
|
Logger.debug('Source %s: current version %s, new version %s',
|
||||||
srcpkg, ubuntu_ver, new_ver)
|
src_pkg.source, ubuntu_ver, new_ver)
|
||||||
|
|
||||||
files = dsc_getfiles(dscname)
|
|
||||||
source_files = [f for f in files if f.is_source_file()]
|
|
||||||
Logger.debug('Files: %s', str([x.get_name() for x in files]))
|
|
||||||
Logger.debug('Source files: %s', str([x.get_name() for x in source_files]))
|
|
||||||
|
|
||||||
if ubuntu_dsc is None:
|
|
||||||
ubuntu_files = None
|
|
||||||
else:
|
|
||||||
ubuntu_files = dsc_getfiles(ubuntu_dsc)
|
|
||||||
|
|
||||||
# do we need the orig.tar.gz?
|
# do we need the orig.tar.gz?
|
||||||
need_orig = True
|
need_orig = True
|
||||||
@ -193,21 +135,25 @@ def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
|||||||
if ubuntu_ver.upstream_version == new_ver.upstream_version:
|
if ubuntu_ver.upstream_version == new_ver.upstream_version:
|
||||||
# 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:
|
deb_files = dict((e['name'], e['md5sum']) for e in src_pkg.dsc['Files']
|
||||||
ubuntu_file = [f for f in ubuntu_files
|
if not e['name'].endswith('.dsc'))
|
||||||
if f.get_name() == source_file.get_name()]
|
ubu_files = dict((e['name'], e['md5sum']) for e in ubu_pkg.dsc['Files']
|
||||||
if len(ubuntu_file) == 0:
|
if not e['name'].endswith('.dsc'))
|
||||||
# The source file does not exist in Ubuntu
|
for name in deb_files.iterkeys():
|
||||||
|
if not re.match(r'.*\.orig(-[^.]+)?\.tar\.[^.]+$', name):
|
||||||
|
continue
|
||||||
|
if name in ubu_files:
|
||||||
|
if deb_files[name] != ubu_files[name]:
|
||||||
|
Logger.warn('The checksums of the file %s mismatch. '
|
||||||
|
'A fake sync is required.', name)
|
||||||
|
fakesync_files.append(name)
|
||||||
|
Logger.debug('Ubuntu version: %s', deb_files[name])
|
||||||
|
Logger.debug('Debian version: %s', ubu_files[name])
|
||||||
|
else:
|
||||||
Logger.info('%s does not exist in Ubuntu.',
|
Logger.info('%s does not exist in Ubuntu.',
|
||||||
source_file.get_name())
|
name)
|
||||||
need_orig = True
|
need_orig = True
|
||||||
elif not ubuntu_file[0] == source_file:
|
|
||||||
# The checksum of the files mismatch -> We need a fake sync
|
|
||||||
Logger.warn('The checksum of the file %s mismatch. '
|
|
||||||
'A fake sync is required.', source_file.get_name())
|
|
||||||
fakesync_files.append(ubuntu_file[0])
|
|
||||||
Logger.debug('Ubuntu version: %s', ubuntu_file[0])
|
|
||||||
Logger.debug('Debian version: %s', source_file)
|
|
||||||
Logger.debug('Needs source tarball: %s', str(need_orig))
|
Logger.debug('Needs source tarball: %s', str(need_orig))
|
||||||
|
|
||||||
cur_ver = ubuntu_ver.get_related_debian_version()
|
cur_ver = ubuntu_ver.get_related_debian_version()
|
||||||
@ -216,23 +162,16 @@ def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
|||||||
'setting current version to %s',
|
'setting current version to %s',
|
||||||
ubuntu_ver.full_version, cur_ver.full_version)
|
ubuntu_ver.full_version, cur_ver.full_version)
|
||||||
|
|
||||||
# extract package
|
src_pkg.pull()
|
||||||
cmd = ['dpkg-source', '-x', dscname]
|
src_pkg.unpack()
|
||||||
env = os.environ
|
|
||||||
env['DEB_VENDOR'] = 'Ubuntu'
|
|
||||||
if not Logger.verbose:
|
|
||||||
cmd.insert(1, "-q")
|
|
||||||
Logger.command(cmd)
|
|
||||||
subprocess.check_call(cmd, env=env)
|
|
||||||
|
|
||||||
# Do a fake sync if required
|
# Do a fake sync if required
|
||||||
if len(fakesync_files) > 0:
|
if fakesync_files:
|
||||||
# Download Ubuntu files (override Debian source tarballs)
|
# Download Ubuntu files (override Debian source tarballs)
|
||||||
pull_source_pkg('UBUNTU', ubuntu_mirror, ubuntu_source.getComponent(),
|
ubu_pkg.pull()
|
||||||
srcpkg, ubuntu_ver.full_version)
|
|
||||||
|
|
||||||
# change into package directory
|
# change into package directory
|
||||||
directory = srcpkg + '-' + new_ver.upstream_version
|
directory = src_pkg.source + '-' + new_ver.upstream_version
|
||||||
Logger.command(('cd', directory))
|
Logger.command(('cd', directory))
|
||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
|
|
||||||
@ -244,7 +183,7 @@ def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
|||||||
if len(fakesync_files) == 0:
|
if len(fakesync_files) == 0:
|
||||||
# create the changes file
|
# create the changes file
|
||||||
changes_filename = "%s_%s_source.changes" % \
|
changes_filename = "%s_%s_source.changes" % \
|
||||||
(srcpkg, new_ver.strip_epoch())
|
(src_pkg.source, new_ver.strip_epoch())
|
||||||
cmd = ["dpkg-genchanges", "-S", "-v" + cur_ver.full_version,
|
cmd = ["dpkg-genchanges", "-S", "-v" + cur_ver.full_version,
|
||||||
"-DDistribution=" + release,
|
"-DDistribution=" + release,
|
||||||
"-DOrigin=debian/" + debian_dist,
|
"-DOrigin=debian/" + debian_dist,
|
||||||
@ -256,8 +195,7 @@ def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
|||||||
if not Logger.verbose:
|
if not Logger.verbose:
|
||||||
cmd += ["-q"]
|
cmd += ["-q"]
|
||||||
Logger.command(cmd + ['>', '../' + changes_filename])
|
Logger.command(cmd + ['>', '../' + changes_filename])
|
||||||
changes = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
changes = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
|
||||||
env={"DEB_VENDOR": "Ubuntu"}).communicate()[0]
|
|
||||||
|
|
||||||
# Add additional bug numbers
|
# Add additional bug numbers
|
||||||
if len(bugs) > 0:
|
if len(bugs) > 0:
|
||||||
@ -274,7 +212,7 @@ def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
|||||||
changes_file.close()
|
changes_file.close()
|
||||||
|
|
||||||
# remove signature and sign package
|
# remove signature and sign package
|
||||||
remove_signature(dscname)
|
remove_signature(src_pkg.dsc_name)
|
||||||
if keyid is not False:
|
if keyid is not False:
|
||||||
cmd = ["debsign", changes_filename]
|
cmd = ["debsign", changes_filename]
|
||||||
if not keyid is None:
|
if not keyid is None:
|
||||||
@ -285,14 +223,15 @@ def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
|||||||
# Create fakesync changelog entry
|
# Create fakesync changelog entry
|
||||||
new_ver = Version(new_ver.full_version + "fakesync1")
|
new_ver = Version(new_ver.full_version + "fakesync1")
|
||||||
changes_filename = "%s_%s_source.changes" % \
|
changes_filename = "%s_%s_source.changes" % \
|
||||||
(srcpkg, new_ver.strip_epoch())
|
(src_pkg.source, 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(["#" + str(b) for b in bugs]))
|
(", ".join(["#" + str(b) for b in bugs]))
|
||||||
else:
|
else:
|
||||||
message = "Fake sync due to mismatching orig tarball."
|
message = "Fake sync due to mismatching orig tarball."
|
||||||
cmd = ["dch", "-v", new_ver.full_version, "-D", release, message]
|
cmd = ['dch', '-v', new_ver.full_version, '--force-distribution',
|
||||||
env = {"DEBFULLNAME": name, "DEBEMAIL": email}
|
'-D', release, message]
|
||||||
|
env = {'DEBFULLNAME': name, 'DEBEMAIL': email}
|
||||||
Logger.command(cmd)
|
Logger.command(cmd)
|
||||||
subprocess.check_call(cmd, env=env)
|
subprocess.check_call(cmd, env=env)
|
||||||
|
|
||||||
@ -305,14 +244,12 @@ def sync_dsc(dscname, debian_dist, release, name, email, bugs, ubuntu_mirror,
|
|||||||
|
|
||||||
# Build source package
|
# Build source package
|
||||||
cmd = ["debuild", "--no-lintian", "-S", "-v" + cur_ver.full_version]
|
cmd = ["debuild", "--no-lintian", "-S", "-v" + cur_ver.full_version]
|
||||||
env = os.environ
|
|
||||||
env['DEB_VENDOR'] = 'Ubuntu'
|
|
||||||
if need_orig:
|
if need_orig:
|
||||||
cmd += ['-sa']
|
cmd += ['-sa']
|
||||||
if keyid:
|
if keyid:
|
||||||
cmd += ["-k" + keyid]
|
cmd += ["-k" + keyid]
|
||||||
Logger.command(cmd)
|
Logger.command(cmd)
|
||||||
returncode = subprocess.call(cmd, env=env)
|
returncode = subprocess.call(cmd)
|
||||||
if returncode != 0:
|
if returncode != 0:
|
||||||
Logger.error('Source-only build with debuild failed. '
|
Logger.error('Source-only build with debuild failed. '
|
||||||
'Please check build log above.')
|
'Please check build log above.')
|
||||||
@ -322,6 +259,9 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror):
|
|||||||
"""Download the specified source package.
|
"""Download the specified source package.
|
||||||
dist, version, component, mirror can all be None.
|
dist, version, component, mirror can all be None.
|
||||||
"""
|
"""
|
||||||
|
if package.endswith('.dsc'):
|
||||||
|
return DebianSourcePackage(dscfile=package, mirrors=[mirror])
|
||||||
|
|
||||||
if dist is None:
|
if dist is None:
|
||||||
dist = "unstable"
|
dist = "unstable"
|
||||||
requested_version = version
|
requested_version = version
|
||||||
@ -352,18 +292,8 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror):
|
|||||||
|
|
||||||
assert component in ('main', 'contrib', 'non-free')
|
assert component in ('main', 'contrib', 'non-free')
|
||||||
|
|
||||||
return pull_source_pkg('DEBIAN', mirror, component, package,
|
return DebianSourcePackage(package, version.full_version, component,
|
||||||
version.full_version)
|
mirrors=[mirror])
|
||||||
|
|
||||||
def fetch_dsc(dscfile):
|
|
||||||
"Fetch a dsc"
|
|
||||||
url = urlparse.urlparse(dscfile)
|
|
||||||
if not url.scheme:
|
|
||||||
dscfile = 'file://' + os.path.abspath(dscfile)
|
|
||||||
cmd = ('dget', '--allow-unauthenticated', '-d', dscfile)
|
|
||||||
Logger.command(cmd)
|
|
||||||
subprocess.check_call(cmd)
|
|
||||||
return os.path.basename(url.path)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
usage = "%prog [options] <.dsc URL/path or package name>"
|
usage = "%prog [options] <.dsc URL/path or package name>"
|
||||||
@ -450,16 +380,13 @@ def main():
|
|||||||
if options.release is None:
|
if options.release is None:
|
||||||
options.release = Launchpad.distributions["ubuntu"].current_series.name
|
options.release = Launchpad.distributions["ubuntu"].current_series.name
|
||||||
|
|
||||||
if args[0].endswith(".dsc"):
|
os.environ['DEB_VENDOR'] = 'Ubuntu'
|
||||||
dscfile = args[0]
|
|
||||||
if '/' in dscfile:
|
|
||||||
dscfile = fetch_dsc(dscfile)
|
|
||||||
else:
|
|
||||||
dscfile = fetch_source_pkg(args[0], options.dist, options.debversion,
|
|
||||||
options.component, options.release,
|
|
||||||
options.debian_mirror)
|
|
||||||
|
|
||||||
sync_dsc(dscfile, options.dist, options.release, options.uploader_name,
|
src_pkg = fetch_source_pkg(args[0], options.dist, options.debversion,
|
||||||
|
options.component, options.release,
|
||||||
|
options.debian_mirror)
|
||||||
|
|
||||||
|
sync_dsc(src_pkg, options.dist, options.release, options.uploader_name,
|
||||||
options.uploader_email, options.bugs, options.ubuntu_mirror,
|
options.uploader_email, options.bugs, options.ubuntu_mirror,
|
||||||
options.keyid)
|
options.keyid)
|
||||||
|
|
||||||
|
@ -13,3 +13,8 @@ max-line-length=80
|
|||||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||||
# tab).
|
# tab).
|
||||||
indent-string=' '
|
indent-string=' '
|
||||||
|
|
||||||
|
[BASIC]
|
||||||
|
|
||||||
|
# Allow variables called e, f, lp
|
||||||
|
good-names=i,j,k,ex,Run,_,e,f,lp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user