Files
git-upstream/ghp/version.py
Darragh Bailey c9523f7a83 Insert correct copyright and licenses
Update copyright and licenses to note that code is HP proprietary and
has not been approved by the OSRB. Add comments noting where code has
been included from other projects and include the appropriate license
terms in the file header.

Change-Id: I2ce8c2d48e6f73d18d95fa073e5f962805121d1a
2013-07-24 07:45:27 +01:00

61 lines
1.5 KiB
Python

#
# Copyright (c) 2011, 2012 OpenStack LLC.
# Copyright (c) 2012, 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import os
import shlex
import subprocess
VERBOSE = os.environ.get('VERBOSE', False)
# following function is taken from git-review
def run_command(cmd, status=False, env={}):
if VERBOSE:
print(datetime.datetime.now(), "Running:", cmd)
cmd_list = shlex.split(str(cmd))
newenv = os.environ
newenv.update(env)
p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=newenv)
(out, nothing) = p.communicate()
out = out.decode('utf-8')
if status:
return (p.returncode, out.strip())
return out.strip()
def git_describe_version():
try:
v = run_command('git describe --tags --dirty')
except RuntimeError:
pass
return v
def get_version():
try:
return git_describe_version()
except:
pass
return 'unknown-version'
version = get_version()