Commit c181882a authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Make devflow-autopkg mode argument optional

parent 1715bcbd
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
"""A set of tools to ease versioning and use of git flow"""
from collections import namedtuple
# Branch types:
# builds_snapshot: Whether the branch can produce snapshot builds
# builds_release: Whether the branch can produce release builds
# versioned: Whether the name of the branch defines a specific version
# 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"])
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),
"release": branch_type(True, True, True,
"^(?P<bverstr>%s)rc[1-9][0-9]*$" % VERSION_RE),
"master": branch_type(False, True, False,
"^%s$" % VERSION_RE),
"hotfix": branch_type(True, True, True,
"^(?P<bverstr>^%s\.[1-9][0-9]*)$" % VERSION_RE)}
BASE_VERSION_FILE = "version"
......@@ -36,12 +36,12 @@
import os
import sys
from optparse import OptionParser
from collections import namedtuple
from sh import mktemp, cd, rm, git_dch # pylint: disable=E0611
from configobj import ConfigObj
from devflow import versioning
from devflow import utils
from devflow import BRANCH_TYPES
try:
from colors import red, green
......@@ -54,15 +54,6 @@ print_green = lambda x: sys.stdout.write(green(x) + "\n")
AVAILABLE_MODES = ["release", "snapshot"]
branch_type = namedtuple("branch_type", ["default_debian_branch"])
BRANCH_TYPES = {
"feature": branch_type("debian-develop"),
"develop": branch_type("debian-develop"),
"release": branch_type("debian-develop"),
"master": branch_type("debian"),
"hotfix": branch_type("debian")}
DESCRIPTION = """Tool for automatical build of debian packages.
%(prog)s is a helper script for automatic build of debian packages from
......@@ -145,8 +136,7 @@ def main():
try:
mode = args[0]
except IndexError:
raise ValueError("Mode argument is mandatory. Usage: %s"
% parser.usage)
mode = utils.get_build_mode()
if mode not in AVAILABLE_MODES:
raise ValueError(red("Invalid argument! Mode must be one: %s"
% ", ".join(AVAILABLE_MODES)))
......
......@@ -34,6 +34,7 @@
import os
import git
from collections import namedtuple
from devflow import BRANCH_TYPES
def get_repository():
......@@ -118,3 +119,19 @@ def _get_branch(branch):
return branch
else:
return None
def get_build_mode():
"""Determine the 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
try:
br_type = BRANCH_TYPES[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
......@@ -47,31 +47,11 @@ import sys
import pprint
from distutils import log # pylint: disable=E0611
from collections import namedtuple
from configobj import ConfigObj
from devflow import BRANCH_TYPES, BASE_VERSION_FILE
from devflow import utils
# Branch types:
# builds_snapshot: Whether the branch can produce snapshot builds
# builds_release: Whether the branch can produce release builds
# versioned: Whether the name of the branch defines a specific version
# 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"])
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),
"release": branch_type(True, True, True,
"^(?P<bverstr>%s)rc[1-9][0-9]*$" % VERSION_RE),
"master": branch_type(False, True, False,
"^%s$" % VERSION_RE),
"hotfix": branch_type(True, True, True,
"^(?P<bverstr>^%s\.[1-9][0-9]*)$" % VERSION_RE)}
BASE_VERSION_FILE = "version"
def get_base_version(vcs_info):
"""Determine the base version from a file in the repository"""
......@@ -85,22 +65,6 @@ def get_base_version(vcs_info):
return lines[0]
def build_mode():
"""Determine the build mode"""
# Get it from environment if exists
mode = os.environ.get("DEVFLOW_BUILD_MODE", None)
if mode is None:
branch = utils.get_vcs_info().branch
try:
br_type = BRANCH_TYPES[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
......@@ -375,7 +339,7 @@ def get_revision(version):
def get_python_version():
v = utils.get_vcs_info()
b = get_base_version(v)
mode = build_mode()
mode = utils.get_build_mode()
return python_version(b, v, mode)
......@@ -387,7 +351,7 @@ def debian_version(base_version, vcs_info, mode):
def get_debian_version():
v = utils.get_vcs_info()
b = get_base_version(v)
mode = build_mode()
mode = utils.get_build_mode()
return debian_version(b, v, mode)
......@@ -414,7 +378,7 @@ def update_version():
raise RuntimeError("Can not compute version outside of a git"
" repository.")
b = get_base_version(v)
mode = build_mode()
mode = utils.get_build_mode()
version = python_version(b, v, mode)
vcs_info_dict = dict(v._asdict()) # pylint: disable=W0212
content = """__version__ = "%(version)s"
......@@ -446,7 +410,7 @@ def bump_version_main():
def bump_version(new_version):
"""Set new base version to base version file and commit"""
v = utils.get_vcs_info()
mode = build_mode()
mode = utils.get_build_mode()
# Check that new base version is valid
python_version(new_version, v, mode)
......@@ -479,7 +443,7 @@ def bump_version(new_version):
def main():
v = utils.get_vcs_info()
b = get_base_version(v)
mode = build_mode()
mode = utils.get_build_mode()
try:
arg = sys.argv[1]
......
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