-
Notifications
You must be signed in to change notification settings - Fork 23
/
describe_version
executable file
·71 lines (52 loc) · 2.42 KB
/
describe_version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
"""Describes the CESM version and any local modifications"""
from __future__ import print_function
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 UFS 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 checkout.
ufsroot = 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', '--all'],
cwd=ufsroot,
universal_newlines=True)
print(separator + 'git describe:\n' + git_describe + separator)
git_status = subprocess.check_output(['git', 'status'],
cwd=ufsroot,
universal_newlines=True)
print(separator + 'git status:\n' + git_status + separator)
manic = os.path.join('manage_externals', 'checkout_externals')
# Give '--verbose' twice to give very verbose output, showing all modified files in
# each external.
manage_externals_status = subprocess.check_output([manic, '--status', '--verbose', '--verbose'],
cwd=ufsroot,
universal_newlines=True)
print(separator + 'manage_externals status:\n' + manage_externals_status + separator)
if __name__ == "__main__":
main()