-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathclang-format.py
34 lines (29 loc) · 1021 Bytes
/
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
import os
import os.path
import subprocess
extList = set(["cpp","cc","h"])
cppDir = ["base","tools","ctpgateway","datafeed","datarecorder","btgateway","cta"]
def clangformat(filePath):
cmdline = ["clang-format.exe","-style","WebKit",filePath]
child = subprocess.Popen(cmdline,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
output,error = child.communicate()
if error:
print error
return
with open(filePath,"wb") as f:
f.write(output)
def formatDir(dirPath):
for root,dirs,files in os.walk(dirPath):
for name in files:
if name.lower().endswith(".pb.cc"):
continue
if name.lower().endswith(".pb.h"):
continue
ext = os.path.splitext(name)[1][1:]
if ext.lower() in extList:
cpp = os.path.join(root, name)
print cpp
clangformat(cpp)
if __name__ == '__main__':
for path in cppDir:
formatDir(path)