Files
kefu/deploy/perm-tree-20261008/head-build/ptree_reverse.py
T
2026-11-16 09:39:42 +08:00

32 lines
1.4 KiB
Python

"""Pre-release (= perm-button, live) versions of the files touched by perm-tree: replay ed_tree.py + the inline
showLeafIcon edit in reverse on copies of the current files. python ptree_reverse.py OUT_DIR"""
import runpy, sys, types
from pathlib import Path
SCRATCH = Path(__file__).resolve().parent
WEB = 'C:/wechat_rpa/admin-web/apps/web-antd/'
OUT = Path(sys.argv[1])
steps = []
fake = types.ModuleType('edhelp')
fake.edit = lambda path, pairs: steps.append((str(path).replace('\\', '/'), list(pairs)))
sys.modules['edhelp'] = fake
runpy.run_path(str(SCRATCH / 'ed_tree.py'), run_name='__main__')
steps.append((WEB + 'src/views/console/roles.vue', [
('checkable show-line block-node :selectable="false" :disabled="readonly"',
'checkable :show-line="{ showLeafIcon: false }" block-node :selectable="false" :disabled="readonly"')]))
texts = {}
for path, _ in steps:
texts.setdefault(path, Path(path).read_bytes().decode('utf-8'))
for path, pairs in reversed(steps):
crlf = '\r\n' in texts[path]
text = texts[path].replace('\r\n', '\n')
for old, new in reversed(pairs):
assert text.count(new) == 1, (path, new[:80])
text = text.replace(new, old)
texts[path] = text.replace('\n', '\r\n') if crlf else text
for path, text in texts.items():
target = OUT / path[len(WEB):]
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(text.encode('utf-8'))
print(path[len(WEB):])