hm_qc/config.py
2025-11-14 17:30:42 +02:00

75 lines
2.4 KiB
Python

"""
Environment configuration for HM QC system.
Set environment variable HM_QC_ENV to control which environment to use:
- export HM_QC_ENV=dev # Development environment
- export HM_QC_ENV=production # Production environment (default)
Development uses relative paths from the repository root.
Production uses absolute paths at /opt/QC.
"""
import os
# Detect environment from environment variable (defaults to production)
ENVIRONMENT = os.getenv('HM_QC_ENV', 'production').lower()
# Get the repository root directory (where this config.py file is located)
REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
# Environment-specific path configuration
if ENVIRONMENT == 'dev':
# Development environment - use relative paths from repo
BASE_DIR = REPO_ROOT
PROFILES_DIR = os.path.join(BASE_DIR, 'profiles')
CHECKS_DIR = os.path.join(BASE_DIR, 'checks')
WORKING_DIR = os.path.join(BASE_DIR, 'tmp', 'HM_working')
REPORTS_DIR = os.path.join(BASE_DIR, 'tmp', 'reports')
SUPPORTING_DIR = os.path.join(BASE_DIR, 'supporting')
else:
# Production environment - use absolute paths
BASE_DIR = '/opt/hm_qc'
PROFILES_DIR = '/opt/hm_qc/profiles'
CHECKS_DIR = '/opt/hm_qc/checks'
WORKING_DIR = '/tmp/HM_working'
REPORTS_DIR = '/opt/hm_qc/reports'
SUPPORTING_DIR = '/opt/hm_qc/supporting'
# Profile paths
PDF_PROFILE_PATH = os.path.join(PROFILES_DIR, 'HM.json')
IMAGE_PROFILE_PATH = os.path.join(PROFILES_DIR, 'HM_image.json')
# Ensure working and reports directories exist in dev mode
if ENVIRONMENT == 'dev':
os.makedirs(WORKING_DIR, exist_ok=True)
os.makedirs(REPORTS_DIR, exist_ok=True)
def get_config():
"""
Returns a dictionary with all configuration values.
Useful for debugging and logging.
"""
return {
'environment': ENVIRONMENT,
'base_dir': BASE_DIR,
'profiles_dir': PROFILES_DIR,
'checks_dir': CHECKS_DIR,
'working_dir': WORKING_DIR,
'reports_dir': REPORTS_DIR,
'supporting_dir': SUPPORTING_DIR,
'pdf_profile_path': PDF_PROFILE_PATH,
'image_profile_path': IMAGE_PROFILE_PATH,
}
def print_config():
"""
Prints the current configuration.
Useful for debugging environment setup.
"""
config = get_config()
print(f"\n{'='*60}")
print(f"HM QC Environment Configuration")
print(f"{'='*60}")
for key, value in config.items():
print(f"{key:20s}: {value}")
print(f"{'='*60}\n")