This commit is contained in:
vipg
2025-10-09 16:31:17 +08:00
parent cd5731e91b
commit 81632fa5d3

View File

@@ -2,16 +2,21 @@ import os
import shutil import shutil
# 1. 定义全局参数 # 1. 定义全局参数
a = "gateway" # 功能名 a = "gateway1" # 功能名
b = "" # 次功能名 b = "" # 次功能名
c = "20000" # 端口号
def main(): def main():
# 确定新目录名称 # 确定新目录名称
if b: if b:
new_dir = f"api_{a}_{b}" new_dir_name = f"api_{a}_{b}"
else: else:
new_dir = f"api_{a}" new_dir_name = f"api_{a}"
# 目标目录调整为当前目录的deploy/api
new_dir = os.path.join("deploy", "api", new_dir_name)
# 确保deploy/api目录存在
os.makedirs(os.path.join("deploy", "api"), exist_ok=True)
# 2. 复制并重命名api_template目录 # 2. 复制并重命名api_template目录
source_dir = "api_template" source_dir = "api_template"
@@ -39,7 +44,7 @@ def main():
os.rename(temp_yaml, new_yaml) os.rename(temp_yaml, new_yaml)
print(f"已重命名yaml文件{yaml_filename}") print(f"已重命名yaml文件{yaml_filename}")
# 4-6. 处理yaml文件内容 # 4-5. 处理yaml文件内容(移除端口号修改)
with open(new_yaml, 'r', encoding='utf-8') as f: with open(new_yaml, 'r', encoding='utf-8') as f:
content = f.read() content = f.read()
@@ -55,16 +60,13 @@ def main():
else: else:
content = content.replace("_template", f"_{a}") content = content.replace("_template", f"_{a}")
# 替换端口号"20001"
content = content.replace("20001", c)
with open(new_yaml, 'w', encoding='utf-8') as f: with open(new_yaml, 'w', encoding='utf-8') as f:
f.write(content) f.write(content)
print(f"已更新yaml文件内容") print(f"已更新yaml文件内容")
else: else:
print(f"警告:未找到 {temp_yaml} 文件跳过yaml处理") print(f"警告:未找到 {temp_yaml} 文件跳过yaml处理")
# 7-9. 处理README.md # 6-8. 处理README.md(移除端口号修改)
readme_path = os.path.join(new_dir, "README.md") readme_path = os.path.join(new_dir, "README.md")
if os.path.exists(readme_path): if os.path.exists(readme_path):
with open(readme_path, 'r', encoding='utf-8') as f: with open(readme_path, 'r', encoding='utf-8') as f:
@@ -82,16 +84,13 @@ def main():
else: else:
content = content.replace("template-", f"{a}-") content = content.replace("template-", f"{a}-")
# 替换端口号"20001"
content = content.replace("20001", c)
with open(readme_path, 'w', encoding='utf-8') as f: with open(readme_path, 'w', encoding='utf-8') as f:
f.write(content) f.write(content)
print(f"已更新README.md内容") print(f"已更新README.md内容")
else: else:
print(f"警告:未找到 {readme_path} 文件跳过README处理") print(f"警告:未找到 {readme_path} 文件跳过README处理")
# 10. 处理release.sh # 9. 处理release.sh
release_path = os.path.join(new_dir, "release.sh") release_path = os.path.join(new_dir, "release.sh")
if os.path.exists(release_path): if os.path.exists(release_path):
with open(release_path, 'r', encoding='utf-8') as f: with open(release_path, 'r', encoding='utf-8') as f:
@@ -109,10 +108,10 @@ def main():
else: else:
print(f"警告:未找到 {release_path} 文件跳过release.sh处理") print(f"警告:未找到 {release_path} 文件跳过release.sh处理")
# 11-13. 处理depend.py # 10-11. 处理init.py移除端口号修改
depend_path = os.path.join(new_dir, "depend.py") init_path = os.path.join(new_dir, "init.py")
if os.path.exists(depend_path): if os.path.exists(init_path):
with open(depend_path, 'r', encoding='utf-8') as f: with open(init_path, 'r', encoding='utf-8') as f:
content = f.read() content = f.read()
# 替换"_template_" # 替换"_template_"
@@ -127,14 +126,11 @@ def main():
else: else:
content = content.replace("template &&", f"{a} &&") content = content.replace("template &&", f"{a} &&")
# 替换端口号"20001" with open(init_path, 'w', encoding='utf-8') as f:
content = content.replace("20001", c)
with open(depend_path, 'w', encoding='utf-8') as f:
f.write(content) f.write(content)
print(f"已更新depend.py内容") print(f"已更新init.py内容")
else: else:
print(f"警告:未找到 {depend_path} 文件,跳过depend.py处理") print(f"警告:未找到 {init_path} 文件,跳过init.py处理")
if __name__ == "__main__": if __name__ == "__main__":
main() main()