Skip to content

Commit

Permalink
Merge tardyp/buildbot:getVersion (PR #1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Jul 23, 2014
2 parents 192259f + 3cba8b4 commit 410a87c
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions master/buildbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@

from __future__ import with_statement

# strategy:
#
# if there is a VERSION file, use its contents. otherwise, call git to
# get a version string. if that also fails, use 'latest'.
#
import os

version = "latest"

try:
fn = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'VERSION')
with open(fn) as f:
version = f.read().strip()

except IOError:
from subprocess import Popen, PIPE
import re

VERSION_MATCH = re.compile(r'\d+\.\d+\.\d+(\w|-)*')

# we can't put this method in utility modules, because they import dependancy packages.
def getVersion(init_file):
version = "latest"
try:
dir = os.path.dirname(os.path.abspath(__file__))
p = Popen(['git', 'describe', '--tags', '--always'], cwd=dir,
stdout=PIPE, stderr=PIPE)
out = p.communicate()[0]

if (not p.returncode) and out:
v = VERSION_MATCH.search(out)
if v:
version = v.group()
except OSError:
pass
cwd = os.path.dirname(os.path.abspath(init_file))
fn = os.path.join(cwd, 'VERSION')
version = open(fn).read().strip()

except IOError:
from subprocess import Popen, PIPE, STDOUT
import re

# accept version to be coded with 2 or 3 parts (X.Y or X.Y.Z),
# no matter the number of digits for X, Y and Z
VERSION_MATCH = re.compile(r'(\d+\.\d+(\.\d+)?)(\w|-)*')

try:
p = Popen(['git', 'describe', '--tags', '--always'], stdout=PIPE, stderr=STDOUT, cwd=cwd)
out = p.communicate()[0]

if (not p.returncode) and out:
v = VERSION_MATCH.search(out)
if v:
version = v.group(1)
except OSError:
pass
return version

version = getVersion(__file__)

0 comments on commit 410a87c

Please sign in to comment.