
* rename hpgit to git-upstream * rename import-upstream commadn to import * change all occurrences of hpgit and import-upstream in code, comments and tests * code cleanup (remove some typos, improve PEP8 compliance) * change license from "HP propietary" to "Apache License v2.0" Change-Id: Ia4f00d662d79ac9725316027a65f4d23ebbd0f02 JIRA:CICD-1319 JIRA:CICD-1318
87 lines
2.2 KiB
Python
87 lines
2.2 KiB
Python
#
|
|
# Copyright (c) 2011, 2012 OpenStack LLC.
|
|
# Copyright (c) 2012, 2013, 2014 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 subprocess
|
|
|
|
VERBOSE = os.environ.get('VERBOSE', False)
|
|
|
|
|
|
class CommandException(Exception):
|
|
pass
|
|
|
|
|
|
# following function is taken from git-review
|
|
def run_command(cmd, status=False, env=None):
|
|
if not env: env = {}
|
|
if VERBOSE:
|
|
print(datetime.datetime.now(), "Running:", cmd)
|
|
new_env = os.environ
|
|
new_env.update(env)
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT, env=new_env)
|
|
(out, nothing) = p.communicate()
|
|
if p.returncode:
|
|
raise CommandException
|
|
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 CommandException:
|
|
raise
|
|
|
|
return v
|
|
|
|
|
|
def git_upstream_version():
|
|
try:
|
|
from git_upstream import git_upstream_version
|
|
except ImportError:
|
|
raise
|
|
return git_upstream_version.version
|
|
|
|
|
|
def write_version_file():
|
|
try:
|
|
v = git_describe_version()
|
|
except:
|
|
return
|
|
print __name__
|
|
with open(os.path.join(os.path.dirname(__file__),
|
|
"git_upstream_version.py"), 'w') as f:
|
|
f.write("# Auto-generated file, do not edit by hand")
|
|
f.write("version = %s" % v)
|
|
|
|
|
|
def get_version():
|
|
for vfunc in git_upstream_version, git_describe_version:
|
|
try:
|
|
return vfunc()
|
|
except:
|
|
pass
|
|
|
|
return 'unknown-version'
|
|
|
|
|
|
version = get_version()
|