示例#1
0
from nmtwizard.redis_database import RedisDatabase
from nmtwizard import common

VERSION = "1.12.0"

app = Flask(__name__)
app._requestid = 1

ch = logging.StreamHandler()
app.logger.addHandler(ch)

formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)

common.add_log_handler(ch)

config_file = os.getenv('LAUNCHER_CONFIG', 'settings.ini')
assert config_file is not None and os.path.isfile(
    config_file), "invalid LAUNCHER_CONFIG"

default_file = os.path.join(os.path.dirname(config_file), "default.json")
assert os.path.isfile(
    default_file), "Cannot find default.json: %s" % default_file

with open(default_file) as default_fh:
    default_config = default_fh.read()
    base_config = json.loads(default_config)
    assert 'storages' in base_config, "incomplete configuration - missing " \
                                      "`storages` in %s" % default_file
示例#2
0
def get_version():
    return VERSION


system_config = config.get_system_config()
mongo_client = DatabaseUtils.get_mongo_client(system_config)
redis_db = DatabaseUtils.get_redis_client(system_config)
redis_db_without_decode = DatabaseUtils.get_redis_client(system_config,
                                                         decode_response=False)

base_config = config.process_base_config(mongo_client)

log_handler = get_log_handler()
app.logger.addHandler(log_handler)
common.add_log_handler(log_handler)

flask_config = system_config["flask"]
redis_uri = DatabaseUtils.get_redis_uri(system_config)
flask_config['SESSION_REDIS'] = redis.from_url(redis_uri)
app.config.update(flask_config)
app.other_config = system_config

app.__class__.get_other_config = get_other_config_flask

app.logger.setLevel(
    logging.getLevelName(
        app.get_other_config(["default", "log_level"], fallback='ERROR')))

sess = Session()
sess.init_app(app)