sponsor-patch: Improve variable names.

This commit is contained in:
Benjamin Drung 2010-09-22 15:44:47 +02:00
parent 533fac4911
commit bf9b7ae3b8

View File

@ -181,34 +181,34 @@ class Print(object):
verbose = False verbose = False
@classmethod @classmethod
def command(self, cmd): def command(cls, cmd):
if self.verbose: if cls.verbose:
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))
@classmethod @classmethod
def debug(self, message): def debug(cls, message):
if self.verbose: if cls.verbose:
print "%s: D: %s" % (script_name, message) print "%s: D: %s" % (script_name, message)
@classmethod @classmethod
def error(self, message): def error(cls, message):
print >> sys.stderr, "%s: Error: %s" % (script_name, message) print >> sys.stderr, "%s: Error: %s" % (script_name, message)
@classmethod @classmethod
def info(self, message): def info(cls, message):
if self.verbose: if cls.verbose:
print "%s: I: %s" % (script_name, message) print "%s: I: %s" % (script_name, message)
@classmethod @classmethod
def normal(self, message): def normal(cls, message):
print "%s: %s" % (script_name, message) print "%s: %s" % (script_name, message)
@classmethod @classmethod
def set_verbosity(self, verbose): def set_verbosity(cls, verbose):
self.verbose = verbose cls.verbose = verbose
def get_source_package_name(bug_task): def get_source_package_name(bug_task):
@ -291,10 +291,11 @@ def edit_source():
# Spawn shell to allow modifications # Spawn shell to allow modifications
cmd = [get_user_shell()] cmd = [get_user_shell()]
Print.command(cmd) Print.command(cmd)
print """An interactive shell in file://%s was launched. print """An interactive shell was launched in
file://%s
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))
@ -373,18 +374,18 @@ def get_patch_or_branch(bug):
return (patch, branch) return (patch, branch)
def download_patch(patch): def download_patch(patch):
patch_file = re.sub(" ", "_", patch.title) patch_filename = re.sub(" ", "_", patch.title)
if not reduce(lambda r, x: r or patch.title.endswith(x), if not reduce(lambda r, x: r or patch.title.endswith(x),
(".debdiff", ".diff", ".patch"), False): (".debdiff", ".diff", ".patch"), False):
Print.info("Patch %s does not have a proper file extension." % \ Print.info("Patch %s does not have a proper file extension." % \
(patch.title)) (patch.title))
patch_file += ".patch" patch_filename += ".patch"
Print.info("Downloading %s." % (patch_file)) Print.info("Downloading %s." % (patch_filename))
f = open(patch_file, "w") patch_file = open(patch_filename, "w")
f.write(patch.data.open().read()) patch_file.write(patch.data.open().read())
f.close() patch_file.close()
return Patch(patch_file) return Patch(patch_filename)
def download_branch(branch): def download_branch(branch):
dir_name = os.path.basename(branch) dir_name = os.path.basename(branch)
@ -452,9 +453,9 @@ def main(script_name, bug_number, build, edit, keyid, upload, workdir,
if not os.path.isdir(workdir): if not os.path.isdir(workdir):
try: try:
os.makedirs(workdir) os.makedirs(workdir)
except os.error, e: except os.error, error:
Print.error("Failed to create the working directory %s " \ Print.error("Failed to create the working directory %s [Errno " \
"[Errno %i]: %s." % (workdir, e.errno, e.strerror)) "%i]: %s." % (workdir, error.errno, error.strerror))
sys.exit(1) sys.exit(1)
if workdir != os.getcwd(): if workdir != os.getcwd():
Print.command(["cd", workdir]) Print.command(["cd", workdir])
@ -591,17 +592,17 @@ def main(script_name, bug_number, build, edit, keyid, upload, workdir,
cmd = ["debdiff", dsc_file, new_dsc_file] cmd = ["debdiff", dsc_file, new_dsc_file]
debdiff_name = task.package + "_" + strip_epoch(new_version) + \ debdiff_name = task.package + "_" + strip_epoch(new_version) + \
".debdiff" ".debdiff"
debdiff_file = os.path.join(workdir, debdiff_name) debdiff_filename = os.path.join(workdir, debdiff_name)
if not verbose: if not verbose:
cmd.insert(1, "-q") cmd.insert(1, "-q")
Print.command(cmd + [">", debdiff_file]) Print.command(cmd + [">", debdiff_filename])
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
debdiff = process.communicate()[0] debdiff = process.communicate()[0]
# write debdiff file # write debdiff file
f = open(debdiff_file, "w") debdiff_file = open(debdiff_filename, "w")
f.writelines(debdiff) debdiff_file.writelines(debdiff)
f.close() debdiff_file.close()
# Make sure that the Launchpad bug will be closed # Make sure that the Launchpad bug will be closed
changes_file = new_dsc_file[:-4] + "_source.changes" changes_file = new_dsc_file[:-4] + "_source.changes"
@ -663,16 +664,16 @@ def main(script_name, bug_number, build, edit, keyid, upload, workdir,
assert os.path.isfile(build_changes), "%s does not exist." % \ assert os.path.isfile(build_changes), "%s does not exist." % \
(build_changes) (build_changes)
cmd = ["lintian", "-IE", "--pedantic", "-q", build_changes] cmd = ["lintian", "-IE", "--pedantic", "-q", build_changes]
lintian_file = os.path.join(workdir, lintian_filename = 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_filename])
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
report = process.communicate()[0] report = process.communicate()[0]
# write lintian report file # write lintian report file
f = open(lintian_file, "w") lintian_file = open(lintian_filename, "w")
f.writelines(report) lintian_file.writelines(report)
f.close() lintian_file.close()
# Upload package # Upload package
if upload: if upload:
@ -681,8 +682,9 @@ def main(script_name, bug_number, build, edit, keyid, upload, workdir,
"_" + architecture + ".build" "_" + architecture + ".build"
build_log = os.path.join(buildresult, build_name) build_log = os.path.join(buildresult, build_name)
print "Please check %s %s carefully:\nfile://%s\nfile://%s\n" \ print "Please check %s %s carefully:\nfile://%s\nfile://%s\n" \
"file://%s" % (task.package, new_version, debdiff_file, "file://%s" % (task.package, new_version,
lintian_file, build_log) debdiff_filename, lintian_filename,
build_log)
answer = yes_edit_no_question("Do you want to upload the " \ answer = yes_edit_no_question("Do you want to upload the " \
"package to the official " \ "package to the official " \
"Ubuntu archive", "yes") "Ubuntu archive", "yes")