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

Option to override configuration file

parent 7316df0e
......@@ -60,26 +60,14 @@ BRANCH_TYPES = {
"hotfix": branch_type("debian")}
def get_packages_to_build(toplevel_dir):
conf_file = os.path.join(toplevel_dir, "autopkg.conf")
f = open(conf_file)
except IOError:
raise RuntimeError("Configuration file %s does not exist!" % conf_file)
lines = [l.strip() for l in f.readlines()]
l = [l for l in lines if not l.startswith("#")]
return l
DESCRIPTION = """Tool for automatical build of debian packages.
%(prog)s is a helper script for automatic build of debian packages from
repositories that follow the `git flow` development model
This script must run from the toplevel directory of a clean git repository and
will perform the following steps:
This script must run from inside a clean git repository and will perform the
following steps:
* Clone your repository to a temporary directory
* Merge the current branch with the corresponding debian branch
* Compute the version of the new package and update the python
......@@ -88,6 +76,9 @@ will perform the following steps:
* Create the debian packages, using `git-buildpackage`
* Tag the appropriate branches if in `release` mode
%(prog)s will work with the packages that are declared in `autopkg.conf`
file, which must exist in the toplevel directory of the git repository.
......@@ -122,6 +113,9 @@ def main():
help="Do not check if working directory is dirty")
parser.add_option("-c", "--config-file",
help="Override default configuration file")
(options, args) = parser.parse_args()
......@@ -130,6 +124,7 @@ def main():
# Get build mode
mode = args[0]
except IndexError:
......@@ -141,16 +136,20 @@ def main():
os.environ["GITFLOW_BUILD_MODE"] = mode
# Load the repository
original_repo = git.Repo(".")
except git.git.InvalidGitRepositoryError:
raise RuntimeError(red("Current directory is not git repository."))
# Check that repository is clean
toplevel = original_repo.working_dir
if original_repo.is_dirty() and not options.force_dirty:
raise RuntimeError(red("Repository %s is dirty." % toplevel))
packages = get_packages_to_build(toplevel)
# Get packages from configuration file
config_file = options.config_file or os.path.join(toplevel, "autopkg.conf")
packages = get_packages_to_build(config_file)
if packages:
print_green("Will build the following packages:\n" + \
......@@ -158,6 +157,7 @@ def main():
raise RuntimeError("Configuration file is empty."
" No packages to build.")
# Clone the repo
repo_dir = options.repo_dir
if not repo_dir:
repo_dir = mktemp("-d", "/tmp/devflow-build-repo-XXX").stdout.strip()
......@@ -174,6 +174,7 @@ def main():
brnorm = versioning.normalize_branch_name(branch)
btypestr = versioning.get_branch_type(brnorm)
# Find the debian branch, and create it if does not exist
debian_branch = "debian-" + brnorm
origin_debian = "origin/" + debian_branch
if not origin_debian in repo.references:
......@@ -190,18 +191,22 @@ def main():
print_green("Created branch '%s' to track '%s'" % (debian_branch,
# Go to debian branch
print_green("Changed to branch '%s'" % debian_branch)
# Merge with starting branch
print_green("Merged branch '%s' into '%s'" % (brnorm, debian_branch))
# Compute python and debian version
python_version = versioning.get_python_version()
debian_version = versioning.\
print_green("The new debian version will be: '%s'" % debian_version)
# Update changelog
dch = git_dch("--debian-branch=%s" % debian_branch,
......@@ -214,6 +219,7 @@ def main():
if mode == "release":
# Commit changelog and update tag branches
os.system("vim debian/changelog")
repo.git.commit("-s", "-a", "-m", "Bump new upstream version")
......@@ -222,6 +228,8 @@ def main():
repo.git.tag(python_tag, brnorm)
# Update the python version files
# TODO: remove this
for package in packages:
# python should run in its directory
......@@ -234,6 +242,7 @@ def main():
# Add files to repo
os.system("grep \"__version_vcs\" -r . -l -I | xargs git add -f")
# Create debian branches
build_dir = options.build_dir
if not options.build_dir:
build_dir = mktemp("-d", "/tmp/devflow-build-XXX").stdout.strip()
......@@ -245,6 +254,7 @@ def main():
" --git-debian-branch=%s --git-export=INDEX --git-ignore-new -sa"
% (build_dir, brnorm, debian_branch))
# Remove cloned repo
if not options.keep_repo:
print_green("Removing cloned repo '%s'." % repo_dir)
rm("-r", repo_dir)
......@@ -254,6 +264,7 @@ def main():
print_green("Completed. Version '%s', build area: '%s'"
% (debian_version, build_dir))
# Print help message
if mode == "release":
TAG_MSG = "Tagged branch %s with tag %s\n"
print_green(TAG_MSG % (brnorm, python_tag))
......@@ -271,5 +282,19 @@ def main():
debian_branch, debian_tag, python_tag))
def get_packages_to_build(config_file):
config_file = os.path.abspath(config_file)
f = open(config_file)
except IOError:
raise RuntimeError("Configuration file %s does not exist!"
% config_file)
lines = [l.strip() for l in f.readlines()]
l = [l for l in lines if not l.startswith("#")]
return l
if __name__ == "__main__":
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