-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_buildinfo.py
More file actions
41 lines (34 loc) · 1.2 KB
/
gen_buildinfo.py
File metadata and controls
41 lines (34 loc) · 1.2 KB
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
# Generates build information for LaTeX
#
# @author Connor Henley, @thatging3rkid
import datetime
import subprocess
def sanitize(s):
"""
Sanitize a given string for use in LaTeX
:param: s the string to sanitize
:returns: a LaTeX-safe string
"""
s = s.replace("_", "\\_")
return s
def main():
# first, print some debugging infro
print("%%% buildinfo.tex\n%%%\n%%% Generated by gen_buildinfo.py on " + str(datetime.datetime.now()) + "\n")
# next, get the current git state
git_describe = "*error\\_getting\\_version*"
git_branch = "*branch\\_error*"
try:
git_describe = subprocess.check_output(["git", "describe", "--tags", "--long"]).strip().decode("utf-8")
git_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode("utf-8")
except:
pass
# we need to sanitize the inputs
git_describe = sanitize(git_describe)
git_branch = sanitize(git_branch)
# finally, print the footers
footer = "version: \\texttt{"+ git_describe +"}";
if git_branch != "master":
footer += " on branch \\texttt{"+ git_branch +"}"
print("\\lfoot{" + footer + "}")
if __name__ == "__main__":
main()