-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
97 lines (80 loc) · 2.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- encoding:utf-8 -*-
"""
"""
import logging
import os
import sys
from datetime import datetime
from os.path import abspath, dirname, join
import uvicorn
import AcgDraw
from AcgDraw import api
from AcgDraw.util import json_read, json_write
# 取根目录
dir = os.getcwd() # 取根目录
# 判断目录是否存在,并且在不存在时创建目录
def mkdir(path):
is_exists = os.path.exists(path)
if not is_exists:
os.makedirs(path.encode("utf-8"))
return True
else:
return False
# 写入json
host = json_read(join(dir, "conf", "config.json"))["global"]["host"]
port = int(json_read(join(dir, "conf", "config.json"))["global"]["port"])
# 初始化目录
create_dir_list = [
"./static/image",
"./data/",
"./conf"
]
def log_output(log_type: str, message: str) -> None:
print("{}[{}]{}".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), log_type, message))
log_output("INFO", "Arknights-Draw")
app = api.api_app
# 自动运行
if len(sys.argv) > 1:
if sys.argv[1] == "init":
log_output("INFO", "服务器未部署,开始部署")
for create_dir in create_dir_list:
mkdir(create_dir)
try:
AcgDraw.update.UpdateHandleArk("./data/Arknights/", "./conf/Arknights/").start_update()
with open("./data/lock.lock", 'w', encoding='utf-8') as f:
f.write("")
except:
log_output("Error", "部署发生错误,请重试")
exit(1)
exit(0)
elif sys.argv[1] == "update":
AcgDraw.update.UpdateHandleArk("./data/Arknights/", "./conf/Arknights/").start_update()
uvicorn.run(app, host=host, port=port, log_level=logging.INFO)
elif sys.argv[1] == "start":
uvicorn.run(app, host=host, port=port, log_level=logging.INFO)
else:
log_output("Error", "参数错误")
exit(1)
# 交互式
else:
input("按任意键继续")
if not os.path.exists("./data/lock.lock"):
log_output("INFO", "服务器未部署,开始部署")
for create_dir in create_dir_list:
mkdir(create_dir)
try:
AcgDraw.update.UpdateHandleArk("./data/Arknights/", "./conf/Arknights/").start_update()
with open("./data/lock.lock", 'w', encoding='utf-8') as f:
f.write("")
uvicorn.run(app, host=host, port=port, log_level=logging.INFO)
except:
log_output("Error", "部署发生错误,请重试")
input("按任意键继续")
else:
log_output("INFO", "服务器已部署 1.启动服务器 2.启动更新")
x = input("请选择操作:")
if int(x) == 1:
uvicorn.run(app, host=host, port=port, log_level=logging.INFO)
elif int(x) == 2:
AcgDraw.update.UpdateHandleArk("./data/Arknights/", "./conf/Arknights/").start_update()
uvicorn.run(app, host=host, port=port, log_level=logging.INFO)