-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·37 lines (34 loc) · 1.31 KB
/
main.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
#!/usr/bin/env python3
import json
import argparse
import glob
import os
from src.generator import generate_pld
from pathlib import Path
from src.schema import PLDSchema, LocaleDictionary
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--schema", help="only generate json schema", action='store_true')
args = parser.parse_args()
if args.schema:
with open("pld_schema.json", "w") as file:
file.write(PLDSchema.schema_json(indent=2))
with open("locale_schema.json", "w") as file:
file.write(LocaleDictionary.schema_json(indent=2))
else:
schema_args = json.load(open(glob.glob("assets/*.json")[0]))
schema = PLDSchema(**schema_args)
locale_args = json.load(open(str(Path("src/locale").joinpath(f"{schema.locale.value}.json"))))
locale = LocaleDictionary(**locale_args)
document = generate_pld(schema, locale)
tex_filepath = "build/pld.tex"
pdf_filepath = "build/pld.pdf"
try:
os.mkdir("build")
except FileExistsError:
pass
document.generate_tex(tex_filepath)
document.generate_pdf(pdf_filepath, clean_tex=True)
print(f"LaTeX file saved at ./{tex_filepath}")
print(f"PDF file saved at ./{pdf_filepath}")
quit(0)