| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- # -*- coding: utf-8 -*-
- #
- import os
- from dotenv import load_dotenv
- from .conf import ConfigManager
- __all__ = ['BASE_DIR', 'PROJECT_DIR', 'VERSION', 'CONFIG']
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- LOG_DIR = os.path.join('/', 'opt', 'maxkb', 'logs')
- PROJECT_DIR = os.path.dirname(BASE_DIR)
- VERSION = '2.0.0'
- # load environment variables from .env file
- load_dotenv()
- def _find_config_root():
- """Auto-detect config directory across platforms."""
- # 1. Explicit env var takes priority
- if os.getenv('MAXKB_CONFIG') is not None:
- return PROJECT_DIR
- config_names = ('config.yml', 'config.yaml', 'config_example.yml')
- # 2. Project root directory
- for name in config_names:
- if os.path.isfile(os.path.join(PROJECT_DIR, name)):
- return PROJECT_DIR
- # 3. conf/ subdirectory under project root
- conf_dir = os.path.join(PROJECT_DIR, 'conf')
- if os.path.isdir(conf_dir):
- for name in config_names:
- if os.path.isfile(os.path.join(conf_dir, name)):
- return conf_dir
- # 4. Fallback to /opt/maxkb/conf (Linux convention)
- return os.path.abspath('/opt/maxkb/conf')
- CONFIG = ConfigManager.load_user_config(root_path=_find_config_root())
|