summaryrefslogtreecommitdiff
path: root/tools/read-version
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-07-09 15:36:16 -0400
committerScott Moser <smoser@ubuntu.com>2012-07-09 15:36:16 -0400
commit7cd3e340264365c2e968b72cce78db9ff74b24a7 (patch)
tree4a7872cde84ca0d29e7e163f768aed564a8fa208 /tools/read-version
parent492dc7478e0ab3eb03eb3b0b5d0e47812339b83f (diff)
parentc7aeea86fb8a17e4402cfc42626dfff2fb04c1a0 (diff)
downloadvyos-cloud-init-7cd3e340264365c2e968b72cce78db9ff74b24a7.tar.gz
vyos-cloud-init-7cd3e340264365c2e968b72cce78db9ff74b24a7.zip
rework packaging tools to find the right cloud-init topdir
This also fixes 'brpm' to address --init-system change that smoser made to setup.py before the large 'rework' merge.
Diffstat (limited to 'tools/read-version')
-rwxr-xr-xtools/read-version101
1 files changed, 31 insertions, 70 deletions
diff --git a/tools/read-version b/tools/read-version
index e6167a2c..323357fe 100755
--- a/tools/read-version
+++ b/tools/read-version
@@ -1,70 +1,31 @@
-#!/usr/bin/python
-# vi: ts=4 expandtab
-
-import os
-import sys
-import re
-
-from distutils import version as ver
-
-possible_topdir = os.path.normpath(os.path.join(os.path.abspath(
- sys.argv[0]), os.pardir, os.pardir))
-if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")):
- sys.path.insert(0, possible_topdir)
-
-from cloudinit import version as cver
-
-def parse_versions(fn):
- with open(fn, 'r') as fh:
- lines = fh.read().splitlines()
- versions = []
- for line in lines:
- line = line.strip()
- if line.startswith("-") or not line:
- continue
- if not re.match(r"[\d]", line):
- continue
- line = line.strip(":")
- if (re.match(r"^[\d+]\.[\d+]\.[\d+]$", line) or
- re.match(r"^[\d+]\.[\d+]$", line)):
- versions.append(line)
- return versions
-
-def find_changelog(args):
- p_files = []
- if args:
- p_files.append(args[0])
- p_files.append(os.path.join(os.pardir, "ChangeLog"))
- p_files.append(os.path.join(os.getcwd(), 'ChangeLog'))
- found = None
- for fn in p_files:
- if os.path.isfile(fn):
- found = fn
- break
- return found
-
-
-if __name__ == '__main__':
- run_args = sys.argv[1:]
- fn = find_changelog(run_args)
- if not fn:
- sys.stderr.write("'ChangeLog' file not found!\n")
- sys.exit(1)
- else:
- versions = parse_versions(fn)
- if not versions:
- sys.stderr.write("No versions found in %s!\n" % (fn))
- sys.exit(1)
- else:
- # Check that the code version is the same
- # as the version we found!
- ch_ver = versions[0].strip()
- code_ver = cver.version()
- ch_ver_obj = ver.StrictVersion(ch_ver)
- if ch_ver_obj != code_ver:
- sys.stderr.write(("Code version %s does not match"
- " changelog version %s\n") %
- (code_ver, ch_ver_obj))
- sys.exit(1)
- sys.stdout.write(ch_ver)
- sys.exit(0)
+#!/bin/sh
+
+set -e
+
+find_root() {
+ local topd
+ if [ -z "${CLOUD_INIT_TOP_D}" ]; then
+ topd=$(cd "$(dirname "${0}")" && cd .. && pwd)
+ else
+ topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd)
+ fi
+ [ $? -eq 0 -a -f "${topd}/setup.py" ] || return
+ ROOT_DIR="$topd"
+}
+
+if ! find_root; then
+ echo "Unable to locate 'setup.py' file that should" \
+ "exist in the cloud-init root directory." 1>&2
+ exit 1;
+fi
+
+CHNG_LOG="$ROOT_DIR/ChangeLog"
+
+if [ ! -e "$CHNG_LOG" ]
+then
+ echo "Unable to find 'ChangeLog' file located at $CHNG_LOG"
+ exit 1
+fi
+
+VERSION=$(grep -P "\d+.\d+.\d+:" $CHNG_LOG | cut -f1 -d ":" | head -n 1)
+echo $VERSION