~harlowja/cloud-init/ds-openstack

« back to all changes in this revision

Viewing changes to tools/read-version

  • Committer: Joshua Harlow
  • Date: 2014-02-07 23:14:26 UTC
  • mfrom: (913.1.22 trunk)
  • Revision ID: harlowja@yahoo-inc.com-20140207231426-2natgf64l4o055du
Remerged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
 
3
 
set -e
4
 
 
5
 
find_root() {
6
 
   local topd
7
 
   if [ -z "${CLOUD_INIT_TOP_D}" ]; then
8
 
      topd=$(cd "$(dirname "${0}")" && cd .. && pwd)
9
 
   else
10
 
      topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd)
11
 
   fi
12
 
   [ $? -eq 0 -a -f "${topd}/setup.py" ] || return
13
 
   ROOT_DIR="$topd"
14
 
}
15
 
fail() { echo "$0:" "$@" 1>&2; exit 1; }
16
 
 
17
 
if ! find_root; then
18
 
    fail "Unable to locate 'setup.py' file that should " \
19
 
         "exist in the cloud-init root directory."
20
 
fi
21
 
 
22
 
CHNG_LOG="$ROOT_DIR/ChangeLog"
23
 
 
24
 
if [ ! -e "$CHNG_LOG" ]; then
25
 
    fail "Unable to find 'ChangeLog' file located at '$CHNG_LOG'"
26
 
fi
27
 
 
28
 
VERSION=$(sed -n '/^[0-9]\+[.][0-9]\+[.][0-9]\+:/ {s/://; p; :a;n; ba; }' \
29
 
          "$CHNG_LOG") &&
30
 
   [ -n "$VERSION" ] ||
31
 
   fail "failed to get version from '$CHNG_LOG'"
32
 
echo "$VERSION"
 
1
#!/usr/bin/env python
 
2
 
 
3
import os
 
4
import re
 
5
import sys
 
6
 
 
7
if 'CLOUD_INIT_TOP_D' in os.environ:
 
8
    topd = os.path.realpath(os.environ.get('CLOUD_INIT_TOP_D'))
 
9
else:
 
10
    topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
 
11
 
 
12
for fname in ("setup.py", "ChangeLog"):
 
13
    if not os.path.isfile(os.path.join(topd, fname)):
 
14
        sys.stderr.write("Unable to locate '%s' file that should "
 
15
                         "exist in cloud-init root directory." % fname)
 
16
        sys.exit(1)
 
17
 
 
18
vermatch = re.compile(r"^[0-9]+[.][0-9]+[.][0-9]+:$")
 
19
 
 
20
with open(os.path.join(topd, "ChangeLog"), "r") as fp:
 
21
    for line in fp:
 
22
        if vermatch.match(line):
 
23
            sys.stdout.write(line.strip()[:-1] + "\n")
 
24
            break
 
25
 
 
26
sys.exit(0)