summaryrefslogtreecommitdiff
path: root/tools/read-version
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-01-23 15:17:17 -0500
committerScott Moser <smoser@ubuntu.com>2014-01-23 15:17:17 -0500
commit573ee6d9d641356374ac616f53cb254d4da7c9db (patch)
treee96228256276875c47c5031160bd2f3cbe3b5398 /tools/read-version
parent1781668dd65737a800c2c8fdbb79c6f1288d3ef2 (diff)
parentc833a84f08019ba4413937f2f1b1f12a4ffe5632 (diff)
downloadvyos-cloud-init-573ee6d9d641356374ac616f53cb254d4da7c9db.tar.gz
vyos-cloud-init-573ee6d9d641356374ac616f53cb254d4da7c9db.zip
merge from trunk
Diffstat (limited to 'tools/read-version')
-rwxr-xr-xtools/read-version46
1 files changed, 20 insertions, 26 deletions
diff --git a/tools/read-version b/tools/read-version
index 18708f2b..d02651e9 100755
--- a/tools/read-version
+++ b/tools/read-version
@@ -1,32 +1,26 @@
-#!/bin/sh
+#!/usr/bin/env python
-set -e
+import os
+import re
+import sys
-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"
-}
-fail() { echo "$0:" "$@" 1>&2; exit 1; }
+if 'CLOUD_INIT_TOP_D' in os.environ:
+ topd = os.path.realpath(os.environ.get('CLOUD_INIT_TOP_D'))
+else:
+ topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
-if ! find_root; then
- fail "Unable to locate 'setup.py' file that should " \
- "exist in the cloud-init root directory."
-fi
+for fname in ("setup.py", "ChangeLog"):
+ if not os.path.isfile(os.path.join(topd, fname)):
+ sys.stderr.write("Unable to locate '%s' file that should "
+ "exist in cloud-init root directory." % fname)
+ sys.exit(1)
-CHNG_LOG="$ROOT_DIR/ChangeLog"
+vermatch = re.compile(r"^[0-9]+[.][0-9]+[.][0-9]+:$")
-if [ ! -e "$CHNG_LOG" ]; then
- fail "Unable to find 'ChangeLog' file located at '$CHNG_LOG'"
-fi
+with open(os.path.join(topd, "ChangeLog"), "r") as fp:
+ for line in fp:
+ if vermatch.match(line):
+ sys.stdout.write(line.strip()[:-1] + "\n")
+ break
-VERSION=$(grep -m1 -o -E '^[0-9]+(\.[0-9]+)+' \
- "$CHNG_LOG") &&
- [ -n "$VERSION" ] ||
- fail "failed to get version from '$CHNG_LOG'"
-echo "$VERSION"
+sys.exit(0)