1 Star 0 Fork 0

JoeEmp/antelope

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
init_project_conf.py 3.42 KB
一键复制 编辑 原始数据 按行查看 历史
JoeEmp 提交于 2023-12-18 15:22 . [code]修改生成模版内容
import os
import shutil
import fire
from colorama import Fore, init
import yaml
init(autoreset=True)
def green_print(s):
print(Fore.GREEN + s)
macro_content = """# 枚举和宏定义
# 默认优先级
DEF_LEVEL = 99
# 全局变量
GLOBAL_VALUE_FILENAME = '%s'
# 邮件配置
EMAIL_FILENAME = '%s'
# 错误用例生成文件名格式
ERROR_SUITE = 'suite/%s_error_suite.yaml'
"""
def update_marco(global_value_path, email_conf_path):
"""更新宏"""
with open(os.path.join('com', "macro.py"), 'w') as f:
f.write(macro_content % (global_value_path, email_conf_path, '%s'))
f.close()
def init_new_marco(global_value_path, email_conf_path, dir_name):
count = 0
while True:
if 0 == count:
print('是否更新下面内容到com/macro.py')
green_print('%s' % macro_content)
question_str = "输入错误,请重新输入(Y/N)>" if 0 < count else "(Y/N)>"
ans = input(question_str)
if 'n' == ans.lower() or 'y' == ans.lower():
break
count += 1
if 'n' == ans.lower():
print('请手动更新 com/macro.py 文件')
shutil.rmtree(dir_name)
return
update_marco(global_value_path, email_conf_path)
def init_dir(dir_name):
print('初始化用例配置')
if os.path.exists(dir_name):
raise UserWarning('文件(夹)%s已存在,初始化失败' % dir_name)
os.mkdir(dir_name)
def init_project_conf(dir_name):
"""初始化项目配置"""
if str(dir_name).endswith('_case'):
dirname = str(dirname)
else:
dir_name = str(dir_name) + '_case'
global_value_path = os.path.join(dir_name, 'global_value.yaml')
email_conf_path = os.path.join(dir_name, 'email_conf.yaml')
init_dir(dir_name)
init_global_value(global_value_path)
init_email_value(email_conf_path)
init_new_marco(global_value_path, email_conf_path, dir_name)
init_cli(dir_name)
def init_cli(dir_name):
key_line = " case_root = 'tests' if t else '{}'"
with open('cli.py', 'r') as f:
lines = f.readlines()
for index, line in enumerate(lines):
if key_line.format('case') in line:
lines[index] = key_line.format(dir_name)+'\n'
with open('cli.py', 'w') as f:
f.writelines(lines)
def init_global_value(filename):
context = {
"demo":
{
"db":
{
"mysql": {
"host": "127.0.0.1",
"username": "root",
"pwd": "123456",
"port": 3306,
"type": "mysql",
}
}
}
}
with open(filename, 'w') as f:
f.write(yaml.dump(context))
f.close()
def init_email_value(filename):
context = {
"sender_addr": "",
"sender_pwd": "",
# 可选发件人名字
"sender_name": "Joe",
"host": "smtp.exmail.qq.com",
"port": 465,
"use_ssl": True,
# 填入数组或者单个邮箱都可以
# to_addrs: hemingjie@wxchina.com
"to_addrs": [
"hemingjie@wxchina.com"],
# 调试模式下,收件人为发件人
"is_debug": False
}
with open(filename, 'w') as f:
f.write(yaml.dump(context))
f.close()
def reset_conf():
update_marco('global_value.yaml', 'email_conf.yaml')
ipc = init_project_conf
reset = reset_conf
if "__main__" == __name__:
fire.Fire()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/JoeEmp/antelope.git
git@gitee.com:JoeEmp/antelope.git
JoeEmp
antelope
antelope
main

搜索帮助