Commit 4c080739 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Allow multiple version files and templates

Extend devflow to support multiple version files of different templates.
To use multiple version files, the user has to define a comma-separated
list of version files and templates in the 'version_file' and
'version_template' options of the configuration file.
parent 651e8382
......@@ -304,7 +304,8 @@ def main():
cd(repo_dir)
version_files = []
for _, pkg_info in config['packages'].items():
version_files.append(pkg_info['version_file'])
if pkg_info.get("version_file"):
version_files.extend(pkg_info.as_list('version_file'))
# Export version info to debuilg environment
os.environ["DEB_DEVFLOW_DEBIAN_VERSION"] = debian_version
os.environ["DEB_DEVFLOW_VERSION"] = python_version
......
......@@ -44,6 +44,7 @@ of the repository code.
import os
import re
import sys
import itertools
from distutils import log # pylint: disable=E0611
......@@ -73,6 +74,7 @@ def get_base_version(vcs_info):
f.close()
return lines[0]
def validate_version(base_version, vcs_info):
branch = vcs_info.branch
......@@ -104,6 +106,7 @@ def validate_version(base_version, vcs_info):
raise ValueError("Base version '%s' unsuitable for branch name '%s'" %
(base_version, branch))
def python_version(base_version, vcs_info, mode):
"""Generate a Python distribution version following devtools conventions.
......@@ -380,27 +383,43 @@ def update_version():
"DEVFLOW_USER_NAME": v.name}
for _pkg_name, pkg_info in config['packages'].items():
version_filename = pkg_info.get('version_file')
if not version_filename:
if pkg_info.get("version_file"):
version_filenames = pkg_info.as_list("version_file")
else:
continue
version_template = pkg_info.get('version_template')
if version_template:
vtemplate_file = os.path.join(toplevel, version_template)
try:
with file(vtemplate_file) as f:
content = f.read(-1) % env
except IOError as e:
if e.errno == 2:
raise RuntimeError("devflow.conf contains '%s' as a"
" version template file, but file does"
" not exists!" % vtemplate_file)
else:
raise
if pkg_info.get('version_template'):
version_templates = pkg_info.as_list("version_template")
else:
content = DEFAULT_VERSION_FILE % env
with file(os.path.join(toplevel, version_filename), 'w+') as f:
log.info("Updating version file '%s'" % version_filename)
f.write(content)
version_templates = itertools.repeat(None, len(version_filenames))
version_templates = list(version_templates)
if len(version_filenames) != len(version_templates):
raise RuntimeError("devflow.conf contains '%s' version files and"
" '%s' version templates. The number of version"
" files and templates must match."
% (len(version_filenames),
len(version_templates)))
v_files_templates = zip(version_filenames, version_templates)
for (vfilename, vtemplate) in v_files_templates:
if vtemplate:
vtemplate_file = os.path.join(toplevel, vtemplate)
try:
with file(vtemplate_file) as f:
content = f.read(-1) % env
except IOError as e:
if e.errno == 2:
raise RuntimeError("devflow.conf contains '%s' as a"
" version template file, but file"
" does not exists!"
% vtemplate_file)
else:
raise
else:
content = DEFAULT_VERSION_FILE % env
with file(os.path.join(toplevel, vfilename), 'w+') as f:
log.info("Updating version file '%s'" % vfilename)
f.write(content)
def bump_version_main():
......@@ -446,7 +465,6 @@ def bump_version(new_version):
_bump_version(new_version, v)
def main():
v = utils.get_vcs_info()
b = get_base_version(v)
......
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