用pylint检查代码
来源:互联网 发布:如何提高淘宝搜索流量 编辑:程序博客网 时间:2024/04/30 06:35
'''Created on 2012-3-13@author: brian'''import osimport shutildef excute_pylint_cmd(file_path): pylint_cmd = "pylint \"%s\" --files-output=y --output-format=html --include-ids=y" % file_path print pylint_cmd os.system(pylint_cmd) #srccode_dir = r"E:\aaaa\bbbb"#pylint_report_dir = r"E:\PylintReport"def pylint_utility_process(srccode_dir, pylint_report_dir): pylint_global = "pylint_global.html" pylint_global_new = "pylint_global_%s.html" if not os.path.isdir(pylint_report_dir): os.mkdir(pylint_report_dir) for root, dirs, files in os.walk(srccode_dir): print root print dirs print files for name in files: file_name,ext_name = os.path.splitext(name) print file_name if ext_name.upper() == ".PY": file_path = os.path.join(root, name) if os.path.isfile(pylint_global): os.remove(pylint_global) excute_pylint_cmd(file_path) os.rename(pylint_global, pylint_global_new % file_name) target_pylint_path = pylint_report_dir + root[len(srccode_dir):len(root)] + r"\pylint_%s.html" target_pylint_global_path = pylint_report_dir + root[len(srccode_dir):len(root)] + r"\pylint_global_%s.html" if not os.path.isdir(pylint_report_dir + root[len(srccode_dir):len(root)]): os.mkdir(pylint_report_dir + root[len(srccode_dir):len(root)]) print target_pylint_path % file_name print target_pylint_global_path % file_name shutil.copy(r"pylint_%s.html" % file_name, target_pylint_path % file_name) shutil.copy(r"pylint_global_%s.html" % file_name, target_pylint_global_path % file_name) #delete source report files. os.remove(r"pylint_%s.html" % file_name) os.remove(r"pylint_global_%s.html" % file_name)