Commit 06071d10 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Merge branch 'release-0.10'

Conflicts:
	version
parents 7d57d676 6da63769
......@@ -42,15 +42,20 @@ from collections import namedtuple
# allowed_version_re: A regular expression describing allowed values for
# base_version in this branch
branch_type = namedtuple("branch_type", ["builds_snapshot", "builds_release",
"versioned", "allowed_version_re"])
"versioned", "allowed_version_re",
"debian_branch"])
VERSION_RE = "[0-9]+\.[0-9]+(\.[0-9]+)*"
BRANCH_TYPES = {
"feature": branch_type(True, False, False, "^%snext$" % VERSION_RE),
"develop": branch_type(True, False, False, "^%snext$" % VERSION_RE),
"feature": branch_type(True, False, False, "^%snext$" % VERSION_RE,
"debian-develop"),
"develop": branch_type(True, False, False, "^%snext$" % VERSION_RE,
"debian-develop"),
"release": branch_type(True, True, True,
"^(?P<bverstr>%s)rc[1-9][0-9]*$" % VERSION_RE),
"^(?P<bverstr>%s)rc[1-9][0-9]*$" % VERSION_RE,
"debian-develop"),
"master": branch_type(False, True, False,
"^%s$" % VERSION_RE),
"^%s$" % VERSION_RE, "debian"),
"hotfix": branch_type(True, True, True,
"^(?P<bverstr>^%s\.[1-9][0-9]*)$" % VERSION_RE)}
"^(?P<bverstr>^%s\.[1-9][0-9]*)$" % VERSION_RE,
"debian")}
BASE_VERSION_FILE = "version"
......@@ -35,9 +35,10 @@
import os
import sys
from git import GitCommandError
from optparse import OptionParser
from sh import mktemp, cd, rm, git_dch # pylint: disable=E0611
from configobj import ConfigObj
from devflow import versioning
from devflow import utils
......@@ -150,8 +151,6 @@ def main():
raise ValueError(red("Invalid argument! Mode must be one: %s"
% ", ".join(AVAILABLE_MODES)))
os.environ["DEVFLOW_BUILD_MODE"] = mode
# Load the repository
original_repo = utils.get_repository()
......@@ -161,20 +160,31 @@ def main():
raise RuntimeError(red("Repository %s is dirty." % toplevel))
# Get packages from configuration file
config_file = options.config_file or os.path.join(toplevel, "devflow.conf")
config = ConfigObj(config_file)
config = utils.get_config(options.config_file)
packages = config['packages'].keys()
print_green("Will build the following packages:\n" + "\n".join(packages))
# Get current branch name and type and check if it is a valid one
branch = original_repo.head.reference.name
branch_type_str = versioning.get_branch_type(branch)
branch_type_str = utils.get_branch_type(branch)
if branch_type_str not in BRANCH_TYPES.keys():
allowed_branches = ", ".join(BRANCH_TYPES.keys())
raise ValueError("Malformed branch name '%s', cannot classify as"
" one of %s" % (branch, allowed_branches))
# Fix needed environment variables
os.environ["DEVFLOW_BUILD_MODE"] = mode
git_config = original_repo.config_reader()
try:
os.environ["DEBFULLNAME"] = git_config.get_value("user", "name")
os.environ["DEBEMAIL"] = git_config.get_value("user", "email")
except:
print "Could not load user/email from config"
# Check that base version file and branch are correct
versioning.get_python_version()
# Get the debian branch
debian_branch = utils.get_debian_branch(branch)
origin_debian = "origin/" + debian_branch
......@@ -214,7 +224,11 @@ def main():
# Tag branch with python version
branch_tag = python_version
repo.git.tag(branch_tag, branch)
try:
repo.git.tag(branch_tag, branch)
except GitCommandError:
# Tag may already exist, if only the debian branch has changed
pass
upstream_tag = "upstream/" + branch_tag
repo.git.tag(upstream_tag, branch)
......@@ -243,8 +257,9 @@ def main():
# Commit Changes
repo.git.commit("-s", "-a", m="Bump version to %s" % debian_version)
# Tag debian branch
debian_branch_tag = "debian/" + branch_tag
repo.git.tag(debian_branch_tag)
debian_branch_tag = "debian/" + utils.version_to_tag(debian_version)
if mode == "release":
repo.git.tag(debian_branch_tag)
# Add version.py files to repo
call("grep \"__version_vcs\" -r . -l -I | xargs git add -f")
......
......@@ -34,20 +34,33 @@
import os
import git
from collections import namedtuple
from configobj import ConfigObj
from devflow import BRANCH_TYPES
def get_repository():
def get_repository(path=None):
"""Load the repository from the current working dir."""
if path is None:
path = os.getcwd()
try:
return git.Repo(".")
return git.Repo(path)
except git.InvalidGitRepositoryError:
msg = "Cound not retrivie git information. Directory '%s'"\
" is not a git repository!" % os.getcwd()
" is not a git repository!" % path
raise RuntimeError(msg)
def get_config(path=None):
"""Load configuration file."""
if path is None:
toplevel = get_vcs_info().toplevel
path = os.path.join(toplevel, "devflow.conf")
config = ConfigObj(path)
return config
def get_vcs_info():
"""Return current git HEAD commit information.
......@@ -101,10 +114,21 @@ def get_debian_branch(branch):
"""Find the corresponding debian- branch"""
if branch == "master":
return "debian"
# Check if debian-branch exists (local or origin)
deb_branch = "debian-" + branch
if _get_branch(deb_branch) or _get_branch("origin/" + deb_branch):
# Check if debian-branch exists (local or origin)
if _get_branch(deb_branch):
return deb_branch
branch_type = BRANCH_TYPES[get_branch_type(branch)]
# If not try the default debian branch
default_branch = branch_type.debian_branch
if _get_branch(default_branch):
repo = get_repository()
repo.git.branch(deb_branch, default_branch)
print "Created branch '%s' from '%s'" % (deb_branch, default_branch)
return deb_branch
# If not try the debian branch
repo.git.branch(deb_branch, default_branch)
print "Created branch '%s' from 'debian'" % deb_branch
return "debian"
......@@ -114,7 +138,7 @@ def _get_branch(branch):
return branch
origin_branch = "origin/" + branch
if origin_branch in repo.refs:
print "Creating branch '%s' to track '%s'" (branch, origin_branch)
print "Creating branch '%s' to track '%s'" % (branch, origin_branch)
repo.git.branch(branch, origin_branch)
return branch
else:
......@@ -126,12 +150,37 @@ def get_build_mode():
# Get it from environment if exists
mode = os.environ.get("DEVFLOW_BUILD_MODE", None)
if mode is None:
branch = get_vcs_info().branch
branch = get_branch_type(get_vcs_info().branch)
try:
br_type = BRANCH_TYPES[branch]
br_type = BRANCH_TYPES[get_branch_type(branch)]
except KeyError:
allowed_branches = ", ".join(x for x in BRANCH_TYPES.keys())
raise ValueError("Malformed branch name '%s', cannot classify as"
" one of %s" % (branch, allowed_branches))
mode = "snapshot" if br_type.builds_snapshot else "release"
return mode
def normalize_branch_name(branch_name):
"""Normalize branch name by removing debian- if exists"""
brnorm = branch_name
if brnorm == "debian":
brnorm = "debian-master"
# If it's a debian branch, ignore starting "debian-"
if brnorm.startswith("debian-"):
brnorm = brnorm.replace("debian-", "", 1)
return brnorm
def get_branch_type(branch_name):
"""Extract the type from a branch name"""
branch_name = normalize_branch_name(branch_name)
if "-" in branch_name:
btypestr = branch_name.split("-")[0]
else:
btypestr = branch_name
return btypestr
def version_to_tag(version):
return version.replace("~", "")
......@@ -47,9 +47,8 @@ import sys
import pprint
from distutils import log # pylint: disable=E0611
from configobj import ConfigObj
from devflow import BRANCH_TYPES, BASE_VERSION_FILE
from devflow import BRANCH_TYPES, BASE_VERSION_FILE, VERSION_RE
from devflow import utils
......@@ -65,26 +64,6 @@ def get_base_version(vcs_info):
return lines[0]
def normalize_branch_name(branch_name):
"""Normalize branch name by removing debian- if exists"""
brnorm = branch_name
if brnorm == "debian":
brnorm = "debian-master"
# If it's a debian branch, ignore starting "debian-"
if brnorm.startswith("debian-"):
brnorm = brnorm.replace("debian-", "", 1)
return brnorm
def get_branch_type(branch_name):
"""Extract the type from a branch name"""
if "-" in branch_name:
btypestr = branch_name.split("-")[0]
else:
btypestr = branch_name
return btypestr
def python_version(base_version, vcs_info, mode):
"""Generate a Python distribution version following devtools conventions.
......@@ -205,8 +184,8 @@ def python_version(base_version, vcs_info, mode):
branch = vcs_info.branch
brnorm = normalize_branch_name(branch)
btypestr = get_branch_type(brnorm)
brnorm = utils.normalize_branch_name(branch)
btypestr = utils.get_branch_type(branch)
try:
btype = BRANCH_TYPES[btypestr]
......@@ -326,10 +305,11 @@ def debian_version_from_python_version(pyver):
def get_revision(version):
"""Find revision for a debian version"""
version_tag = utils.version_to_tag(version)
repo = utils.get_repository()
minor = 1
while True:
tag = "debian/" + version + "-" + str(minor)
tag = "debian/" + version_tag + "-" + str(minor)
if tag in repo.tags:
minor += 1
else:
......@@ -370,9 +350,9 @@ def update_version():
"""
v = utils.get_vcs_info()
toplevel = v.toplevel + "/"
toplevel = v.toplevel
config = ConfigObj(toplevel + "devflow.conf")
config = utils.get_config()
if not v:
# Return early if not in development environment
raise RuntimeError("Can not compute version outside of a git"
......@@ -392,8 +372,9 @@ __version_user_info__ = "%(user_info)s"
for _pkg_name, pkg_info in config['packages'].items():
version_filename = pkg_info['version_file']
if version_filename:
path = os.path.join(toplevel, version_filename)
log.info("Updating version file '%s'" % version_filename)
version_file = file(toplevel + version_filename, "w+")
version_file = file(path, "w+")
version_file.write(content)
version_file.close()
......@@ -421,7 +402,7 @@ def bump_version(new_version):
old_version = get_base_version(v)
sys.stdout.write("Current base version is '%s'\n" % old_version)
version_file = toplevel + "/version"
version_file = os.path.join(toplevel, "version")
sys.stdout.write("Updating version file %s from version '%s' to '%s'\n"
% (version_file, old_version, new_version))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment