美文网首页
统计项目代码行数

统计项目代码行数

作者: yousa_ | 来源:发表于2020-02-13 14:20 被阅读0次
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:ShidongDu time:2020/2/13
# -*- coding: utf-8 -*-
import os

# 需要统计的文件类型
exts = ['.py']
# 排除的文件夹
excludes = ["E:\PycharmProjects\test002\.idea"]

def get_line_count(file_name):
    line_count = 0
    with open('code_line_count.txt', 'a') as f:
        f.write('file_name : %s \n' % file_name)
    with open(file_name, 'r', encoding='utf8') as f:
        for file_line in f.readlines():
            file_line = file_line.strip()
            # if not len(file_line) or file_line.startswith('//'):
            #     continue
            line_count += 1
    with open('code_line_count.txt', 'a') as f:
        f.write('line count::%s\n' % line_count)
    return line_count


if __name__ == '__main__':
    with open('code_line_count.txt', 'w') as f:
        f.write('\n')
    count = 0
    file_count = 0
    for root, dirs, files in os.walk(os.getcwd()):
        for f in files:
            file_name = (root+'\\'+f)
            print(file_name)

            if os.path.dirname(file_name).split()[0] not in excludes:
                if os.path.splitext(f)[1]:
                    ext = f[f.rindex('.'):]
                    try:
                        if exts.index(ext) >= 0:
                            file_count += 1
                            c = get_line_count(file_name)
                            count += c
                            with open('code_line_count.txt', 'a') as f:
                                f.write('total count:%s\n' % count)
                    except:
                        pass

    with open('code_line_count.txt', 'a') as f:
        f.write('\n')
        f.write('--------------------------------------\n')
        f.write('total file count:%d\n' % file_count)
        f.write('total line count:%d\n' % count)

    import datetime
    with open('code_line_count_everyday.txt', 'a') as f:
        f.write('\n')
        f.write('--------------------------------------\n')
        now = datetime.datetime.now()
        now = str(now)
        f.write('date: ' + now +'\n')
        f.write('total file count:%d\n' % file_count)
        f.write('total line count:%d\n' % count)

相关文章

  • GIT统计代码量

    GIT统计代码量 Git统计个人提交代码行数 Git统计项目总行数 查看git上个人代码量(需要修改usernam...

  • 统计项目代码行数

    做开发这么久了,做项目这么久了。每天日出而作,日落而息。或加班加点,或通宵达旦赶进度。不知不觉中,每个类的代码行数...

  • 统计项目代码行数

    本文介绍了 3 种统计项目代码的方式,分别为 Cloc 库、VSCode 代码统计插件 —— VS Code Co...

  • 统计项目代码行数

  • 项目代码行数统计

    一、git命令统计 1、统计某人代码提交量 gitlog--author="mengfanxiao"--prett...

  • Git代码行数统计

    使用GitBash 1. 统计项目内所有代码行数 在代码路径下运行以下指令,可统计出当前仓库中的总代码行数: 输出...

  • Qt编写自定义控件69-代码行数统计

    一、前言 代码行数统计主要用来统计项目中的所有文件的代码行数,其中包括空行、注释行、代码行,可以指定过滤拓展名,比...

  • Qt开源作品10-代码统计组件

    一、前言 代码行数统计主要用来统计项目中的所有文件的代码行数,其中包括空行、注释行、代码行,可以指定过滤拓展名,比...

  • [code]统计项目代码量

    功能统计一个文件夹中所有指定后缀名文件中的数据行数 应用场景统计项目代码行数 代码 用例

  • iOS 项目代码行数统计

    1. 打开终端; 2. 通过cd命令到达我们的工程文件,这里注意如果要避免统计引用的第三方库的代码量,我们就要进一...

网友评论

      本文标题:统计项目代码行数

      本文链接:https://www.haomeiwen.com/subject/osokfhtx.html