环境:windows/linux (python2编译器)
文件:
- cpplint_scanner.py —— 执行命令:python cpplint_scanner.py
- src_path.ini —— 配置文件,存储扫描目录
说明:生成cpplint.xml于扫描文件根目录中
#!/usr/bin/env python
import ConfigParser
import os, string, sys
print("==========begin of cpplint check==========")
def get_file(root_path, all_files):
files = os.listdir(root_path)
for file in files:
if not os.path.isdir(root_path + '/' + file): # not a dir
all_files.append(root_path + '/' + file)
else: # is a dir
get_file((root_path+'/'+file),all_files)
return all_files
cf = ConfigParser.ConfigParser()
cf.read("src_path.ini")
for item in cf.options('srcpath'):
rootdir = cf.get('srcpath', item)
list = os.listdir(rootdir)
print("len(list)", len(list),rootdir)
paths = get_file(rootdir,[]);
for path in paths:
str = "python cpplint_mod.py %(path)s >> %(item)s 2>&1"%{'path':path, 'item':item}
print("==========path==========", path)
os.system(str)
print("perl cpplintReport2checkstyleReport.perl" + item + " cpplint.xml")
command_str = "perl cpplintReport2checkstyleReport.perl" + item + " cpplint.xml"
os.system(command_str)
print(os.getcwd())
str = "mv cpplint.xml" + rootdir
print(str)
os.system(str)
print("==========end of cpplint check==========")
[srcpath]
report1.txt=D:\xxxx\xxxx1
report2.txt=D:\xxxx\xxxx2
report3.txt=D:\xxxx\xxxx3
report4.txt=D:\xxxx\xxxx4