syncpackage: Convert style to PEP 8.

This commit is contained in:
Benjamin Drung 2010-10-30 18:45:14 +02:00
parent b32dd85a63
commit b5b099424f

View File

@ -31,430 +31,446 @@ import sys
import urllib import urllib
# ubuntu-dev-tools modules # ubuntu-dev-tools modules
from ubuntutools.requestsync.mail import getDebianSrcPkg as ubuntutools_requestsync_mail_getDebianSrcPkg from ubuntutools.requestsync.mail import getDebianSrcPkg as requestsync_mail_getDebianSrcPkg
from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg
from ubuntutools.lp import udtexceptions from ubuntutools.lp import udtexceptions
from ubuntutools.lp.lpapicache import Launchpad from ubuntutools.lp.lpapicache import Launchpad
class File(object): class File(object):
def __init__(self, url, checksum, size): def __init__(self, url, checksum, size):
self.url = url self.url = url
self.name = os.path.basename(url) self.name = os.path.basename(url)
self.checksum = checksum self.checksum = checksum
self.size = size self.size = size
def __repr__(self): def __repr__(self):
return self.name + " (" + self.checksum + " " + self.size + ") source " + \ return self.name + " (" + self.checksum + " " + self.size + \
str(bool(self.is_source_file())) ") source " + str(bool(self.is_source_file()))
def __eq__(self, other): def __eq__(self, other):
return self.name == other.name and self.checksum == other.checksum and \ return self.name == other.name and self.checksum == other.checksum and \
self.size == other.size self.size == other.size
def get_name(self): def get_name(self):
return self.name return self.name
def is_source_file(self): def is_source_file(self):
return re.match(".*\.orig.*\.tar\..*", self.name) return re.match(".*\.orig.*\.tar\..*", self.name)
def download(self, script_name=None, verbose=False): def download(self, script_name=None, verbose=False):
'''Download file (by URL) to the current directory. '''Download file (by URL) to the current directory.
If the file is already present, this function does nothing.''' If the file is already present, this function does nothing.'''
file_exists = os.path.exists(self.name) file_exists = os.path.exists(self.name)
if file_exists: if file_exists:
# Check for correct checksum # Check for correct checksum
m = hashlib.md5() m = hashlib.md5()
m.update(open(self.name).read()) m.update(open(self.name).read())
file_exists = m.hexdigest() == self.checksum file_exists = m.hexdigest() == self.checksum
if not file_exists: if not file_exists:
if verbose: if verbose:
print '%s: I: Downloading %s...' % (script_name, self.url) print '%s: I: Downloading %s...' % (script_name, self.url)
try: try:
urllib.urlretrieve(self.url, self.name) urllib.urlretrieve(self.url, self.name)
except IOError as e: except IOError as e:
print >> sys.stderr, "%s: Error: Failed to download %s [Errno %i]: %s." % \ parameters = (script_name, self.name, e.errno, e.strerror)
(script_name, self.name, e.errno, e.strerror) print >> sys.stderr, ("%s: Error: Failed to download %s "
sys.exit(1) "[Errno %i]: %s.") % parameters
sys.exit(1)
class Version(debian.debian_support.Version): class Version(debian.debian_support.Version):
def strip_epoch(self): 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
return "1.1.3-1".'''
parts = self.full_version.split(':') strip_epoch(1:1.52-1) will return "1.52-1" and strip_epoch(1.1.3-1) will
if len(parts) > 1: return "1.1.3-1".'''
del parts[0]
version_without_epoch = ':'.join(parts)
return version_without_epoch
def get_related_debian_version(self): parts = self.full_version.split(':')
related_debian_version = self.full_version if len(parts) > 1:
uidx = related_debian_version.find('ubuntu') del parts[0]
if uidx > 0: version_without_epoch = ':'.join(parts)
related_debian_version = related_debian_version[:uidx] return version_without_epoch
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): def get_related_debian_version(self):
return self.full_version.find('ubuntu') > 0 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 print_command(script_name, cmd): def print_command(script_name, cmd):
for i in xrange(len(cmd)): for i in xrange(len(cmd)):
if cmd[i].find(" ") >= 0: if cmd[i].find(" ") >= 0:
cmd[i] = '"' + cmd[i] + '"' cmd[i] = '"' + cmd[i] + '"'
print "%s: I: %s" % (script_name, " ".join(cmd)) print "%s: I: %s" % (script_name, " ".join(cmd))
def remove_signature(dscname, script_name=None, verbose=False): def remove_signature(dscname, script_name=None, 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.'''
f = open(dscname) f = open(dscname)
if f.readline().strip() == "-----BEGIN PGP SIGNED MESSAGE-----": if f.readline().strip() == "-----BEGIN PGP SIGNED MESSAGE-----":
unsigned_file = [] unsigned_file = []
# search until begin of body found # search until begin of body found
for l in f: for l in f:
if l.strip() == "": if l.strip() == "":
break break
# search for end of body # search for end of body
for l in f: for l in f:
if l.strip() == "": if l.strip() == "":
break break
unsigned_file.append(l) unsigned_file.append(l)
f.close() f.close()
f = open(dscname, "w") f = open(dscname, "w")
f.writelines(unsigned_file) f.writelines(unsigned_file)
f.close() f.close()
def dsc_getfiles(dscurl): def dsc_getfiles(dscurl):
'''Return list of files in a .dsc file (excluding the .dsc file itself).''' '''Return list of files in a .dsc file (excluding the .dsc file itself).'''
basepath = os.path.dirname(dscurl) basepath = os.path.dirname(dscurl)
dsc = debian.deb822.Dsc(urllib.urlopen(dscurl)) dsc = debian.deb822.Dsc(urllib.urlopen(dscurl))
if 'Files' not in dsc: if 'Files' not in dsc:
print >> sys.stderr, "%s: Error: No Files field found in the dsc file. Please check %s!" % \ parameters = (script_name, os.path.basename(dscurl))
(script_name, os.path.basename(dscurl)) print >> sys.stderr, ("%s: Error: No Files field found in the dsc "
sys.exit(1) "file. Please check %s!") % parameters
sys.exit(1)
files = [] files = []
for f in dsc['Files']: for f in dsc['Files']:
url = os.path.join(basepath, f['name']) url = os.path.join(basepath, f['name'])
if not f['name'].endswith('.dsc'): if not f['name'].endswith('.dsc'):
files.append(File(url, f['md5sum'], f['size'])) files.append(File(url, f['md5sum'], f['size']))
return files return files
def add_fixed_bugs(changes, bugs, script_name=None, verbose=False): def add_fixed_bugs(changes, bugs, script_name=None, verbose=False):
'''Add additional Launchpad bugs to the list of fixed bugs in changes file.''' '''Add additional Launchpad bugs to the list of fixed bugs in changes file.'''
changes = filter(lambda l: l.strip() != "", changes.split("\n")) changes = filter(lambda l: l.strip() != "", changes.split("\n"))
# Remove duplicates # Remove duplicates
bugs = set(bugs) bugs = set(bugs)
for i in xrange(len(changes)): for i in xrange(len(changes)):
if changes[i].startswith("Launchpad-Bugs-Fixed:"): if changes[i].startswith("Launchpad-Bugs-Fixed:"):
bugs.update(changes[i][22:].strip().split(" ")) bugs.update(changes[i][22:].strip().split(" "))
changes[i] = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs)) changes[i] = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs))
break break
elif i == len(changes) - 1: elif i == len(changes) - 1:
# Launchpad-Bugs-Fixed entry does not exist in changes file # Launchpad-Bugs-Fixed entry does not exist in changes file
line = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs)) line = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs))
changes.append(line) changes.append(line)
return "\n".join(changes + [""]) return "\n".join(changes + [""])
def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs, keyid=None, verbose=False): def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs,
assert dscurl.endswith(".dsc") keyid=None, verbose=False):
dscname = os.path.basename(dscurl) assert dscurl.endswith(".dsc")
basepath = os.path.dirname(dscurl) dscname = os.path.basename(dscurl)
(srcpkg, new_ver) = dscname.split('_') basepath = os.path.dirname(dscurl)
uploader = name + " <" + email + ">" (srcpkg, new_ver) = dscname.split('_')
uploader = name + " <" + email + ">"
if os.path.exists(os.path.join(basepath, dscname)): if os.path.exists(os.path.join(basepath, dscname)):
dscfile = dscurl dscfile = dscurl
else: else:
try: try:
urllib.urlretrieve(dscurl, dscname) urllib.urlretrieve(dscurl, dscname)
except IOError as e: except IOError as e:
print >> sys.stderr, "%s: Error: Failed to download %s [Errno %i]: %s." % \ parameters = (script_name, dscname, e.errno, e.strerror)
(script_name, dscname, e.errno, e.strerror) print >> sys.stderr, ("%s: Error: Failed to download %s "
sys.exit(1) "[Errno %i]: %s.") % parameters
dscfile = debian.deb822.Dsc(file(dscname)) sys.exit(1)
if "Version" not in dscfile: dscfile = debian.deb822.Dsc(file(dscname))
print >> sys.stderr, "%s: Error: No Version field found in the dsc file. Please check %s!" % \ if "Version" not in dscfile:
(script_name, dscname) print >> sys.stderr, ("%s: Error: No Version field found in the dsc "
sys.exit(1) "file. Please check %s!") % (script_name, dscname)
new_ver = Version(dscfile["Version"]) sys.exit(1)
new_ver = Version(dscfile["Version"])
try: try:
ubuntu_source = getUbuntuSrcPkg(srcpkg, release) ubuntu_source = getUbuntuSrcPkg(srcpkg, release)
ubuntu_ver = Version(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"),
assert len(ubuntu_dsc) == 1 ubuntu_source.sourceFileUrls())
ubuntu_dsc = ubuntu_dsc[0] assert len(ubuntu_dsc) == 1
except udtexceptions.PackageNotFoundException: ubuntu_dsc = ubuntu_dsc[0]
ubuntu_ver = Version('~') except udtexceptions.PackageNotFoundException:
ubuntu_dsc = None ubuntu_ver = Version('~')
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
if new_ver <= ubuntu_ver: if new_ver <= ubuntu_ver:
raise Exception('%s version %s is not greater than already available %s' % \ raise Exception('%s version %s is not greater than already available '
(srcpkg, new_ver, ubuntu_ver)) '%s' % (srcpkg, new_ver, ubuntu_ver))
if verbose: if verbose:
print '%s: D: Source %s: current version %s, new version %s' % \ print '%s: D: Source %s: current version %s, new version %s' % \
(script_name, srcpkg, ubuntu_ver, new_ver) (script_name, srcpkg, ubuntu_ver, new_ver)
files = dsc_getfiles(dscurl) files = dsc_getfiles(dscurl)
source_files = filter(lambda f: f.is_source_file(), files) source_files = filter(lambda f: f.is_source_file(), files)
if verbose: if verbose:
print '%s: D: Files: %s' % (script_name, str(map(lambda x: x.get_name(), files))) print '%s: D: Files: %s' % (script_name, str(map(lambda x: x.get_name(),
print '%s: D: Source files: %s' % (script_name, str(map(lambda x: x.get_name(), source_files))) files)))
map(lambda f: f.download(verbose), files) print '%s: D: Source files: %s' % (script_name,
str(map(lambda x: x.get_name(), source_files)))
map(lambda f: f.download(verbose), files)
if ubuntu_dsc is None: if ubuntu_dsc is None:
ubuntu_files = None ubuntu_files = None
else: else:
ubuntu_files = dsc_getfiles(ubuntu_dsc) 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
fakesync_files = [] fakesync_files = []
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: for source_file in source_files:
ubuntu_file = filter(lambda f: f.get_name() == source_file.get_name(), ubuntu_files) ubuntu_file = filter(lambda f: f.get_name() == source_file.get_name(),
if len(ubuntu_file) == 0: ubuntu_files)
# The source file does not exist in Ubuntu if len(ubuntu_file) == 0:
if verbose: # The source file does not exist in Ubuntu
print "%s: I: %s does not exist in Ubuntu." % \ if verbose:
(script_name, source_file.get_name()) parameters = (script_name, source_file.get_name())
need_orig = True print "%s: I: %s does not exist in Ubuntu." % parameters
elif not ubuntu_file[0] == source_file: need_orig = True
# The checksum of the files mismatch -> We need a fake sync elif not ubuntu_file[0] == source_file:
print "%s: Warning: The checksum of the file %s mismatch. A fake sync is required." % \ # The checksum of the files mismatch -> We need a fake sync
(script_name, source_file.get_name()) parameters = (script_name, source_file.get_name())
fakesync_files.append(ubuntu_file[0]) print ("%s: Warning: The checksum of the file %s mismatch. "
if verbose: "A fake sync is required.") % parameters
print "%s: D: Ubuntu version: %s" % (script_name, ubuntu_file[0]) fakesync_files.append(ubuntu_file[0])
print "%s: D: Debian version: %s" % (script_name, source_file) if verbose:
if verbose: print "%s: D: Ubuntu version: %s" % (script_name,
print '%s: D: needs source tarball: %s' % (script_name, str(need_orig)) ubuntu_file[0])
print "%s: D: Debian version: %s" % (script_name,
source_file)
if verbose:
print '%s: D: needs source tarball: %s' % (script_name, str(need_orig))
cur_ver = ubuntu_ver.get_related_debian_version() cur_ver = ubuntu_ver.get_related_debian_version()
if ubuntu_ver.is_modified_in_ubuntu(): if ubuntu_ver.is_modified_in_ubuntu():
print '%s: Warning: Overwriting modified Ubuntu version %s, setting current version to %s' % \ params = (script_name, ubuntu_ver.full_version, cur_ver.full_version)
(script_name, ubuntu_ver.full_version, cur_ver.full_version) print ('%s: Warning: Overwriting modified Ubuntu version %s, '
'setting current version to %s') % params
# extract package # extract package
cmd = ['dpkg-source', '-x', dscname] cmd = ['dpkg-source', '-x', dscname]
if not verbose: if not verbose:
cmd.insert(1, "-q") cmd.insert(1, "-q")
if verbose: if verbose:
print_command(script_name, cmd) print_command(script_name, cmd)
subprocess.check_call(cmd) subprocess.check_call(cmd)
# Do a fake sync if required # Do a fake sync if required
if len(fakesync_files) > 0: if len(fakesync_files) > 0:
# Download Ubuntu files (override Debian source tarballs) # Download Ubuntu files (override Debian source tarballs)
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 + '-' + new_ver.upstream_version directory = srcpkg + '-' + new_ver.upstream_version
if verbose: if verbose:
print_command(script_name, ["cd", directory]) print_command(script_name, ["cd", directory])
os.chdir(directory) os.chdir(directory)
# read Debian distribution from debian/changelog if not specified # read Debian distribution from debian/changelog if not specified
if debian_dist is None: if debian_dist is None:
line = open("debian/changelog").readline() line = open("debian/changelog").readline()
debian_dist = line.split(" ")[2].strip(";") debian_dist = line.split(" ")[2].strip(";")
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, new_ver.strip_epoch()) changes_file = "%s_%s_source.changes" % (srcpkg, 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,
"-e" + uploader] "-e" + uploader]
if need_orig: if need_orig:
cmd.append("-sa") cmd.append("-sa")
else: else:
cmd.append("-sd") cmd.append("-sd")
if not verbose: if not verbose:
cmd += ["-q"] cmd += ["-q"]
if verbose: if verbose:
print_command(script_name, cmd + [">", "../" + changes_file]) print_command(script_name, cmd + [">", "../" + changes_file])
changes = subprocess.Popen(cmd, stdout=subprocess.PIPE, changes = subprocess.Popen(cmd, stdout=subprocess.PIPE,
env={"DEB_VENDOR": "Ubuntu"}).communicate()[0] env={"DEB_VENDOR": "Ubuntu"}).communicate()[0]
# Add additional bug numbers # Add additional bug numbers
if len(bugs) > 0: if len(bugs) > 0:
changes = add_fixed_bugs(changes, bugs, verbose) changes = add_fixed_bugs(changes, bugs, verbose)
# remove extracted (temporary) files # remove extracted (temporary) files
if verbose: if verbose:
print_command(script_name, ["cd", ".."]) print_command(script_name, ["cd", ".."])
os.chdir('..') os.chdir('..')
shutil.rmtree(directory, True) shutil.rmtree(directory, True)
# write changes file # write changes file
f = open(changes_file, "w") f = open(changes_file, "w")
f.writelines(changes) f.writelines(changes)
f.close() f.close()
# remove signature and sign package # remove signature and sign package
remove_signature(dscname) remove_signature(dscname)
if keyid is not False: if keyid is not False:
cmd = ["debsign", changes_file] cmd = ["debsign", changes_file]
if not keyid is None: if not keyid is None:
cmd.insert(1, "-k" + keyid) cmd.insert(1, "-k" + keyid)
if verbose: if verbose:
print_command(script_name, cmd) print_command(script_name, cmd)
subprocess.check_call(cmd) subprocess.check_call(cmd)
else: else:
# 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_file = "%s_%s_source.changes" % (srcpkg, new_ver.strip_epoch()) 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.full_version, "-D", release, message] cmd = ["dch", "-v", new_ver.full_version, "-D", release, message]
env = {"DEBFULLNAME": name, "DEBEMAIL": email} env = {"DEBFULLNAME": name, "DEBEMAIL": email}
if verbose: if verbose:
print_command(script_name, cmd) print_command(script_name, cmd)
subprocess.check_call(cmd, env=env) subprocess.check_call(cmd, env=env)
# update the Maintainer field # update the Maintainer field
cmd = ["update-maintainer"] cmd = ["update-maintainer"]
if not verbose: if not verbose:
cmd.append("-q") cmd.append("-q")
if verbose: if verbose:
print_command(script_name, cmd) print_command(script_name, cmd)
subprocess.check_call(cmd) subprocess.check_call(cmd)
# 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 = os.environ
env['DEB_VENDOR'] = 'Ubuntu' env['DEB_VENDOR'] = 'Ubuntu'
if need_orig: if need_orig:
cmd += ['-sa'] cmd += ['-sa']
if keyid: if keyid:
cmd += ["-k" + keyid] cmd += ["-k" + keyid]
if verbose: if verbose:
print_command(script_name, cmd) print_command(script_name, cmd)
subprocess.check_call(cmd, env=env) subprocess.check_call(cmd, env=env)
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: if type(version) == str:
version = Version(version) 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 = Version(getUbuntuSrcPkg(package, release).getVersion()) ubuntu_version = Version(getUbuntuSrcPkg(package, release).getVersion())
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_version = Version('~') ubuntu_version = Version('~')
if ubuntu_version >= Version(debian_srcpkg.getVersion()): if ubuntu_version >= 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 = requestsync_mail_getDebianSrcPkg(package, dist)
if version is None: if version is None:
version = 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()
assert component in ("main", "contrib", "non-free") assert component in ("main", "contrib", "non-free")
if package.startswith("lib"): if package.startswith("lib"):
group = package[0:4] group = package[0:4]
else: else:
group = package[0] group = package[0]
dsc_file = package + "_" + version.strip_epoch() + ".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,
return dscurl package, dsc_file)
return dscurl
if __name__ == "__main__": if __name__ == "__main__":
script_name = os.path.basename(sys.argv[0]) script_name = os.path.basename(sys.argv[0])
usage = "%s [options] <.dsc URL/path or package name>" % (script_name) usage = "%s [options] <.dsc URL/path or package name>" % (script_name)
epilog = "See %s(1) for more info." % (script_name) epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog) parser = optparse.OptionParser(usage=usage, epilog=epilog)
parser.add_option("-d", "--distribution", type = "string", parser.add_option("-d", "--distribution", type="string",
dest = "dist", default = None, dest="dist", default=None,
help = "Debian distribution to sync from.") help="Debian distribution to sync from.")
parser.add_option("-r", "--release", parser.add_option("-r", "--release", dest="release", default=None,
help="Specify target Ubuntu release.", dest="release", default=None) help="Specify target Ubuntu release.")
parser.add_option("-V", "--debian-version", parser.add_option("-V", "--debian-version", dest="debversion", default=None,
help="Specify the version to sync from.", dest="debversion", default=None) help="Specify the version to sync from.")
parser.add_option("-c", "--component", parser.add_option("-c", "--component", dest="component", default=None,
help="Specify the Debian component to sync from.", dest="component", default=None) help="Specify the Debian component to sync from.")
parser.add_option("-v", "--verbose", help="print more information", parser.add_option("-v", "--verbose", help="print more information",
dest="verbose", action="store_true", default=False) dest="verbose", action="store_true", default=False)
parser.add_option("-n", "--uploader-name", dest="uploader_name", parser.add_option("-n", "--uploader-name", dest="uploader_name",
help="Use UPLOADER_NAME as the name of the maintainer " help="Use UPLOADER_NAME as the name of the maintainer "
"for this upload instead of evaluating DEBFULLNAME.", "for this upload instead of evaluating DEBFULLNAME.",
default = os.environ["DEBFULLNAME"]) default=os.environ["DEBFULLNAME"])
parser.add_option("-e", "--uploader-email", dest="uploader_email", parser.add_option("-e", "--uploader-email", dest="uploader_email",
help="Use UPLOADER_EMAIL as email address of the maintainer " help="Use UPLOADER_EMAIL as email address of the "
"for this upload instead of evaluating DEBEMAIL.", "maintainer for this upload instead of evaluating "
default = os.environ["DEBEMAIL"]) "DEBEMAIL.", default=os.environ["DEBEMAIL"])
parser.add_option("-k", "--key", dest="keyid", parser.add_option("-k", "--key", dest="keyid", default=None,
help="Specify the key ID to be used for signing.", default=None) help="Specify the key ID to be used for signing.")
parser.add_option('--dont-sign', dest='keyid', action='store_false', parser.add_option('--dont-sign', dest='keyid', action='store_false',
help='Do not sign the upload') help='Do not sign the upload')
parser.add_option("-b", "--bug", metavar="BUG", parser.add_option("-b", "--bug", metavar="BUG",
help="Mark a Launchpad bug as being fixed by this upload", help="Mark a Launchpad bug as being fixed by this upload",
dest="bugs", action="append", default=list()) dest="bugs", action="append", default=list())
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) == 0: if len(args) == 0:
print >> sys.stderr, "%s: Error: No .dsc URL/path or package name specified." % \ print >> sys.stderr, ("%s: Error: No .dsc URL/path or package name "
(script_name) "specified.") % (script_name)
sys.exit(1) sys.exit(1)
elif len(args) > 1: elif len(args) > 1:
print >> sys.stderr, "%s: Error: Multiple .dsc URLs/paths or package names specified: %s" % \ parameters = (script_name, ", ".join(args))
(script_name, ", ".join(args)) print >> sys.stderr, ("%s: Error: Multiple .dsc URLs/paths or "
sys.exit(1) "package names specified: %s") % parameters
sys.exit(1)
invalid_bug_numbers = filter(lambda x: not x.isdigit(), options.bugs) invalid_bug_numbers = filter(lambda x: not x.isdigit(), options.bugs)
if len(invalid_bug_numbers) > 0: if len(invalid_bug_numbers) > 0:
print >> sys.stderr, "%s: Error: Invalid bug number(s) specified: %s" % \ print >> sys.stderr, "%s: Error: Invalid bug number(s) specified: %s" \
(script_name, ", ".join(invalid_bug_numbers)) % (script_name, ", ".join(invalid_bug_numbers))
sys.exit(1) sys.exit(1)
Launchpad.login_anonymously() Launchpad.login_anonymously()
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"): if args[0].endswith(".dsc"):
dscurl = args[0] dscurl = args[0]
else: else:
if options.component not in (None, "main", "contrib", "non-free"): if options.component not in (None, "main", "contrib", "non-free"):
print >> sys.stderr, "%s: Error: %s is not a valid Debian component." \ parameters = (script_name, options.component)
" It should be one of main, contrib, or non-free." % \ print >> sys.stderr, ("%s: Error: %s is not a valid Debian "
(script_name, options.component) "component. It should be one of main, "
sys.exit(1) "contrib, or non-free.") % parameters
dscurl = get_debian_dscurl(args[0], options.dist, options.release, sys.exit(1)
options.debversion, options.component) dscurl = get_debian_dscurl(args[0], options.dist, options.release,
options.debversion, options.component)
if options.verbose: if options.verbose:
print "%s: D: .dsc url: %s" % (script_name, dscurl) print "%s: D: .dsc url: %s" % (script_name, dscurl)
sync_dsc(script_name, dscurl, options.dist, options.release, options.uploader_name, sync_dsc(script_name, dscurl, options.dist, options.release,
options.uploader_email, options.bugs, options.keyid, options.verbose) options.uploader_name, options.uploader_email, options.bugs,
options.keyid, options.verbose)