1 Star 0 Fork 189

qinqinbaobei/MaxKB_2

forked from 飞致云/MaxKB 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
guoyuqi 提交于 2024-04-15 15:24 . docs: 修复注释中的错别字 (#80)
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/qinqinbaobei/MaxKB_2.git
git@gitee.com:qinqinbaobei/MaxKB_2.git
qinqinbaobei
MaxKB_2
MaxKB_2
main

搜索帮助