-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapply_clang_format.py
76 lines (61 loc) · 1.93 KB
/
apply_clang_format.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
64
65
66
67
68
69
70
71
72
73
74
75
76
def allowed_extensions():
return [
"c",
"cpp",
"h",
"hpp",
"inl",
"tpp",
"glsl",
"frag",
"vert",
"comp",
"geom",
"tese",
"tesc",
]
def extension(file):
from pathlib import Path
return Path(file).suffix.strip('.')
def run_clang_format_on_one_folder(folder, ignored=[], print_result=True):
import os
from os import listdir
from os.path import join, isfile
for file in listdir(folder):
path = join(folder, file)
if isfile(path) and extension(path) in allowed_extensions() and not file in ignored:
if (print_result):
print(path)
os.chdir(folder)
os.system(f"clang-format -style=file -i {file}")
def run_clang_format_on_folder(folder, ignored=[], print_result=True):
import os
for subfolder in [x[0] for x in os.walk(folder)]:
run_clang_format_on_one_folder(subfolder, ignored, print_result)
def parent_folder():
from pathlib import Path
return Path(__file__).parent.parent
def apply_clang_format(folder, ignored=[], print_result=True):
import os
if print_result:
from termcolor import colored
path = os.path.join(parent_folder(), folder)
if (os.path.isdir(path)):
if print_result:
print(colored(
f"Applying clang-format on '{folder}' (Full path: '{path}')",
'green'))
run_clang_format_on_folder(path, ignored, print_result)
else:
if print_result:
print(colored(
f"Applying clang-format on '{folder}' FAILED. We did not find '{path}'",
'red'))
if __name__ == '__main__':
apply_clang_format('src')
apply_clang_format('include')
apply_clang_format('res')
apply_clang_format('test')
apply_clang_format('tests')
apply_clang_format('example')
apply_clang_format('examples')