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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
""" ------------------------------------------------
describe: 解析配置
base_info: __author__ = "PyGo" __time__ = "2022/9/14" __version__ = "v.1.0.0" __mail__ = "gaoming971366@163.com" __project__ = "quality-inspect"
usage:
design:
reference urls:
python version: python3
Enjoy the good time everyday!!! Life is short, I use python.
------------------------------------------------ """
import os import sys import yaml import inspect import logging
logger = logging.getLogger(__name__)
def _get_cur_folder(): if getattr(sys, "frozen", False): return os.path.dirname(os.path.abspath(__file__)) else: cur_folder = os.path.dirname(inspect.getfile(inspect.currentframe())) return os.path.abspath(cur_folder)
def _get_global_projects(mode='dev'): if mode not in ['dev', 'prod']: return None return os.path.join(os.path.join(os.path.join(_get_cur_folder(), 'etc'), mode), 'projects.json')
def _get_config(mode='dev'): if mode not in ['dev', 'prod']: return None return os.path.join(os.path.join(os.path.join(_get_cur_folder(), 'etc'), mode), 'config.yaml')
def __get_log_dir(): return os.path.join(_get_cur_folder(), 'log')
def __get_result_dir(): return os.path.join(_get_cur_folder(), 'result')
""" default config """
NAME = 'quality-inspect' VERSION = 'v1.0.0' DEBUG = True SECRET_KEY = 'BelivemeIcanfly'
""" enrty: initializate config """ mode = os.environ.get('mode') or 'dev' _config_file = _get_config(mode) if not os.path.exists(_config_file): logger.critical('====== config file is not exist, exit ======') sys.exit(1)
with open(_config_file, 'r', encoding='UTF-8') as f: _config_info = yaml.safe_load(f) if not _config_info: logger.critical('====== config file is unavail, exit ======') sys.exit(1)
NAME = _config_info['SERVER']['NAME'] or NAME VERSION = _config_info['SERVER']['VERSION'] or VERSION DEBUG = _config_info['SERVER']['DEBUG'] DEBUG = False if not DEBUG else DEBUG SECRET_KEY = _config_info['SERVER']['SECRET_KEY'] or SECRET_KEY
|