generated from lorossi/latex-notes-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
envsetup.py
executable file
·63 lines (47 loc) · 1.54 KB
/
envsetup.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pathlib import Path
from re import M, sub
from sys import argv
TEMP_FOLDERS = ["tikztemp"]
TEMP_EXTENSIONS = ["aux", "auxlock", "log", "pdf", "out", "toc"]
PLACEHOLDER_EXT = ".placeholder"
ARROW_STYLE = "{Triangle[scale=0.8]}"
def clean_styles() -> None:
"""cleans the tikzstyles file as it was created by tikzit"""
# load styles files
with open("tikzit.tikzstyles", "r") as f:
data = f.read()
# remove tikzit attributes
data = sub("tikzit [a-z]+=(([a-zA-Z]+)|(\{.+\}))(, ){0,1}", "", data)
# remove none fields
data = sub("[a-z]*=none(, ){0,1}", "", data)
# replace arrows
data = sub("[<>]", ARROW_STYLE, data)
# strip comments
data = sub("^%.*\n", "", data, flags=M)
# remove empty lines
data = sub("^\s*$\n", "", data, flags=M)
# save files
with open("tikzstyle.tikzstyles", "w") as f:
f.write(data)
def make_folder() -> None:
for f in TEMP_FOLDERS:
Path(f).mkdir(parents=True, exist_ok=True)
Path(f"{f}/{PLACEHOLDER_EXT}").touch()
def delete_folder() -> None:
for folder in TEMP_FOLDERS:
for file in Path(folder).iterdir():
file.unlink()
Path(folder).rmdir()
def delete_temp() -> None:
for e in TEMP_EXTENSIONS:
for file in Path(".").glob(f"*.{e}"):
file.unlink(missing_ok=True)
def main(argv: list[str]) -> None:
if "deletetemp" in argv:
delete_temp()
delete_folder()
if "cleanstyle" in argv:
clean_styles()
make_folder()
if __name__ == "__main__":
main(argv)