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