forked from abolybook/aboly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildly.py
40 lines (33 loc) · 1.2 KB
/
buildly.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
38
39
40
#!/usr/bin/env python3
# coding: utf-8
from __future__ import unicode_literals, print_function
import os
import subprocess
import sys
def main():
BUILD_CMD = ['xelatex', r'\newcommand{\buildnoly}{%d} \newcommand{\lycommitno}{%s} \input{ly.tex}']
COMMITNO_CMD = ['git', 'rev-parse', 'HEAD']
BUILDNO_FILE = 'buildnoly.txt' # shabby toy of my own; not included in the GitHub project
if subprocess.call([sys.executable, 'autolybody.py']) != 0:
print("Failed to run autolybody.py", file=sys.stderr)
return 1
buildno = 0
use_buildno_file = os.path.isfile(BUILDNO_FILE)
if use_buildno_file:
try:
with open(BUILDNO_FILE) as fin:
buildno = int(fin.read()) + 1
except Exception:
use_buildno_file = False
try:
commitno = subprocess.check_output(COMMITNO_CMD).strip().decode('ascii')
except subprocess.CalledProcessError:
commitno = 0
BUILD_CMD[1] = BUILD_CMD[1] % (buildno, commitno)
r = subprocess.call(BUILD_CMD)
if r == 0 and use_buildno_file:
with open(BUILDNO_FILE, 'w') as fout:
fout.write(str(buildno))
return r
if __name__ == '__main__':
sys.exit(main())