|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import easygui as g
- import os
- def show_result(start_dir):
- lines = 0
- total = 0
- text = ""
- for i in source_list:
- lines = source_list[i]
- total += lines
- text += "【%s】源文件 %d 个,源代码 %d 行\n" %(i,file_list[i],lines)
-
- msg = "您目前一共累计编写了 %d 行代码,完成度:%.2f %%\n 离10万行代码还差 %d 行,请继续努力!" %(total,total/1000,100000-total)
- title = '统计结果'
- g.textbox(msg,title,text)
- def culc_code(file_name):
-
- lines = 0
- with open(file_name) as f:
- print('正在分析文件:%s...'%file_name)
- try :
- for each_line in f:
- lines += 1
- except UnicodeDecodeError:
- pass
- return lines
- def scan_dir(start_dir):
- os.chdir(start_dir)
- for file_name in os.listdir(os.curdir):
-
- ext = os.path.splitext(file_name)[1]
- if ext in target:
- lines = culc_code(file_name)
-
- try:
- file_list[ext] += 1
- except KeyError:
- file_list[ext] = 1
- try:
- source_list[ext] += lines
- except KeyError:
- source_list[ext] = lines
- if os.path.isdir(file_name):
- scan_dir(file_name)
- os.chdir(os.pardir)
-
- target = ['.c','.py']
- source_list = {}
- file_list ={}
- g.msgbox('请打开您存放所有代码的文件夹...','统计代码量')
- path = g.diropenbox('请选择你的代码库:','浏览文件夹')
-
- show_result(path)
- scan_dir(path)
-
复制代码
|
|