-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclang_format_all.py
48 lines (39 loc) · 1.09 KB
/
clang_format_all.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
import os
from subprocess import call
clang_paths = ('C:\\Program Files\\LLVM\\bin\\clang-format.exe', 'C:\\Program Files (x86)\\LLVM\\bin\\clang-format.exe')
for path in clang_paths:
if os.path.isfile(path):
clang_format_path = path
break
exclude_dirs = [
"project/libs"
]
allowed_file_suffixes = [
".c",
".h",
".hpp",
".cpp"
]
def isExcluded(filenameToTest):
filenameToTest = filenameToTest.replace(os.sep, "/")
extension = os.path.splitext(filenameToTest)[1].lower()
extensionMatches = False
if extension in allowed_file_suffixes:
pass
else:
return True
for exclude_dir in exclude_dirs:
if filenameToTest.startswith( "./"+exclude_dir ):
#print(filenameToTest)
return True
return False
for subdir, dirs, files in os.walk("."):
for file in files:
#print os.path.join(subdir, file)
filepath = subdir + os.sep + file
if isExcluded(filepath):
pass
else:
print (filepath)
#print(clang_format_path)
call([clang_format_path, "-i",filepath])