built
"""
+
class Ebuild(object):
"""This class represents an .ebuild file."""
"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):
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}",
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
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])
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",
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."""
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)
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)
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:
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
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,
"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)
"{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")
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'):
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.
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
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")
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
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:
logger.error('Could not push tag: ' + str(error))
sys.exit(1)
+
if __name__ == '__main__':
main()