#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ru-4 源代码鉴别材料 重生成器(确定性、字节忠实)。 复刻 ru-4 既有格式:7 模块按目录字典序(ad→biz→community→compliance→feed→telemetry→trade), 模块内按相对 game-cloud 路径字典序;仅 src/main 下 .java; 分隔「// ===== 文件: <相对game-cloud路径> =====」;每文件 = 分隔行 + 源码行(splitlines,文件间无空行); 总行 = 文件数 + 物理行;取前 1500 + 后 1500,中间省略。 只读源码,产物写 /tmp/ru4_new.txt;打印逐文件/分模块/总计数,并落各模块清单表行 /tmp/ru4_tbl_*.md。""" import os, glob from collections import OrderedDict REPO = "/Users/lili/Project/games-development-ai" CLOUD = os.path.join(REPO, "game-cloud") # 目录字典序(与既有 .txt 起始 game-module-ad 一致) MODULES = ["game-module-ad", "game-module-biz", "game-module-community", "game-module-compliance", "game-module-feed", "game-module-telemetry", "game-module-trade"] SEP = "// ===== 文件: {rel} =====" files = [] # (module, rel_from_cloud, wcl, splitlines) no_trailing_nl = [] for m in MODULES: found = [] for j in glob.glob(os.path.join(CLOUD, m, "game-module-*", "src", "main", "**", "*.java"), recursive=True): found.append((os.path.relpath(j, CLOUD), j)) found.sort(key=lambda x: x[0]) for rel, j in found: raw = open(j, encoding="utf-8").read() wcl = raw.count("\n") # wc -l 口径 if raw and not raw.endswith("\n"): no_trailing_nl.append(rel) files.append((m, rel, wcl, raw.splitlines())) # splitlines:无文件间空行,总行=文件数+物理行 # 拼接(字节忠实:每文件=分隔行 + 源码各行) concat = [] for m, rel, wcl, sl in files: concat.append(SEP.format(rel=rel)) concat.extend(sl) total = len(concat) front = concat[:1500] back = concat[-1500:] omit_from, omit_to, omit_cnt = 1501, total - 1500, total - 3000 nfiles = len(files) nsrc = sum(f[2] for f in files) nonblank = sum(sum(1 for x in sl if x.strip() != "") for (m, rel, wcl, sl) in files) blank = nsrc - nonblank mod = OrderedDict() for m, rel, wcl, sl in files: e = mod.setdefault(m, [0, 0]); e[0] += 1; e[1] += wcl RULE = "=" * 80 header = [ "软件名称:绘境AI游戏分发变现与合规云服务系统 版本:V1.0", "说明:本鉴别材料为本软件原创业务源代码(Java,包名 com.wanxiang.huijing.game.module.*),按纳入文件目录字典序连续拼接。", "统计:纳入原创源文件 %d 个;连续有效代码(含文件分隔标记行)共 %d 行(其中物理代码行 %d 行、空白行 %d 行、非空白有效行 %d 行)。" % (nfiles, total, nsrc, blank, nonblank), "因总行数超过 3000 行,依软著登记规范取【前 1500 行 + 后 1500 行】,中间部分以分隔标识省略。完整文件清单见《源文件清单.md》。", "(已严格排除第三方与生成物:芋道(Yudao Cloud,MIT)基座 huijing-framework/gateway/module-system/module-infra/module-bpm/module-pay/server/dependencies、node_modules、target、各模块 src/test 测试代码、littlejsengine、spikes、*.min.js 等。)", ] out = header + [RULE, "【前 1500 行】"] + front \ + [RULE, "【中间部分省略:第 %d 行 至 第 %d 行,共省略 %d 行】" % (omit_from, omit_to, omit_cnt), RULE, "【后 1500 行】"] + back open("/tmp/ru4_new.txt", "w", encoding="utf-8").write("\n".join(out) + "\n") print("FILES=%d SRC_LINES=%d CONCAT=%d NONBLANK=%d BLANK=%d OMIT=%d (%d-%d) TXT_LINES=%d" % ( nfiles, nsrc, total, nonblank, blank, omit_cnt, omit_from, omit_to, len(out))) for m, (c, l) in mod.items(): print(" %-26s %d files / %d lines" % (m, c, l)) if no_trailing_nl: print(" [WARN 无尾换行]", no_trailing_nl) print(" BOUNDARY concat[1500]=%r" % (front[1499],)) # 各模块清单表行(刷新《源文件清单.md》用) for mm in MODULES: rows = ["| %s | %d |" % (rel, wcl) for (m, rel, wcl, sl) in files if m == mm] open("/tmp/ru4_tbl_%s.md" % mm, "w", encoding="utf-8").write("\n".join(rows) + "\n")