Skip to content

Commit

Permalink
Synchronize __init__.py between buildbot and buildslave
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-sezemsky committed Feb 5, 2015
1 parent 61f8156 commit 489308b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
25 changes: 14 additions & 11 deletions master/buildbot/__init__.py
Expand Up @@ -12,14 +12,21 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

#
# Keep in sync with slave/buildslave/__init__.py
#
# We can't put this method in utility modules, because they import dependancy packages
#
from __future__ import with_statement

import os
import re


# we can't put this method in utility modules, because they import dependancy packages.
def getVersion(init_file):
"""
Return BUILDBOT_VERSION environment variable, content of VERSION file, git
tag or 'latest'
"""

try:
return os.environ['BUILDBOT_VERSION']
except KeyError:
Expand All @@ -28,9 +35,7 @@ def getVersion(init_file):
try:
cwd = os.path.dirname(os.path.abspath(init_file))
fn = os.path.join(cwd, 'VERSION')
with open(fn) as vfile:
version = vfile.read().strip()
return version
return open(fn).read().strip()
except IOError:
pass

Expand All @@ -41,19 +46,17 @@ def getVersion(init_file):
# no matter the number of digits for X, Y and Z
VERSION_MATCH = re.compile(r'(\d+\.\d+(\.\d+)?)(\w|-)*')

version = 'latest'

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)
return v.group(1)
except OSError:
pass

return version
return "latest"

version = getVersion(__file__)
22 changes: 13 additions & 9 deletions slave/buildslave/__init__.py
Expand Up @@ -12,16 +12,21 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

# strategy:
#
# if there is a VERSION file, use its contents. otherwise, call git to
# get a version string. if that also fails, use 'latest'.
# Keep in sync with master/buildbot/__init__.py
#
# We can't put this method in utility modules, because they import dependancy packages
#
from __future__ import with_statement
import os

import re

def getVersion(init_file):
"""
Return BUILDBOT_VERSION environment variable, content of VERSION file, git
tag or 'latest'
"""

try:
return os.environ['BUILDBOT_VERSION']
except KeyError:
Expand All @@ -30,8 +35,7 @@ def getVersion(init_file):
try:
cwd = os.path.dirname(os.path.abspath(init_file))
fn = os.path.join(cwd, 'VERSION')
version = open(fn).read().strip()
return version
return open(fn).read().strip()
except IOError:
pass

Expand All @@ -49,10 +53,10 @@ def getVersion(init_file):
if (not p.returncode) and out:
v = VERSION_MATCH.search(out)
if v:
version = v.group(1)
return version
return v.group(1)
except OSError:
pass

return "latest"

version = getVersion(__file__)

0 comments on commit 489308b

Please sign in to comment.