You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

61 lines
2.0 KiB

# -*- coding: utf-8 -*-
"""F3 bruno 侧产出:把 客户导入 6 端点副本补进 客户公海 页(同名同内容,仅重排 seq)。
依据 bruno-sync skill:挂 N 个 tag 就在 N 个页面文件夹下各生成一份同名同内容 .bru。
幂等:目标同名文件已存在则跳过。seq 取目标文件夹现有最大值顺延。
注意:meta 字段带两格缩进,seq 匹配必须容缩进。
"""
import io
import os
import re
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
DOCS = r"E:\code\crm-api-docs\A4 客户管理"
SRC = DOCS + r"\我的客户\客户导入"
DST = DOCS + r"\客户公海"
def max_seq(folder):
m = 0
for fn in os.listdir(folder):
if not fn.endswith(".bru"):
continue
with open(os.path.join(folder, fn), "r", encoding="utf-8") as f:
for line in f:
mm = re.match(r"\s*seq:\s*(\d+)", line)
if mm:
m = max(m, int(mm.group(1)))
return m
def main():
srcs = sorted(fn for fn in os.listdir(SRC) if fn.endswith(".bru"))
seq = max_seq(DST)
print("dst max_seq=%d" % seq)
written, skipped = [], []
for fn in srcs:
dst_path = os.path.join(DST, fn)
if os.path.exists(dst_path):
skipped.append(fn)
continue
with open(os.path.join(SRC, fn), "r", encoding="utf-8") as f:
content = f.read()
seq += 1
new, n = re.subn(r"(?m)^(\s*)seq:\s*\d+\s*$",
lambda mm: mm.group(1) + "seq: %d" % seq,
content, count=1)
assert n == 1, "seq 行未命中: %s" % fn
with open(dst_path, "w", encoding="utf-8", newline="\n") as f:
f.write(new)
written.append("%s (seq=%d)" % (fn, seq))
print("written=%d skipped=%d" % (len(written), len(skipped)))
for w in written:
print(" +", w)
for s in skipped:
print(" =", s)
if __name__ == "__main__":
main()