summaryrefslogtreecommitdiff
path: root/tools/read-version
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-25 13:07:17 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-25 13:07:17 -0700
commitd45b0aacf88cf640dde538b3ee92958099129f74 (patch)
tree5898a2a07bd521adbe40ce9e96aeb9123d75c4d6 /tools/read-version
parenta1402ec7346dc935cec1dc1a02eff3816d98ffc2 (diff)
downloadvyos-cloud-init-d45b0aacf88cf640dde538b3ee92958099129f74.tar.gz
vyos-cloud-init-d45b0aacf88cf640dde538b3ee92958099129f74.zip
This tool knows how to extract the current version from the 'changelog' file.
Diffstat (limited to 'tools/read-version')
-rwxr-xr-xtools/read-version51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/read-version b/tools/read-version
new file mode 100755
index 00000000..4458c712
--- /dev/null
+++ b/tools/read-version
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+# vi: ts=4 expandtab
+
+import os
+import sys
+import re
+
+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:
+ sys.stdout.write(versions[0].strip())
+ sys.exit(0)