INNER CODE UNIT · Python
write_file
1186258278/OpenClawChineseTranslation · scripts/inject_panel.py:63
def write_file(path, content):
"""写入文件内容"""
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
def upsert_marked_block(content, marker, block_content):
"""插入或更新带 marker 的注入块"""
block = f"{marker}\n{block_content}"
if marker in content:
pattern = re.compile(re.escape(marker) + r"[\s\S]*$", re.MULTILINE)
return pattern.sub(block, content), True
return content.rstrip() + "\n\n" + block + "\n", False
def inject_to_directory(name, build_dir, panel_js, panel_css, inject_marker):
"""注入功能面板到指定目录"""
print(f"\n{'─' * 50}")
print(f"📁 注入到: {name}")
print(f" 路径: {os.path.abspath(build_dir)}")