-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from billsacks/describe_version_git_fleximod
Improve describe_version for git-fleximod
- Loading branch information
Showing
1 changed file
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,67 @@ | ||
./bin/git-fleximod status | ||
#!/usr/bin/env python | ||
"""Describes the CESM version and any local modifications""" | ||
|
||
import os | ||
import argparse | ||
import subprocess | ||
|
||
def commandline_args(): | ||
"""Parse and return command-line arguments | ||
""" | ||
|
||
# We don't really need an argument parser, since there currently aren't any | ||
# arguments. But providing this allows supporting a '--help' option with a | ||
# description. | ||
|
||
description = """ | ||
Script for describing the CESM version and any local modifications | ||
Simply run: | ||
./describe_version | ||
without any arguments. | ||
You may want to redirect the output to a file, such as: | ||
./describe_version > current_version.txt | ||
""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description=description, | ||
formatter_class=argparse.RawTextHelpFormatter) | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
def main(): | ||
"""Main function for describe_version""" | ||
# We currently don't actually need any arguments, but call this to allow '--help' usage | ||
_ = commandline_args() | ||
|
||
# Allow this script to run correctly even if invoked from some other directory; note that | ||
# we assume that the script resides in the top level of the CESM checkout. | ||
cesmroot = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
separator = 72*'-' + '\n' | ||
|
||
# The '--long' option to git describe forces it to always show the hash, even if we're | ||
# on a tag. | ||
git_describe = subprocess.check_output(['git', 'describe', '--long'], | ||
cwd=cesmroot, | ||
universal_newlines=True) | ||
print(separator + 'git describe:\n' + git_describe + separator) | ||
|
||
git_status = subprocess.check_output(['git', 'status'], | ||
cwd=cesmroot, | ||
universal_newlines=True) | ||
print(separator + 'git status:\n' + git_status + separator) | ||
|
||
fleximod = os.path.join('bin', 'git-fleximod') | ||
fleximod_status = subprocess.check_output([fleximod, 'status'], | ||
cwd=cesmroot, | ||
universal_newlines=True) | ||
print(separator + 'git-fleximod status:\n' + fleximod_status + separator) | ||
|
||
if __name__ == "__main__": | ||
main() |