#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ru-1 源代码鉴别材料 重生成器(修截断边界 bug:前段第1500行被空行替换 + 省略区间标注差一)。 规则取自 docs/ip/ruanzhu-1-game-studio/源文件清单.md + .txt 头部: game-studio/src 下 .ts/.vue/.css(排 .d.ts),按相对 game-studio/ 的路径字典序; 每文件前置「/* ======== 文件: ======== */」;文件尾换行形成块间空行;取前1500+后1500。 只读源码,产物写 /tmp/ru1_new.txt(字节忠实);打印计数与边界行。""" import os, glob REPO = "/Users/lili/Project/games-development-ai" ROOT = os.path.join(REPO, "game-studio") SRC = os.path.join(ROOT, "src") EQ = "=" * 80 SEP = "/* ======== 文件:%s ======== */" files = [] for p in glob.glob(os.path.join(SRC, "**", "*"), recursive=True): if not os.path.isfile(p): continue if not (p.endswith(".ts") or p.endswith(".vue") or p.endswith(".css")): continue if p.endswith(".d.ts"): continue files.append((os.path.relpath(p, ROOT), p)) # rel = src/App.vue ... files.sort(key=lambda x: x[0]) concat, nsrc = [], 0 for rel, p in files: raw = open(p, encoding="utf-8").read() nsrc += raw.count("\n") # wc -l 口径 concat.append(SEP % rel) concat.extend(raw.split("\n")) # 末元素 ''(文件尾换行)= 块间空行 total = len(concat) front, back = concat[:1500], concat[-1500:] omit_to = total - 1500 nfiles = len(files) hdr = [ "软件名称:绘境AI游戏创作工作室系统[前端] 版本:V1.0", "(源代码鉴别材料 · 简体中文 · 用于中国版权保护中心软件著作权登记)", "说明:本材料为本软件原创源代码连续摘录。原创源代码有效合计 %d 行,分布于 %d 个源文件(已排除 node_modules、dist、public 静态资源、*.min.js、自动生成的 .d.ts 等第三方与生成物);为标注每个文件归属,材料中另插入了 %d 行「文件分隔注释行」,故连续行号上限为 %d。" % (nsrc, nfiles, nfiles, total), "按软著规范取前 1500 行 + 后 1500 行(每页≥50 行,约 60 页)。每个源文件以「/* ======== 文件:相对路径 ======== */」分隔。转 PDF 时每页页眉标注「绘境AI游戏创作工作室系统[前端] V1.0」并附页码。", ] mid = ["", EQ, "【中间略:完整源代码共 %d 行,此处省略第 1501 行至第 %d 行,下接后 1500 行】" % (total, omit_to), EQ, "", EQ, "【后 1500 行】", EQ, ""] out = hdr + [EQ, "【前 1500 行】", EQ, ""] + front + mid + back open("/tmp/ru1_new.txt", "w", encoding="utf-8").write("\n".join(out) + "\n") print("FILES=%d SRC_LINES=%d CONCAT=%d OMIT=1501-%d TXT=%d" % (nfiles, nsrc, total, omit_to, len(out))) print("FRONT 第1500行(应为真实源码行,非空)= %r" % front[1499]) print("BACK 首行 = %r" % back[0]) ext = {} for rel, p in files: ext[rel.split(".")[-1]] = ext.get(rel.split(".")[-1], 0) + 1 print("类型分布:", ext)