diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-08-30 13:57:05 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-08-30 13:57:05 +0200 |
| commit | 52c50b7299efb2050794ac589902af325156f7c3 (patch) | |
| tree | 2b4bc8f30c8fed814b3483fb6c6ebf24bb2f246a /src/util.py | |
| parent | bd05bc364bdab25b2f55dd5b5831e9f13cc16aea (diff) | |
| download | allocbench-52c50b7299efb2050794ac589902af325156f7c3.tar.gz allocbench-52c50b7299efb2050794ac589902af325156f7c3.zip | |
add --version flag to executables
Diffstat (limited to 'src/util.py')
| -rw-r--r-- | src/util.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util.py b/src/util.py index 9941d6f..6ec984a 100644 --- a/src/util.py +++ b/src/util.py @@ -145,3 +145,26 @@ def print_license_and_exit(): print("Copyright (C) 2018-2019 Florian Fischer") print("License GPLv3: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>") exit(0) + + +def print_version_and_exit(): + """Print current commit info before exit""" + proc = subprocess.run(["git", "rev-parse", "HEAD"], + universal_newlines=True, stdout=subprocess.PIPE) + + if proc.returncode != 0: + print_error("git rev-parse failed") + exit(1) + commit = proc.stdout[:-1] + + proc = subprocess.run(["git", "status", "--porcelain"], + universal_newlines=True, stdout=subprocess.PIPE) + + if proc.returncode != 0: + print_error("git status --porcelain failed") + exit(1) + + dirty = "-dirty" if proc.stdout != "" else "" + + print(f"{commit}{dirty}") + exit(0) |
