code_lines.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:useful_script 作者: JyHu 项目源码 文件源码
def classify_count(prj, res, et, ef):
    if os.path.isdir(prj):      # ??????????
        files = os.listdir(prj)
        for file in files:
            if file.find('.') == 0: continue    # ??????
            loc = file.rfind('.')               # ????????
            fname = file[:(loc if loc != -1 else len(file))]        # ???
            ftype = file[(loc + 1 if loc != -1 else len(file)):]    # ????
            curp = prj + '/' + file                                 # ?????????
            if fname in origin_folder or ftype in origin_type or ftype in et or fname in ef: continue   # ??????????
            if os.path.isdir(curp): classify_count(curp, res, et, ef)       # ???????????????
            elif imghdr.what(curp): continue        # ??????????????
            else:
                try:
                    with open(curp, 'r') as f:
                        words = re.sub('\\s+(/\\*([.\\s\\S]*?)\\*/)|(//.*)', '', f.read())          # ????????????????
                        codelines = [line for line in words.split('\n') if len(line.strip()) > 0]   # ???????????????????
                        if not ftype in res.keys(): res[ftype] = 0      # ????
                        res[ftype] += len(codelines)
                        if not file_count_key in res.keys() : res[file_count_key] = 1
                        res[file_count_key] += 1
                        print('%5d  %s' % (len(codelines), curp))
                except Exception as e: print(curp, e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号