46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
work = Path(__file__).resolve().parent
|
|
canonical = Path('C:/kefu')
|
|
source = work / 'backend/payload'
|
|
payload = work / 'merged/payload'
|
|
remote = json.loads((work / 'source-before-remote.json').read_text('utf-8'))
|
|
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
entries = []
|
|
for path in sorted((source / 'wechat_rpa').glob('*.py')):
|
|
relative = path.relative_to(source)
|
|
original, target = canonical / relative, payload / relative
|
|
before = sha(original) if original.is_file() else None
|
|
kind = 'test' if path.name.startswith('test_') else 'production'
|
|
if kind == 'production':
|
|
assert remote['host'].get(path.name) == before, path.name
|
|
assert all(hashes.get(path.name) == before for hashes in remote['services'].values()), path.name
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
data = path.read_bytes()
|
|
if path.name == 'rbac.py':
|
|
lines = data.splitlines(keepends=True)
|
|
previous_page, task_page = (name.encode('utf-8') for name in ('"知识加工与检索"', '"整理任务"'))
|
|
for code in ('knowledge:run', 'knowledge:run:control', 'knowledge:watch'):
|
|
prefix = f' Permission("{code}",'.encode('ascii')
|
|
indexes = [index for index, line in enumerate(lines) if line.startswith(prefix) and previous_page in line]
|
|
assert len(indexes) == 1, code
|
|
index = indexes[0]
|
|
lines[index] = lines[index].replace(previous_page, task_page, 1)
|
|
data = b''.join(lines)
|
|
target.write_bytes(data)
|
|
entries.append({'source_path': str(original), 'staged_path': str(target), 'before_sha256': before,
|
|
'staged_sha256': sha(target), 'role': kind})
|
|
|
|
modules = {Path(item['source_path']).name for item in entries if item['role'] == 'production'}
|
|
assert {'knowledge_api.py', 'knowledge_store.py', 'rbac.py'} <= modules
|
|
(work / 'merged/staged-manifest.json').write_text(json.dumps({'files': entries}, indent=2) + '\n', encoding='utf-8')
|
|
print(f'{len(entries)} backend payload files prepared')
|