Files
smart-management-auto-test/base_framework/platform_tools/IDF/manage.py

65 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# encoding: UTF-8
from flask_cors import CORS
from flask import make_response, jsonify, request, redirect
import os, sys
import configparser
import argparse
from apscheduler.schedulers.background import BackgroundScheduler
BASIC_PATH = os.path.dirname(os.path.abspath(__file__))
BASE_PATH = os.path.abspath(os.path.join(BASIC_PATH, '../../../{}'.format("base_framework")))
sys.path.append(BASE_PATH)
PROJECT_PATH = os.path.abspath(os.path.join(BASIC_PATH, '../../..'))
sys.path.append(PROJECT_PATH)
env_choose_path = os.path.join(BASE_PATH, 'base_config', 'env_choose.ini')
team_names = ["UBRD","TMO","H2R","CC","LaLive","SCM","TO"]
for team in team_names:
TEAM_PATH = os.path.abspath(os.path.join(BASIC_PATH, '../../../{}'.format(team)))
sys.path.append(TEAM_PATH)
from base_framework.platform_tools.IDF.app import create_app
from base_framework.platform_tools.IDF.app.api.controller.commonController import CommonController
def start_env():
parser = argparse.ArgumentParser(description="Choose current environment")
parser.add_argument("-e", dest='env', help="ST or PRE", default='QA')
args = parser.parse_args()
choose_env = args.env
return choose_env
get_env = start_env()
cof = configparser.ConfigParser()
cof.read(env_choose_path, encoding='utf-8')
cof.set(section="is_ip_from_ini", option="is_ip_from_ini", value="false")
cof.set(section="run_evn_name", option="current_evn", value=get_env.upper())
with open(env_choose_path, 'w') as fw: # 循环写入
cof.write(fw)
app = create_app()
CORS(app, resources=r'/*')
create_common_controll = CommonController()
# 初始化调度器
scheduler = BackgroundScheduler()
# 添加每日任务每天凌晨0点执行
scheduler.add_job(create_common_controll.daily_task_update_month_number, 'cron', hour=0, minute=0)
# 启动调度器
scheduler.start()
if get_env == "SIM":
app.run(host="0.0.0.0", port=int("5112"), debug=True, use_reloader=False)
else:
app.run(host="0.0.0.0", port=int("5113"), debug=True, use_reloader=False)
def cors_response(res):
response = make_response(jsonify(res))
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = '*'
response.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return response