forked from Mini-Conf/Mini-Conf
-
Notifications
You must be signed in to change notification settings - Fork 12
/
generate_version.py
37 lines (28 loc) · 944 Bytes
/
generate_version.py
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
from __future__ import print_function
import json
import subprocess
import sys
from time import strftime
def get_version_info():
now = strftime("%Y-%m-%d %H:%M:%S")
# If we would like the short form, add '--short' option
# sha = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'])
sha = subprocess.check_output(["git", "rev-parse", "HEAD"])
# For Python3, convert bytes to str
sha = sha.decode() if isinstance(sha, bytes) else sha
sha = sha.strip()
version = {"date": now, "sha": sha}
return json.dumps(version, indent=4)
def show_usage():
print("Usage: python[3] %s output_file" % sys.argv[0])
def writeFile(path, string):
f = open(path, "w")
f.write(string)
f.close()
if __name__ == "__main__":
if len(sys.argv) == 2:
file_path = sys.argv[1]
json_string = get_version_info()
writeFile(file_path, json_string)
else:
show_usage()