def dir_cmt_stat(): p1 = "/Users/apple/Documents/work1/cpp_repos/linux-master/security" pw = "./result/linux_dir_security.csv" w = open(pw, 'w') w.write("dir,cmt rate,code,comment\n") for i in os.listdir(p1): p = p1 + '/' + i if not os.path.isdir(p): continue arr = func.cpp_file_select(p) code = 0 comment = 0 for file in arr: a = '' with open(file) as f: a = f.read() b = func.code_line_num(a) code += b[0] comment += b[1] if code == 0: print("file " + p + " zero!!") w.write(p + ",NO CODE\n") else: print("Dir %s:\tcmt rate: %f\tcode: %d\tcomment: %d\t" % (p, comment / (code + comment), code, comment)) w.write(','.join([ p, str(comment / (code + comment)), str(code), str(comment) ]) + '\n')
#coding: utf-8 import os import func_match as fm import func #突然发现我的文件结构和你们不一样,我的result、opencv都在其他目录,你们注意改改 if __name__ == "__main__": path = "../cpp_repos/linux-master" file_paths = func.cpp_file_select(path) if not os.path.exists('result'): os.mkdir('result') w_have = open("./result/linux_func_with_comment.csv", 'w') w_not_have = open("./result/linux_func_without_comment.csv", 'w') w_have.write("path,func,comment\n") w_not_have.write("path,func\n") file_cnt = 0 for i in file_paths: file_cnt += 1 if file_cnt % 10==0: print("finished %d"%file_cnt) res = fm.extract_func(i) for flag, code, comment in res: if flag == 'Cmt':