| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- # -*- coding: utf-8 -*-
- """统计交付物的真实规模(行数/文件数),供文档引用。"""
- import os
- ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- SKIP_DIRS = {"build", "build-cmake", "runs", "__pycache__", ".git", "--no-plc"}
- def walk(sub, exts):
- files = 0
- lines = 0
- base = os.path.join(ROOT, sub)
- for dirpath, dirnames, filenames in os.walk(base):
- dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
- for fn in filenames:
- if not fn.endswith(exts):
- continue
- files += 1
- try:
- with open(os.path.join(dirpath, fn), "r", encoding="utf-8",
- errors="ignore") as fh:
- lines += sum(1 for _ in fh)
- except OSError:
- pass
- return files, lines
- GROUPS = [
- ("portcv (py)", "portcv", (".py",)),
- ("scripts (py)", "scripts", (".py",)),
- ("tests (py)", "tests", (".py",)),
- ("cpp (cpp)", "cpp", (".cpp",)),
- ("cpp (hpp/h)", "cpp", (".hpp", ".h")),
- ("docs (md)", "docs", (".md",)),
- ("deploy", "deploy", (".service", ".conf", ".md", ".yaml", ".txt")),
- ("configs (json)", "configs", (".json",)),
- ]
- if __name__ == "__main__":
- total = 0
- for name, sub, exts in GROUPS:
- f, ln = walk(sub, exts)
- total += ln
- print("%-14s %4d files %7d lines" % (name, f, ln))
- top_md = [fn for fn in os.listdir(ROOT) if fn.endswith(".md")]
- print("root md:", top_md)
- print("total lines:", total)
|