__author__ = 'all.woo' ''' manage ''' # 更新python第三方库 print(" * Check or update Python third-party libraries") CONFIG["py_venv"]["VENV_PATH"]["value"] = sys.prefix update_pylib(input_venv_path=False) # 网站还未启动的时候, 连接数据库, 更新collection from apps.core.utils.update_db_collection import update_mdb_collections, init_datas from apps.core.db.mongodb import PyMongo print(" * Check or update the database collection") database = DatabaseConfig() mdb_web = PyMongo() mdb_sys = PyMongo() mdb_user = PyMongo() db_init = 2 while db_init: try: mdb_web.init_app(config_prefix='MONGO_WEB', db_config=database.MONGO_WEB_URI) mdb_sys.init_app(config_prefix='MONGO_SYS', db_config=database.MONGO_SYS_URI) mdb_user.init_app(config_prefix='MONGO_USER', db_config=database.MONGO_USER_URI) except OperationFailure as e: print("\n[Mongodb] *{}".format(e)) print("Mongodb validation failure, the user name," " password mistake or database configuration errors.\n"
if "--debug" not in sys.argv and "-D" not in sys.argv: # 更新python第三方类库 print(" * Check or update Python third-party libraries") CONFIG["py_venv"]["VENV_PATH"]["value"] = sys.prefix update_pylib(input_venv_path=False) else: print(" * Using --debug, the system will not check Python dependencies") # 网站还未启动的时候, 连接数据库, 更新collection from apps.core.utils.update_sys_data import update_mdb_collections, init_datas, compatible_processing from apps.core.db.mongodb import PyMongo print(" * Check or update the database collection") database = DatabaseConfig() mdbs = {} for k, mdb_acc in DB_CONFIG["mongodb"].items(): mdbs[k] = PyMongo() db_init = 2 while db_init: try: for name, mdb in mdbs.items(): if name not in ["sys", "user", "web"]: print( " *[Error] 由v1.x.x更新到v2.x.x需要请更新你的数据库配置文件apps/configs/db_config.py\n" " 请参考同目录下的db_config_sample.py") sys.exit() mdb.init_app(config_prefix=name.upper(), db_config=database.__dict__["{}_URI".format( name.upper())]) except OperationFailure as e:
from flask_mail import Mail from flask_oauthlib.client import OAuth from flask_session import Session from flask_wtf import CSRFProtect from flask_login import LoginManager from redis import StrictRedis from apps.configs.db_config import DB_CONFIG ''' Flask app 与其他核心模块实例化 注意: 不要将模块初始话设置放在本文件 ''' # 主程序 web_start_log.info("Initialize the OsrApp") app = OsrApp(__name__) web_start_log.info("Instance of each module") mdb_web = PyMongo() mdb_sys = PyMongo() mdb_user = PyMongo() cache = Cache() babel = Babel() csrf = CSRFProtect() login_manager = LoginManager() sess = Session() rest_session = RestSession() mail = Mail() weblog = WebLogger() oauth = OAuth() redis = StrictRedis(host=DB_CONFIG["redis"]["host"][0], port=DB_CONFIG["redis"]["port"][0], password=DB_CONFIG["redis"]["password"])
from flask_mail import Mail from flask_oauthlib.client import OAuth from flask_session import Session from flask_wtf import CSRFProtect from flask_login import LoginManager from apps.core.flask.myflask import App from apps.core.flask.cache import Cache from apps.core.db.mongodb import PyMongo from apps.core.logger.logging import Logger, start_logger from apps.configs.db_config import DB_CONFIG start_logger.info("Initialize the application") app = App(__name__) db_site = PyMongo() db_sys = PyMongo() db_user = PyMongo() cache = Cache() start_logger.info("Initialize third-party libraries") csrf = CSRFProtect() login_manager = LoginManager() session = Session() mail = Mail() logger = Logger() oauth = OAuth() redis = StrictRedis(host=DB_CONFIG["redis"]["host"], port=DB_CONFIG["redis"]["port"],
# -*- coding: utf-8 -*- """ start.py ~~~~~~~~~~~~~~~~~~~ :author: Finger :license: BSD, see LICENSE for more details. """ from apps.configs.config import CONFIG from apps.core.db.mongodb_config import MongoDBConfig from apps.core.utils.mongodb import update_collections from apps.core.db.mongodb import PyMongo print("* Check or update the database collection") mongodb_conf = MongoDBConfig() db_site = PyMongo() db_sys = PyMongo() db_user = PyMongo() db_init = 2 while db_init: db_site.init_app(config_prefix="MONGO_SITE", db_config=mongodb_conf.SITE_URI) db_sys.init_app(config_prefix="MONGO_SYS", db_config=mongodb_conf.SYS_URI) db_user.init_app(config_prefix="MONGO_USER", db_config=mongodb_conf.USER_URI) if db_init == 2: update_collections(db_sys=db_sys, db_site=db_site, db_user=db_user) db_init -= 1