25 lines
858 B
Python
Raw Normal View History

"""
get project files by "git ls-files" command
如果项目文件数超出100那么结束执行退出码为1并且输出英文文件数太多需要通过ls命令逐层查看各个目录中的文件目录结构信息
"""
import subprocess
import sys
def get_project_tree():
"""
Get project files by "git ls-files" command
"""
try:
output = subprocess.check_output(["git", "ls-files"]).decode("utf-8").split("\n")
if len(output) > 100:
sys.stderr.write("Error: Too many files, you need to view the files and directory structure in each directory through the 'ls' command.\n")
sys.exit(1)
return output
except Exception as e:
sys.stderr.write(f"Error: {str(e)}\n")
sys.exit(1)
if __name__ == "__main__":
print(get_project_tree())
sys.exit(0)