统计svn上的项目的java代码数量

需要统计一下svn上项目的代码的数量,具体应该怎么做呢?
第一步:编辑脚本将所有的svn的项目的源码拉到指定的目录下面。

rm -rf /tmp/svntest
mkdir /tmp/svntest
i=1
while read line
do
cd /tmp/svntest
mkdir /tmp/svntest/$i
cd /tmp/svntest/$i
svn checkout --username="XXXX" --password=XXXX 

第二步:编写统计文件行数的脚本

$line > /dev/null
repo=`echo ${line##*/}`
cd $repo
echo $line
line=`find . -type f -name "*.java" -o -name "*.jsp" -o -name "*.html" -o -name "*.js" | xargs cat | egrep -v '^\s+*$'| wc -l`
file=`find . -type f -name "*.java" -o -name "*.jsp" -o -name "*.html" -o -name "*.js" | xargs ls -tl | wc -l`
echo "java_file_number: $file code_line: $line"
let i=$i+1

以下是完整的脚本代码:

#!/bin/bash
rm -rf /tmp/svntest
mkdir /tmp/svntest
i=1
while read line
do
cd /tmp/svntest
mkdir /tmp/svntest/$i
cd /tmp/svntest/$i
svn checkout --username="XXXX" --password=XXXX $line > /dev/null
repo=`echo ${line##*/}`
cd $repo
echo $line
line=`find . -type f -name "*.java" -o -name "*.jsp" -o -name "*.html" -o -name "*.js" | xargs cat | egrep -v '^\s+*$'| wc -l`
file=`find . -type f -name "*.java" -o -name "*.jsp" -o -name "*.html" -o -name "*.js" | xargs ls -tl | wc -l`
echo "java_file_number: $file code_line: $line"
let i=$i+1
done << Eof
http://XXXXX/geexek/enroll
http://XXXXX/geexek/mainsite/trunk/geexek
http://XXXXX/geexek/toolbox/integration
http://XXXXX/geexek/toolbox/rmiupload/src
http://XXXXX/geexek/cmptservice/trunk/orienteering
http://XXXXX/geexek/enroll/managex
http://XXXXX/geexek/enroll/branches/dev_1.0/managements
http://XXXXX/corun/Server/DEyesServer/branches/Geexek-branch/GeexekApp
http://XXXXX/corun/Server/DEyesServer/branches/Geexek-branch/gWeexServer
Eof

第三步、将整理好的txt文件,通过脚本,转化成csv文件方便统计。

import pandas as pd
import numpy as np
import re

rePattern = re.compile("\d+")

resDic = {
    'project':[],
    'javaFiles':[],
    'javaLines':[],
    'csFiles':[],
    'csLines':[],
    'jsFiles':[],
    'jsLines':[],
    'jspFiles':[],
    'jspLines':[],
    'htmlFiles':[],
    'htmlLines':[]
}

def findResult(name,eachLine):
    res = re.findall(rePattern,str(eachLine))
    resDic[name+'Files'].append(res[0])
    resDic[name+'Lines'].append(res[1])
    return 


if __name__ == "__main__":
        
    with open('./代码统计.txt','r') as f:
        for eachLine in f:
            if "==" in eachLine:
                continue
            if "http" in eachLine and "svn" not in eachLine:
    #             print(eachLine.split("/")[-1])
                eachLine = eachLine.strip("\n")
                resDic['project'].append(eachLine.split("/")[-1])
                continue
            if "java" in eachLine:
                findResult('java',eachLine)
                continue
            if "cs" in eachLine:
                findResult('cs',eachLine)
                continue
            if "js" in eachLine and "jsp" not in eachLine:
                findResult('js',eachLine)
                continue
            if "jsp" in eachLine:
                findResult("jsp",eachLine)
                continue
            if "html" in eachLine:
                findResult("html",eachLine)
                
    df = pd.DataFrame(resDic)
    df.to_csv("sum.csv")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值