diff options
author | Scott Moser <smoser@brickies.net> | 2016-08-09 02:59:29 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-08-09 02:59:29 -0400 |
commit | 537477335449c7730633d321905c57f694441eb3 (patch) | |
tree | 1984dcd6866a7d154f54a76eb0795cae0cd4b537 /tools/read-version | |
parent | b56d7a191fc695be364430f8428a17591c523403 (diff) | |
download | vyos-cloud-init-537477335449c7730633d321905c57f694441eb3.tar.gz vyos-cloud-init-537477335449c7730633d321905c57f694441eb3.zip |
read-version: do not attempt git-describe if no git.
Even if there is a .git directory, we can't use git if there
is no git executable in the path. In that case just fall back
to the cloud-init version.
Diffstat (limited to 'tools/read-version')
-rwxr-xr-x | tools/read-version | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/read-version b/tools/read-version index 85c62343..5ecf7247 100755 --- a/tools/read-version +++ b/tools/read-version @@ -26,6 +26,25 @@ def tiny_p(cmd, capture=True): return out +def which(program): + # Return path of program for execution if found in path + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + _fpath, _ = os.path.split(program) + if _fpath: + if is_exe(program): + return program + else: + for path in os.environ.get("PATH", "").split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + return None + + use_long = '--long' in sys.argv or os.environ.get('CI_RV_LONG') use_tags = '--tags' in sys.argv or os.environ.get('CI_RV_TAGS') output_json = '--json' in sys.argv @@ -33,7 +52,7 @@ output_json = '--json' in sys.argv src_version = ci_version.version_string() version_long = None -if os.path.isdir(os.path.join(_tdir, ".git")): +if os.path.isdir(os.path.join(_tdir, ".git")) and which("git"): flags = [] if use_tags: flags = ['--tags'] |