diff --git a/create_api.py b/create_api.py index 11133ac..e26284a 100644 --- a/create_api.py +++ b/create_api.py @@ -2,16 +2,21 @@ import os import shutil # 1. 定义全局参数 -a = "gateway" # 功能名 +a = "gateway1" # 功能名 b = "" # 次功能名 -c = "20000" # 端口号 def main(): # 确定新目录名称 if b: - new_dir = f"api_{a}_{b}" + new_dir_name = f"api_{a}_{b}" 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目录 source_dir = "api_template" @@ -39,7 +44,7 @@ def main(): os.rename(temp_yaml, new_yaml) print(f"已重命名yaml文件:{yaml_filename}") - # 4-6. 处理yaml文件内容 + # 4-5. 处理yaml文件内容(移除端口号修改) with open(new_yaml, 'r', encoding='utf-8') as f: content = f.read() @@ -55,16 +60,13 @@ def main(): else: content = content.replace("_template", f"_{a}") - # 替换端口号"20001" - content = content.replace("20001", c) - with open(new_yaml, 'w', encoding='utf-8') as f: f.write(content) print(f"已更新yaml文件内容") else: print(f"警告:未找到 {temp_yaml} 文件,跳过yaml处理") - # 7-9. 处理README.md + # 6-8. 处理README.md(移除端口号修改) readme_path = os.path.join(new_dir, "README.md") if os.path.exists(readme_path): with open(readme_path, 'r', encoding='utf-8') as f: @@ -82,16 +84,13 @@ def main(): else: content = content.replace("template-", f"{a}-") - # 替换端口号"20001" - content = content.replace("20001", c) - with open(readme_path, 'w', encoding='utf-8') as f: f.write(content) print(f"已更新README.md内容") else: print(f"警告:未找到 {readme_path} 文件,跳过README处理") - # 10. 处理release.sh + # 9. 处理release.sh release_path = os.path.join(new_dir, "release.sh") if os.path.exists(release_path): with open(release_path, 'r', encoding='utf-8') as f: @@ -109,10 +108,10 @@ def main(): else: print(f"警告:未找到 {release_path} 文件,跳过release.sh处理") - # 11-13. 处理depend.py - depend_path = os.path.join(new_dir, "depend.py") - if os.path.exists(depend_path): - with open(depend_path, 'r', encoding='utf-8') as f: + # 10-11. 处理init.py(移除端口号修改) + init_path = os.path.join(new_dir, "init.py") + if os.path.exists(init_path): + with open(init_path, 'r', encoding='utf-8') as f: content = f.read() # 替换"_template_" @@ -127,14 +126,11 @@ def main(): else: content = content.replace("template &&", f"{a} &&") - # 替换端口号"20001" - content = content.replace("20001", c) - - with open(depend_path, 'w', encoding='utf-8') as f: + with open(init_path, 'w', encoding='utf-8') as f: f.write(content) - print(f"已更新depend.py内容") + print(f"已更新init.py内容") else: - print(f"警告:未找到 {depend_path} 文件,跳过depend.py处理") + print(f"警告:未找到 {init_path} 文件,跳过init.py处理") if __name__ == "__main__": main() \ No newline at end of file