查找循环复杂度信息并导出文件
在测试代码的过程中,经常会遇到各种测试,例如循环复杂度测试等,这里通过遍历工具生成的文件,进行循环复杂度信息匹配,避免人为的重复劳作。
以下是python的代码,当然,该代码也可以通过修改部分参数来达到类似的需求的功能。
import os
import re
def deal_read_cycl(folder_in, file_out,regex_patt = r"\[V\]\sFunction\s'(.*?)'.*?:\s(\d+)",find_index = "index",show_prog = False):
'''
folder_in:Folder You Read
file_out: Result save in this file
regex_patt:regex patt
find_index:Just for you find
show_prog:print the process
'''
f_out = open(file_out,"w")
patt = re.compile(regex_patt)
for i in os.listdir(folder_in):
if os.path.isdir(os.path.join(folder_in,i)):
domain_name = i.split(".")[0]
#show log on screen
if show_prog:
print("-------->" + domain_name)
for j in os.listdir(os.path.join(folder_in,i)):
if find_index in j:
f_in = open(os.path.join(folder_in,i,j),"r").read()
for m in patt.finditer(f_in):
f_out.write(domain_name + "\t" + m.group(1) + "\t" + m.group(2) + "\n")
print("Find Ok")
f_out.close()
print(''' folder_in:Folder You Read
file_out: Result save in this file
regex_patt:regex patt(default:\[V\]\sFunction\s'(.*?)'.*?:\s(\d+))
find_index:Just for you find(default:index)
show_prog:print the process(default:False)
''')
ReadFolder = input("Please input Folder Test:")
WriteFile = input("Please input File to Write:")
deal_read_cycl(ReadFolder,WriteFile)