This action will force synchronization from zhlei/PySide6-Code-Tutorial, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
"""调用cloc代码行数统计工具统计本项目代码量的脚本https://github.com/AlDanial/cloc"""import pathlibfrom os import popen# 配置项Git_Ignore_File = "../.gitignore" # gitignore文件路径,用以排除不需要列目录的文件Project_Root_Path = "../" # 项目根目录路径# 配置项完def cloc(gitignore_file: str = ".gitignore") -> None:"""使用cloc统计项目代码行数 \n:param gitignore_file: gitignore文件路径:return: None"""ignored_dir = ""gitignore_file_p = pathlib.Path(gitignore_file)with gitignore_file_p.open("r", encoding="UTF-8") as f:for dir_name in f.readlines():if not dir_name.startswith("#"):dir_name = dir_name.replace("/", "").replace("\n", ",")ignored_dir += dir_name# 调用cloc,并排除gitignore中的目录,需要提前将cloc添加到系统环境变量cmd = f"cloc --exclude-dir {ignored_dir}{Project_Root_Path}"with popen(cmd) as p:cmd_result = p.read()# 如果cmd执行正常退出则p.close()返回None,失败则返回状态码if p.close():print("cloc调用失败,请检查")else:# 根据cloc返回结果,连续两个换行符后面的内容是需要的信息cloc_result = cmd_result.split("\n\n", 1)[1]print(cloc_result)# TODO 将 self.cloc_result 写入 Markdown 文件if __name__ == "__main__":cloc(Git_Ignore_File)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。