-
Notifications
You must be signed in to change notification settings - Fork 0
/
stex_to_png.py
52 lines (29 loc) · 1.06 KB
/
stex_to_png.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
import os
import sys
import re
def process_directoy(path_to_directory: str):
for root, subDirs, files in os.walk(path_to_directory):
for file in files:
process_file(root, file)
for subDir in subDirs:
process_directoy(os.path.join(root, subDir.title()))
def process_file(path_to_dir: str, file_name: str):
if not file_name.endswith(".stex"):
return
new_file_name: str = re.sub("png-.*\\.stex", "png", file_name)
path_to_file: str = os.path.join(path_to_dir, file_name)
source_file = open(path_to_file, "rb")
read_bytes = source_file.read()
write_bytes = read_bytes[32:]
path_to_target_file = os.path.join(path_to_dir, new_file_name)
target_file = open(path_to_target_file, "wb")
target_file.write(write_bytes)
source_file.close()
target_file.close()
def main():
if len(sys.argv) != 2:
raise Exception("Wrong number of arguments. Are you missing a target?")
target_path = sys.argv[1]
process_directoy(target_path)
if __name__ == "__main__":
main()