Linux下的代码统计工具--sloccount
来源:互联网 发布:腾讯视频网络电视版 编辑:程序博客网 时间:2024/06/05 06:52
转载自:http://www.cnblogs.com/visayafan/archive/2012/06/01/2529431.html,但是下边那个生成html文件的python代码有问题,还请大神赐教!
sloccount=Count Source Lines Of Code
官网:http://www.dwheeler.com/sloccount/
Ubuntu安装
sudo apt-get install sloccount
使用
sloccount [--version] [--cached] [--append] [ --datadir directory ] [--follow] [--duplicates] [--crossdups] [--autogen] [--multiproject] [--filecount] [--wide] [--details] [ --effort F E ] [ --schedule F E ] [ --personcost cost ] [ --overhead overhead ] [ --addlang language ] [ --addlangall ] [--] directories
--cached
跳过计算过程,直接使用上次结果
--multiproject
如果该文件夹包括一系列的子文件夹,而它们中的每一个都是相对独立开发的不同的项目,那么使用"--multiproject"选项,评估将会正确的考虑到这一点。
--filecount
显示文件数目而非代码行数
--details
显示每个源文件的详细信息
--duplicates
算上所有重复的(默认情况下如果文件有相同的内容,则只算一个)
--crossdups
如果顶目录包含几个不同的项目,并且你想把不同的项目下重复的文件在每个项目中都算上一次,则使用该选项。
转换成html文件
有一个sloc2html.py可以把生成的结果转换为带图形统计结果的html文件。 缺点是对中文支持不好。
例如:
sloccount . > result.txt
python sloc2html.py > result.html
再打开result.html即可看到结果形如:
sloc2html.py文件如下:
#!/usr/bin/env python# Written by Rasmus Toftdahl Olesen <rto@pohldata.dk># Modified slightly by David A. Wheeler# Released under the GNU General Public License v. 2 or higherfrom string import *import sysNAME = "sloc2html"VERSION = "0.0.2"if len(sys.argv) != 2: print "Usage:" print "\t" + sys.argv[0] + " <sloc output file>" print "\nThe output of sloccount should be with --wide and --multiproject formatting" sys.exit()colors = { "python" : "blue", "ansic" : "yellow", "perl" : "purple", "cpp" : "green", "sh" : "red", "yacc" : "brown", "lex" : "silver", # Feel free to make more specific colors. "ruby" : "maroon", "cs" : "gray", "java" : "navy", "ada" : "olive", "lisp" : "fuchsia", "objc" : "purple", "fortran" : "purple", "cobol" : "purple", "pascal" : "purple", "asm" : "purple", "csh" : "purple", "tcl" : "purple", "exp" : "purple", "awk" : "purple", "sed" : "purple", "makefile" : "purple", "sql" : "purple", "php" : "purple", "modula3" : "purple", "ml" : "purple", "haskell" : "purple" }print "<html>"print "<head>"print "<title>Counted Source Lines of Code (SLOC)</title>"print "</head>"print "<body>"print "<h1>Counted Source Lines of Code</h1>"file = open ( sys.argv[1], "r" )print "<h2>Projects</h2>"line = ""while line != "SLOC\tDirectory\tSLOC-by-Language (Sorted)\n": line = file.readline()print "<table>"print "<tr><th>Lines</th><th>Project</th><th>Language distribution</th></tr>"line = file.readline()while line != "\n": num, project, langs = split ( line ) print "<tr><td>" + num + "</td><td>" + project + "</td><td>" print "<table width=\"500\"><tr>" for lang in split ( langs, "," ): l, n = split ( lang, "=" ) print "<td bgcolor=\"" + colors[l] + "\" width=\"" + str( float(n) / float(num) * 500 ) + "\">" + l + "=" + n + " (" + str(int(float(n) / float(num) * 100)) + "%)</td>" print "</tr></table>" print "</td></tr>" line = file.readline()print "</table>"print "<h2>Languages</h2>"while line != "Totals grouped by language (dominant language first):\n": line = file.readline()print "<table>"print "<tr><th>Language</th><th>Lines</th></tr>"line = file.readline()while line != "\n": lang, lines, per = split ( line ) lang = lang[:-1] print "<tr><td bgcolor=\"" + colors[lang] + "\">" + lang + "</td><td>" + lines + " " + per + "</td></tr>" line = file.readline()print "</table>"print "<h2>Totals</h2>"while line == "\n": line = file.readline()print "<table>"print "<tr><td>Total Physical Lines of Code (SLOC):</td><td>" + strip(split(line,"=")[1]) + "</td></tr>"line = file.readline()print "<tr><td>Estimated development effort:</td><td>" + strip(split(line,"=")[1]) + " person-years (person-months)</td></tr>"line = file.readline()line = file.readline()print "<tr><td>Schedule estimate:</td><td>" + strip(split(line,"=")[1]) + " years (months)</td></tr>"line = file.readline()line = file.readline()print "<tr><td>Total estimated cost to develop:</td><td>" + strip(split(line,"=")[1]) + "</td></tr>"print "</table>"file.close()print "Please credit this data as \"generated using 'SLOCCount' by David A. Wheeler.\"\n"print "</body>"print "</html>"
0 0
- Linux下的代码统计工具--sloccount
- Linux | 代码统计工具SLOCCount
- sloccount 代码统计工具
- Linux下源代码行数统计工具(sloccount, cloc等)
- Mac下代码统计工具
- Linux下完成时间统计的代码
- Linux下统计代码行数的方法
- Linux下统计代码行数的方法
- Linux shell代码统计工具
- Mac OS 下统计代码行数的工具
- linux下统计代码行数
- Linux下统计代码行数
- LINUX下统计代码行数
- linux下统计代码行数
- LINUX下统计代码行数
- Linux下统计代码行数
- 统计代码量的工具。
- Linux下的一些I/O统计工具
- freemark语法
- mysql SQL Layer各个模块介绍
- tomcat启动时报错找不到mina的包
- XTU ACM 1195 Large Population 并查集->最小生成树
- 接口和抽象类有什么区别
- Linux下的代码统计工具--sloccount
- Xcode storyboard开发有感
- 使用HttpURLConnection的getContentLength()方法返回-1??
- Extjs中grid 的ColumnModel 属性配置
- 黑马程序员----集合框架(一)
- wcf的svcutil.exe工具生成代码的奇怪问题
- Zend Framework手册 中文版
- Javascript 模块化编程
- 用memset对非字符型数组初始化可能会出现错误