forked from 1Panel-dev/MaxKB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (61 loc) · 1.81 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
import argparse
import logging
import os
import sys
import django
from django.core import management
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
APP_DIR = os.path.join(BASE_DIR, 'apps')
os.chdir(BASE_DIR)
sys.path.insert(0, APP_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "smartdoc.settings")
django.setup()
def collect_static():
"""
收集静态文件到指定目录
本项目主要是将前端vue/dist的前端项目放到静态目录下面
:return:
"""
logging.info("Collect static files")
try:
management.call_command('collectstatic', '--no-input', '-c', verbosity=0, interactive=False)
logging.info("Collect static files done")
except:
pass
def perform_db_migrate():
"""
初始化数据库表
"""
logging.info("Check database structure change ...")
logging.info("Migrate model change to database ...")
try:
management.call_command('migrate')
except Exception as e:
logging.error('Perform migrate failed, exit', exc_info=True)
sys.exit(11)
def start_services():
management.call_command('migrate')
management.call_command('runserver', "0.0.0.0:8080")
if __name__ == '__main__':
os.environ['HF_HOME'] = '/opt/maxkb/model/base'
parser = argparse.ArgumentParser(
description="""
qabot service control tools;
Example: \r\n
%(prog)s start all -d;
"""
)
parser.add_argument(
'action', type=str,
choices=("start", "upgrade_db", "collect_static"),
help="Action to run"
)
args = parser.parse_args()
action = args.action
if action == "upgrade_db":
perform_db_migrate()
elif action == "collect_static":
collect_static()
else:
collect_static()
start_services()