From 470a552270c8fdd3108bf6e494b4e82bf71c8c1d Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 13 Feb 2014 11:22:06 +0100 Subject: [PATCH] gentoo_build: Clean up pep8 warnings. --- gentoo_build | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/gentoo_build b/gentoo_build index 3ef2735..139959a 100755 --- a/gentoo_build +++ b/gentoo_build @@ -73,6 +73,7 @@ Auto increment/decrement substitition variables: built """ + class Ebuild(object): """This class represents an .ebuild file.""" @@ -178,14 +179,14 @@ class Ebuild(object): "exactly one!".format(n=n_subs)) def set_version(self, version): - """Specify the version of the ebuild file.""" + """Specify the version of the ebuild file.""" self.version = debian2gentoo_version(version) self.logger.info('Set version of {name} ebuild to ' '"{version}".'.format(name=self.name, version=self.version)) -class MyOptionParser(optparse.OptionParser): # pylint: disable=R0904 +class MyOptionParser(optparse.OptionParser): # pylint: disable=R0904 """Derive the OptionParser class to override the format_epilog method""" def format_epilog(self, formatter): @@ -216,7 +217,7 @@ def version_substitution(logger, pattern, git_commit=None): subst['debupstream'] = changelog.upstream_version subst['debversion'] = changelog.full_version try: - version = pattern.format(**subst) # pylint: disable=W0142 + version = pattern.format(**subst) # pylint: disable=W0142 except KeyError as error: key = error.args[0] allowed_keys = ["{debupstream}", "{debversion}", "{git-commit}", @@ -234,14 +235,16 @@ def version_substitution(logger, pattern, git_commit=None): sys.exit(1) return version + def debian2gentoo_version(debian_version): """Translate a Debian version into a Gentoo version. - + We just replace dashes and pluses (from the Debian revision) by points. More suffisticated version mapping from Gentoo to Debian is not done. """ return debian_version.replace("-", ".") + def re_subn(pattern, repl, string, count=0, flags=0): """Implement multi-line string replacement. This function is a work-around for the missing flags parameter @@ -258,6 +261,7 @@ def re_subn(pattern, repl, string, count=0, flags=0): else: return re.subn(pattern, repl, string, count, flags) + def main(): """Read command-line parameters and needed environment variables.""" script_name = os.path.basename(sys.argv[0]) @@ -299,11 +303,11 @@ def main(): parser.add_option("--chroot", dest="chroot_name", default=env[ENV_CHROOT], help="chroot to use for calling ebuild (default: " - "{default})".format(default = DEFAULT_CHROOT_NAME)) + "{default})".format(default=DEFAULT_CHROOT_NAME)) parser.add_option("--chroot-user", dest="chroot_user", default=env[ENV_CHROOT_USER], help="chroot user to use for calling ebuild (default: " - "{default})".format(default = DEFAULT_CHROOT_USER)) + "{default})".format(default=DEFAULT_CHROOT_USER)) parser.add_option("-d", "--directory", dest="directory", help="change to the specified directory") parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true", @@ -347,6 +351,7 @@ def main(): gentoo_build(script_name, logger, release_repo, options) + def shell_env(): """Return all environment variables in a format that can be parsed by a shell again.""" @@ -355,6 +360,7 @@ def shell_env(): env += '{key}="{value}"\n'.format(key=key, value=value) return env + def gentoo_build(script_name, logger, release_repo_uri, options): """Main function that creates a versioned ebuild file and releases it.""" ebuilds = find_ebuilds(logger, options.category) @@ -373,7 +379,7 @@ def gentoo_build(script_name, logger, release_repo_uri, options): ebuild.set_version(git_tag) ebuild.set_git_commit(git_tag) ebuild.modify_keywords(options.keywords) - tmpdir = tempfile.mkdtemp(prefix=script_name+".") + tmpdir = tempfile.mkdtemp(prefix=script_name + ".") try: # Checkout release repository branch = get_release_repo_branch(logger, options, repo) @@ -389,7 +395,7 @@ def gentoo_build(script_name, logger, release_repo_uri, options): tmpdir, ebuild.get_relpath()) release_repo.git.add("-A") release_repo.git.commit("-m", "Added " + ebuild.get_relpath()) - logger.info("Added following commit:\n" + \ + logger.info("Added following commit:\n" + release_repo.git.log("-p", "--stat", "HEAD~1..HEAD")) # Push changes to the release repository if options.dry_run: @@ -409,6 +415,7 @@ def gentoo_build(script_name, logger, release_repo_uri, options): else: shutil.rmtree(tmpdir) + def get_release_repo_branch(logger, options, repo): """Return the branch to use for the release repo.""" branch = options.release_branch @@ -425,6 +432,7 @@ def get_release_repo_branch(logger, options, repo): sys.exit(1) return branch + def update_manifest(logger, chroot_name, chroot_user, workdir, ebuild_path): """Update manifest file in a Gentoo chroot.""" cmd = ["schroot", "-c", chroot_name, "-u", chroot_user, @@ -436,6 +444,7 @@ def update_manifest(logger, chroot_name, chroot_user, workdir, ebuild_path): "code {code}.".format(code=retcode)) sys.exit(retcode) + def check_branch_existance(logger, repo_uri, branch): """Check if the specified remote repository has the given branch. This check is needed, because a git clone on Debian 6.0 (squeeze) @@ -449,6 +458,7 @@ def check_branch_existance(logger, repo_uri, branch): "{repo}".format(branch=branch, repo=repo_uri)) sys.exit(1) + def find_ebuilds(logger, category): """Search for ebuild files in the current directory""" ebuild_files = glob.glob("*.ebuild") @@ -463,6 +473,7 @@ def find_ebuilds(logger, category): ebuild=" ".join(ebuild_files))) return [Ebuild(logger, e, category) for e in ebuild_files] + def auto_versioning(logger, repo, autodecrement, autoincrement): """Increment or decrement the Debian version.""" if not os.path.isfile('debian/changelog'): @@ -495,6 +506,7 @@ def auto_versioning(logger, repo, autodecrement, autoincrement): tag_head_commit(logger, repo, new_tag) return new_tag + def tag_from_debian_changelog(logger, repo): """Create a tag from the version specified in debian/changelog. Returns the name of the created tag. @@ -514,6 +526,7 @@ def tag_from_debian_changelog(logger, repo): tag_head_commit(logger, repo, new_tag, resolve_existing_msg) return new_tag + def tag_head_commit(logger, repo, new_tag, resolve_existing_msg=""): """Tags the head commit with the given tag name.""" current_commit = repo.head.commit @@ -544,6 +557,7 @@ def tag_head_commit(logger, repo, new_tag, resolve_existing_msg=""): tag=new_tag)) repo.git.tag(new_tag) + def format_commit(commit): """Create a human readable string for a given git commit.""" remote_url = commit.repo.config_reader().get('remote "origin"', "url") @@ -551,6 +565,7 @@ def format_commit(commit): weburl += "/commit/" + commit.hexsha[0:7] return commit.hexsha[0:7] + ' (' + weburl + ')' + def get_latest_tag(logger, repo): """Get the tag name for the branch head commit. The function will fail if the branch head commit is not tagged or has @@ -572,6 +587,7 @@ def get_latest_tag(logger, repo): logger.info('Use tag "{tag}" as release version.'.format(tag=tag)) return tag + def push_tag(logger, repo, tag, dry_run): """Pushed the given git tag unless it is a dry run.""" if dry_run: @@ -585,5 +601,6 @@ def push_tag(logger, repo, tag, dry_run): logger.error('Could not push tag: ' + str(error)) sys.exit(1) + if __name__ == '__main__': main() -- 2.39.5