sponsor-patch: Convert style to PEP 8.

This commit is contained in:
Benjamin Drung 2010-09-19 20:45:24 +02:00
parent 5e0d815405
commit 7e26340170

View File

@ -64,7 +64,8 @@ class BugTask(object):
return os.path.join(os.getcwd(), dsc_file)
def get_branch_link(self):
return "lp:" + self.project + "/" + self.get_series() + "/" + self.package
return "lp:" + self.project + "/" + self.get_series() + "/" + \
self.package
def get_long_info(self):
return "Bug task: " + str(self.bug_task) + "\n" + \
@ -87,7 +88,8 @@ class BugTask(object):
def get_series(self, latest_release=False):
if self.series is None or latest_release:
return self.launchpad.distributions[self.project].current_series.name
dist = self.launchpad.distributions[self.project]
return dist.current_series.name
else:
return self.series
@ -117,7 +119,8 @@ class BugTask(object):
archive = dist.getArchive(name="primary")
distro_series = dist.getSeries(name_or_version=series)
published = archive.getPublishedSources(source_name=self.package,
distro_series=distro_series, status=status, exact_match=True)
distro_series=distro_series,
status=status, exact_match=True)
latest_source = None
for source in published:
@ -127,7 +130,8 @@ class BugTask(object):
return latest_source
def get_version(self):
return debian.debian_support.Version(self.get_source().source_package_version)
source_package_version = self.get_source().source_package_version
return debian.debian_support.Version(source_package_version)
def get_latest_released_version(self):
version = self.get_source(True).source_package_version
@ -148,10 +152,13 @@ class Patch(object):
def __init__(self, patch_file):
self.patch_file = patch_file
self.full_path = os.path.realpath(self.patch_file)
assert os.path.isfile(self.full_path), "%s does not exist." % (self.full_path)
assert os.path.isfile(self.full_path), "%s does not exist." % \
(self.full_path)
cmd = ["diffstat", "-l", "-p0", self.full_path]
changed_files = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
self.changed_files = filter(lambda l: l != "", changed_files.split("\n"))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
changed_files = process.communicate()[0]
self.changed_files = filter(lambda l: l != "",
changed_files.split("\n"))
def get_name(self):
return self.patch_file
@ -159,12 +166,14 @@ class Patch(object):
def get_strip_level(self):
strip_level = None
if self.is_debdiff():
changelog = filter(lambda f: f.endswith("debian/changelog"), self.changed_files)[0]
changelog = filter(lambda f: f.endswith("debian/changelog"),
self.changed_files)[0]
strip_level = len(changelog.split(os.sep)) - 2
return strip_level
def is_debdiff(self):
return len(filter(lambda f: f.endswith("debian/changelog"), self.changed_files)) > 0
return len(filter(lambda f: f.endswith("debian/changelog"),
self.changed_files)) > 0
class Print(object):
@ -284,8 +293,8 @@ def edit_source():
Print.command(cmd)
print """An interactive shell in file://%s was launched.
Edit your files. When you are done, exit the shell. If you wish to abort the
process, exit the shell such that it returns an exit code other than zero.""" % \
(os.getcwd())
process, exit the shell such that it returns an exit code other than zero.""" \
% (os.getcwd())
returncode = subprocess.call(cmd)
if returncode != 0:
Print.error("Shell exited with exit value %i." % (returncode))
@ -301,10 +310,12 @@ def get_fixed_lauchpad_bugs(changes_file):
return fixed_bugs
def strip_epoch(version):
'''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".'''
return "1.1.3-1".
"""
parts = version.full_version.split(':')
if len(parts) > 1:
@ -324,12 +335,12 @@ def get_patch_or_branch(bug):
linked_branches = map(lambda b: b.branch, bug.linked_branches)
if len(attached_patches) == 0 and len(linked_branches) == 0:
if len(bug.attachments) == 0:
Print.error("No attachment and no linked branch found on bug #%i." % \
(bug.id))
Print.error("No attachment and no linked branch found on bug #%i." \
% (bug.id))
else:
Print.error(("No attached patch and no linked branch found. Go to "
" https://launchpad.net/bugs/%i and mark an attachment as"
" patch.") % (bug.id))
"https://launchpad.net/bugs/%i and mark an attachment "
"as patch.") % (bug.id))
sys.exit(1)
elif len(attached_patches) == 1 and len(linked_branches) == 0:
patch = attached_patches[0]
@ -337,13 +348,14 @@ def get_patch_or_branch(bug):
branch = linked_branches[0].bzr_identity
else:
if len(attached_patches) == 0:
Print.normal("https://launchpad.net/bugs/%i has %i branches linked:" % \
(bug.id, len(linked_branches)))
Print.normal("https://launchpad.net/bugs/%i has %i branches "
"linked:" % (bug.id, len(linked_branches)))
elif len(linked_branches) == 0:
Print.normal("https://launchpad.net/bugs/%i has %i patches attached:" % \
(bug.id, len(attached_patches)))
Print.normal("https://launchpad.net/bugs/%i has %i patches"
" attached:" % (bug.id, len(attached_patches)))
else:
Print.normal("https://launchpad.net/bugs/%i has %i branch(es) linked and %i patch(es) attached:" % \
Print.normal("https://launchpad.net/bugs/%i has %i branch(es)"
" linked and %i patch(es) attached:" % \
(bug.id, len(linked_branches), len(attached_patches)))
i = 0
for linked_branch in linked_branches:
@ -362,8 +374,10 @@ def get_patch_or_branch(bug):
def download_patch(patch):
patch_file = re.sub(" ", "_", patch.title)
if not reduce(lambda r, x: r or patch.title.endswith(x), (".debdiff", ".diff", ".patch"), False):
Print.info("Patch %s does not have a proper file extension." % (patch.title))
if not reduce(lambda r, x: r or patch.title.endswith(x),
(".debdiff", ".diff", ".patch"), False):
Print.info("Patch %s does not have a proper file extension." % \
(patch.title))
patch_file += ".patch"
Print.info("Downloading %s." % (patch_file))
@ -405,8 +419,8 @@ def extract_source(dsc_file, verbose=False):
def apply_patch(task, patch):
edit = False
if patch.is_debdiff():
cmd = ["patch", "--merge", "--force", "-p", str(patch.get_strip_level()),
"-i", patch.full_path]
cmd = ["patch", "--merge", "--force", "-p",
str(patch.get_strip_level()), "-i", patch.full_path]
Print.command(cmd)
if subprocess.call(cmd) != 0:
Print.error("Failed to apply debdiff %s to %s %s." % \
@ -440,7 +454,8 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
workdir = os.getcwd()
script_name = os.path.basename(sys.argv[0])
launchpad = launchpadlib.launchpad.Launchpad.login_anonymously(script_name, "production")
launchpad = launchpadlib.launchpad.Launchpad.login_anonymously(script_name,
"production")
bug = launchpad.bugs[bug_number]
(patch, branch) = get_patch_or_branch(bug)
@ -462,10 +477,11 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
if len(open_ubuntu_tasks) == 1:
task = open_ubuntu_tasks[0]
else:
Print.normal("https://launchpad.net/bugs/%i has %i Ubuntu tasks:" % \
(bug_number, len(ubuntu_tasks)))
Print.normal("https://launchpad.net/bugs/%i has %i Ubuntu tasks:" \
% (bug_number, len(ubuntu_tasks)))
for i in xrange(len(ubuntu_tasks)):
print "%i) %s" % (i + 1, ubuntu_tasks[i].get_package_and_series())
print "%i) %s" % (i + 1,
ubuntu_tasks[i].get_package_and_series())
selected = input_number("To which Ubuntu tasks do the patch belong",
1, len(ubuntu_tasks))
task = ubuntu_tasks[selected - 1]
@ -515,14 +531,16 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
try:
new_version = changelog.get_version()
except IndexError:
Print.error("Debian package version could not be determined. debian/changelog is probably malformed.")
Print.error("Debian package version could not be determined. "
"debian/changelog is probably malformed.")
ask_for_manual_fixing()
continue
# Check if version of the new package is greater than the version in the archive.
# Check if version of the new package is greater than the version in
# the archive.
if new_version <= task.get_version():
Print.error("The version %s is not greater than the already available %s." % \
(new_version, task.get_version()))
Print.error("The version %s is not greater than the already "
"available %s." % (new_version, task.get_version()))
ask_for_manual_fixing()
continue
@ -538,8 +556,8 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
cmd = ['bzr', 'bd', '-S', '--', '--no-lintian']
previous_version = task.get_previous_version()
cmd.append("-v" + previous_version.full_version)
if previous_version.upstream_version == changelog.upstream_version \
and upload == "ubuntu":
if previous_version.upstream_version == changelog.upstream_version and \
upload == "ubuntu":
# FIXME: Add proper check that catches cases like changed
# compression (.tar.gz -> tar.bz2) and multiple orig source tarballs
cmd.append("-sd")
@ -561,14 +579,17 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
new_dsc_file = os.path.join(workdir,
task.package + "_" + strip_epoch(new_version) + ".dsc")
assert os.path.isfile(dsc_file), "%s does not exist." % (dsc_file)
assert os.path.isfile(new_dsc_file), "%s does not exist." % (new_dsc_file)
assert os.path.isfile(new_dsc_file),
"%s does not exist." % (new_dsc_file)
cmd = ["debdiff", dsc_file, new_dsc_file]
debdiff_file = os.path.join(workdir,
task.package + "_" + strip_epoch(new_version) + ".debdiff")
debdiff_name = task.package + "_" + strip_epoch(new_version) + \
".debdiff"
debdiff_file = os.path.join(workdir, debdiff_filename)
if not verbose:
cmd.insert(1, "-q")
Print.command(cmd + [">", debdiff_file])
debdiff = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
debdiff = process.communicate()[0]
# write debdiff file
f = open(debdiff_file, "w")
@ -592,15 +613,17 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
allowed = map(lambda s: s + "-proposed", supported_series) + \
[devel_series]
if changelog.distributions not in allowed:
Print.error("%s is not an allowed series. It needs to be one of %s." \
% (changelog.distributions, ", ".join(allowed)))
Print.error("%s is not an allowed series. It needs to be one "
"of %s." % (changelog.distributions,
", ".join(allowed)))
ask_for_manual_fixing()
continue
elif upload and upload.startwith("ppa/"):
allowed = supported_series + [devel_series]
if changelog.distributions not in allowed:
Print.error("%s is not an allowed series. It needs to be one of %s." \
% (changelog.distributions, ", ".join(allowed)))
Print.error("%s is not an allowed series. It needs to be one "
"of %s." % (changelog.distributions,
", ".join(allowed)))
ask_for_manual_fixing()
continue
@ -609,7 +632,8 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
if not os.path.isdir(buildresult):
os.makedirs(buildresult)
cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"]
architecture = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].strip()
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
architecture = process.communicate()[0].strip()
# build package
dist = re.sub("-.*$", "", changelog.distributions)
@ -626,14 +650,17 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
continue
# Check lintian
build_changes = os.path.join(buildresult, task.package + "_" + \
strip_epoch(new_version) + "_" + architecture + ".changes")
assert os.path.isfile(build_changes), "%s does not exist." % (build_changes)
changes_name = task.package + "_" + strip_epoch(new_version) + \
"_" + architecture + ".changes"
build_changes = os.path.join(buildresult, changes_name)
assert os.path.isfile(build_changes), "%s does not exist." % \
(build_changes)
cmd = ["lintian", "-IE", "--pedantic", "-q", build_changes]
lintian_file = os.path.join(workdir,
task.package + "_" + strip_epoch(new_version) + ".lintian")
Print.command(cmd + [">", lintian_file])
report = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
report = process.communicate()[0]
# write lintian report file
f = open(lintian_file, "w")
@ -643,11 +670,15 @@ def main(script_name, bug_number, build, edit, keyid, upload, verbose=False):
# Upload package
if upload:
if upload == "ubuntu":
build_log = os.path.join(buildresult, task.package + "_" + \
strip_epoch(new_version) + "_" + architecture + ".build")
print "Please check %s %s carefully:\nfile://%s\nfile://%s\nfile://%s" % \
(task.package, new_version, debdiff_file, lintian_file, build_log)
answer = yes_edit_no_question("Do you want to upload the package to the official Ubuntu archive", "yes")
build_name = task.package + "_" + strip_epoch(new_version) + \
"_" + architecture + ".build"
build_log = os.path.join(buildresult, build_name)
print "Please check %s %s carefully:\nfile://%s\nfile://%s\n"
"file://%s" % (task.package, new_version, debdiff_file,
lintian_file, build_log)
answer = yes_edit_no_question("Do you want to upload the "
"package to the official Ubuntu "
"archive", "yes")
if answer == "edit":
continue
elif answer == "no":
@ -687,14 +718,15 @@ if __name__ == "__main__":
parser.add_option("-b", "--build", help="Build the package with pbuilder.",
dest="build", action="store_true", default=False)
parser.add_option("-e", "--edit", help="launch sub-shell to allow editing of the patch",
parser.add_option("-e", "--edit",
help="launch sub-shell to allow editing of the patch",
dest="edit", action="store_true", default=False)
parser.add_option("-k", "--key", dest="keyid",
help="Specify the key ID to be used for signing.", default=None)
parser.add_option("-k", "--key", dest="keyid", default=None,
help="Specify the key ID to be used for signing.")
parser.add_option("-s", "--sponsor", help="sponsoring; equals -b -u ubuntu",
dest="sponsoring", action="store_true", default=False)
parser.add_option("-u", "--upload", dest="upload",
help="Specify an upload destination (default none).", default=None)
parser.add_option("-u", "--upload", dest="upload", default=None,
help="Specify an upload destination (default none).")
parser.add_option("-v", "--verbose", help="print more information",
dest="verbose", action="store_true", default=False)
@ -721,5 +753,3 @@ if __name__ == "__main__":
main(script_name, bug_number, options.build, options.edit, options.keyid,
options.upload, options.verbose)
# vim: set noet: