Add python script to build files
This commit is contained in:
parent
349f1df7f3
commit
e2c6943e89
1 changed files with 46 additions and 0 deletions
46
build.py
Executable file
46
build.py
Executable file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import pathlib
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
CWD = pathlib.Path(os.getcwd())
|
||||||
|
BASE_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
TEMPLATE_FILE = BASE_DIR / 'main.tex'
|
||||||
|
OUTPUT_FILE = CWD / 'output.pdf'
|
||||||
|
CONTEXT_FILE = CWD / 'context.yaml'
|
||||||
|
BUILD_PASSES = 2
|
||||||
|
|
||||||
|
|
||||||
|
def build(input_file: pathlib.Path):
|
||||||
|
build_args = ['pandoc', str(input_file)]
|
||||||
|
|
||||||
|
if CONTEXT_FILE.exists():
|
||||||
|
build_args.append(str(CONTEXT_FILE))
|
||||||
|
|
||||||
|
build_args.extend([
|
||||||
|
'--template',
|
||||||
|
str(TEMPLATE_FILE),
|
||||||
|
'-o',
|
||||||
|
str(OUTPUT_FILE)
|
||||||
|
])
|
||||||
|
return subprocess.run(build_args, cwd=str(BASE_DIR), check=True)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args(args=None):
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-v", "--verbose", help="Set verbosity level (repeat argument)", action="count", default=0)
|
||||||
|
parser.add_argument("input", help="Input File", action='store', type=pathlib.Path,)
|
||||||
|
parser.add_help = True
|
||||||
|
return parser.parse_args(args=args)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = parse_args()
|
||||||
|
input_file = args.input.resolve()
|
||||||
|
if not input_file.is_file():
|
||||||
|
raise ValueError("Failed to find {}".format(input_file))
|
||||||
|
for i in range(2):
|
||||||
|
print("Building pass {}.".format(i + 1))
|
||||||
|
build(input_file)
|
Reference in a new issue