码迷,mamicode.com
首页 > 编程语言 > 详细

Mac OS X代码量统计程序(Python版)

时间:2014-07-21 16:38:02      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:源代码统计

方便统计各种平台项目的代码量,主要用到了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!")

Mac OS X代码量统计程序(Python版)

标签:源代码统计

原文地址:http://blog.csdn.net/thirtydevs/article/details/38019389

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!