FileServer/app_config.py

63 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from config_file import read_config as read_cfg
APP_VERSION="1.0"
SCRIPT_PATH = os.path.dirname(__file__)
CONFIGS_DIR = SCRIPT_PATH + "/configs"
CONFIG_FILE_NAME = CONFIGS_DIR + "/server_config.yaml"
API_KEY = ''
UPLOAD_DIR = 'uploads'
DB_URL = ''
APP_PORT = 25100
IS_DEBUG = False
IS_DOCS_AVAILABLE = False
HTML_FILE = 'html/main.html'
CSS_FILE = 'css/main.css'
JS_FILE = 'js/main.js'
ALIAS_NUM_LETTERS = 3
ALIAS_NUM_DIGITS = 4
"""
For 3 + 4 defaults there are 1 406 080 000 possible values:
Кількість варіантів для кожної літери (великої або малої) дорівнює 52 (26 великих + 26 малих).
Кількість комбінацій для трьох літер: 52 * 52 * 52 = 140 608.
Кількість варіантів для кожної цифри: 10 (0-9).
Кількість комбінацій для чотирьох цифр: 10 * 10 * 10 * 10 = 10 000.
Загальна кількість комбінацій: 140 608 * 10 000 = 1 406 080 000.
"""
def read_app_config():
j, _ = read_cfg(CONFIG_FILE_NAME)
return j
def get_config_value(cfg, section, key, default):
if '.' in section:
s = section.split('.', 1)
new_section = s[1]
new_cfg = cfg[s[0]]
return get_config_value(new_cfg, new_section, key, default)
else:
return cfg[section][key] if section in cfg and key in cfg[section] else default
def parse_config(cfg):
global UPLOAD_DIR, APP_PORT, IS_DEBUG, DB_URL, ALIAS_NUM_LETTERS, ALIAS_NUM_DIGITS\
, IS_DOCS_AVAILABLE, HTML_FILE, CSS_FILE, JS_FILE
UPLOAD_DIR = get_config_value(cfg, 'server', 'directory', UPLOAD_DIR)
APP_PORT = get_config_value(cfg, 'server', 'port', APP_PORT)
DB_URL = get_config_value(cfg, 'server', 'db_url', DB_URL)
IS_DEBUG = get_config_value(cfg, 'server', 'debug', IS_DEBUG)
ALIAS_NUM_LETTERS = get_config_value(cfg, 'server', 'alias_letters', ALIAS_NUM_LETTERS)
ALIAS_NUM_DIGITS = get_config_value(cfg, 'server', 'alias_digits', ALIAS_NUM_DIGITS)
IS_DOCS_AVAILABLE = get_config_value(cfg, 'server', 'docs_available', IS_DOCS_AVAILABLE)
HTML_FILE = get_config_value(cfg, 'interface', 'html', HTML_FILE)
CSS_FILE = get_config_value(cfg, 'interface', 'css', CSS_FILE)
JS_FILE = get_config_value(cfg, 'interface', 'js', JS_FILE)
def init_config():
config = read_app_config()
parse_config(config)
if __name__ == '__main__':
init_config()