Commit 9fe1ecd8 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Support debian revisions

Find the correct debian revision, by looking the debian tags. Also, move
some functions to new 'utils' module.
parent 693a31b7
......@@ -33,7 +33,6 @@
"""Helper script for automatic build of debian packages."""
import git
import os
import sys
from optparse import OptionParser
......@@ -42,6 +41,7 @@ from sh import mktemp, cd, rm, git_dch # pylint: disable=E0611
from configobj import ConfigObj
from devflow import versioning
from devflow import utils
try:
from colors import red, green
......@@ -154,10 +154,7 @@ def main():
os.environ["DEVFLOW_BUILD_MODE"] = mode
# Load the repository
try:
original_repo = git.Repo(".")
except git.InvalidGitRepositoryError:
raise RuntimeError(red("Current directory is not git repository."))
original_repo = utils.get_repository()
# Check that repository is clean
toplevel = original_repo.working_dir
......
# Copyright (C) 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.
import os
import git
from collections import namedtuple
def get_repository():
"""Load the repository from the current working dir."""
try:
return git.Repo(".")
except git.InvalidGitRepositoryError:
msg = "Cound not retrivie git information. Directory '%s'"\
" is not a git repository!" % os.getcwd()
raise RuntimeError(msg)
def get_vcs_info():
"""Return current git HEAD commit information.
Returns a tuple containing
- branch name
- commit id
- commit count
- git describe output
- path of git toplevel directory
"""
repo = get_repository()
branch = repo.head.reference
revid = get_commit_id(branch.commit, branch)
revno = len(list(repo.iter_commits()))
toplevel = repo.working_dir
info = namedtuple("vcs_info", ["branch", "revid", "revno",
"toplevel"])
return info(branch=branch.name, revid=revid, revno=revno,
toplevel=toplevel)
def get_commit_id(commit, current_branch):
"""Return the commit ID
If the commit is a 'merge' commit, and one of the parents is a
debian branch we return a compination of the parents commits.
"""
def short_id(commit):
return commit.hexsha[0:7]
parents = commit.parents
cur_br_name = current_branch.name
if len(parents) == 1:
return short_id(commit)
elif len(parents) == 2:
if cur_br_name.startswith("debian-") or cur_br_name == "debian":
pr1, pr2 = parents
return short_id(pr1) + "_" + short_id(pr2)
else:
return short_id(commit)
else:
raise RuntimeError("Commit %s has more than 2 parents!" % commit)
......@@ -45,12 +45,12 @@ import os
import re
import sys
import pprint
import git
from distutils import log # pylint: disable=E0611
from collections import namedtuple
from configobj import ConfigObj
from devflow import utils
# Branch types:
# builds_snapshot: Whether the branch can produce snapshot builds
......@@ -73,59 +73,6 @@ BRANCH_TYPES = {
BASE_VERSION_FILE = "version"
def get_commit_id(commit, current_branch):
"""Return the commit ID
If the commit is a 'merge' commit, and one of the parents is a
debian branch we return a compination of the parents commits.
"""
def short_id(commit):
return commit.hexsha[0:7]
parents = commit.parents
cur_br_name = current_branch.name
if len(parents) == 1:
return short_id(commit)
elif len(parents) == 2:
if cur_br_name.startswith("debian-") or cur_br_name == "debian":
pr1, pr2 = parents
return short_id(pr1) + "_" + short_id(pr2)
else:
return short_id(commit)
else:
raise RuntimeError("Commit %s has more than 2 parents!" % commit)
def get_vcs_info():
"""Return current git HEAD commit information.
Returns a tuple containing
- branch name
- commit id
- commit count
- git describe output
- path of git toplevel directory
"""
try:
repo = git.Repo(".")
branch = repo.head.reference
revid = get_commit_id(branch.commit, branch)
revno = len(list(repo.iter_commits()))
toplevel = repo.working_dir
except git.InvalidGitRepositoryError:
log.error("Could not retrieve git information. " +
"Current directory not a git repository?")
return None
info = namedtuple("vcs_info", ["branch", "revid", "revno",
"toplevel"])
return info(branch=branch.name, revid=revid, revno=revno,
toplevel=toplevel)
def get_base_version(vcs_info):
"""Determine the base version from a file in the repository"""
......@@ -406,11 +353,25 @@ def debian_version_from_python_version(pyver):
True
"""
return pyver.replace("_", "~").replace("rc", "~rc") + "-1"
version = pyver.replace("_", "~").replace("rc", "~rc")
minor = get_revision(version)
return version + "-" + str(minor)
def get_revision(version):
"""Find revision for a debian version"""
repo = utils.get_repository()
minor = 1
while True:
tag = "debian/" + version + "-" + str(minor)
if tag in repo.tags:
minor += 1
else:
return minor
def get_python_version():
v = get_vcs_info()
v = utils.get_vcs_info()
b = get_base_version(v)
mode = build_mode()
return python_version(b, v, mode)
......@@ -422,7 +383,7 @@ def debian_version(base_version, vcs_info, mode):
def get_debian_version():
v = get_vcs_info()
v = utils.get_vcs_info()
b = get_base_version(v)
mode = build_mode()
return debian_version(b, v, mode)
......@@ -442,7 +403,7 @@ def update_version():
"""
v = get_vcs_info()
v = utils.get_vcs_info()
toplevel = v.toplevel + "/"
config = ConfigObj(toplevel + "devflow.conf")
......@@ -482,13 +443,13 @@ def bump_version_main():
def bump_version(new_version):
"""Set new base version to base version file and commit"""
v = get_vcs_info()
v = utils.get_vcs_info()
mode = build_mode()
# Check that new base version is valid
python_version(new_version, v, mode)
repo = git.Repo(".")
repo = utils.get_repository()
toplevel = repo.working_dir
old_version = get_base_version(v)
......@@ -514,7 +475,7 @@ def bump_version(new_version):
def main():
v = get_vcs_info()
v = utils.get_vcs_info()
b = get_base_version(v)
mode = build_mode()
......
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