Mac OS X代码量统计程序(Python版)
方便统计各种平台项目的代码量,主要用到了find指令来进行处理的详情点击打开链接;
源代码下载点击打开链接
源代码如下:
# -*- coding: utf-8 -*- ''' Created on Jul 18, 2014 @author: Jayhomzhou @note: 计算注释以及代码的总行数(即代码量) ''' import subprocess def countCodes(codePath, fileTypes): typeStrs = '' for ft in fileTypes: typeStrs += ' -name "*.' + ft +'" -or' if len(typeStrs) > 0: typeStrs = typeStrs[0:len(typeStrs)-3]#去除最后面的'-or'字符 countOrder = 'find ' + codePath + ' ' + typeStrs + ' |xargs grep -v "^$"|wc -l'#grep -v "^$"是去掉空行 print(countOrder) codeLinesCount = "0" pOrder = subprocess.Popen(countOrder, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in pOrder.stdout.readlines(): codeLinesCount = line.decode().replace('\n','').strip() break; return codeLinesCount if __name__ == '__main__': print("Counting...") codePath = input("Please input the codePath:\n") if len(codePath) == 0: codePath = './' fileTypes = input("Please input the file types:\niOS(m,h,cpp,xib,mm)\njava(java,xml)\nWP(cs,xaml)\n") if len(codePath) and len(fileTypes): print('Line\'s Count:' + countCodes(codePath, fileTypes.split(','))) else: print('Command is empty!') print("Count end!")
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。