Merge commit '397efb86dc84197b74d9a3b16a11b1d0d534ad9e' as 'integrations/document-ai'
This commit is contained in:
67
integrations/document-ai/src/config_loader.py
Normal file
67
integrations/document-ai/src/config_loader.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
설정 파일(settings.json) 로더
|
||||
프로젝트 전체에서 사용되는 설정을 중앙에서 관리하고 제공합니다.
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any
|
||||
|
||||
class ConfigLoader:
|
||||
def __init__(self, config_path: str = "config/settings.json"):
|
||||
self.config_path = Path(config_path)
|
||||
self.config = self._load_config()
|
||||
|
||||
def _load_config(self) -> Dict[str, Any]:
|
||||
"""JSON 설정 파일을 읽어 딕셔너리로 반환합니다."""
|
||||
if not self.config_path.exists():
|
||||
raise FileNotFoundError(f"설정 파일을 찾을 수 없습니다: {self.config_path}")
|
||||
|
||||
with open(self.config_path, 'r', encoding='utf-8') as f:
|
||||
config_data = json.load(f)
|
||||
|
||||
# 경로 설정에서 '~'를 실제 홈 디렉토리로 확장
|
||||
if 'paths' in config_data:
|
||||
for key, value in config_data['paths'].items():
|
||||
if isinstance(value, str) and value.startswith('~/'):
|
||||
config_data['paths'][key] = str(Path.home() / value[2:])
|
||||
|
||||
return config_data
|
||||
|
||||
def get_section(self, section_name: str) -> Dict[str, Any]:
|
||||
"""설정의 특정 섹션을 반환합니다."""
|
||||
return self.config.get(section_name, {})
|
||||
|
||||
@property
|
||||
def network_config(self) -> Dict[str, Any]:
|
||||
return self.get_section("network")
|
||||
|
||||
@property
|
||||
def paths_config(self) -> Dict[str, Any]:
|
||||
return self.get_section("paths")
|
||||
|
||||
@property
|
||||
def models_config(self) -> Dict[str, Any]:
|
||||
return self.get_section("models")
|
||||
|
||||
# 전역 설정 인스턴스 생성
|
||||
# 프로젝트 어디서든 `from config_loader import settings`로 불러와 사용 가능
|
||||
settings = ConfigLoader()
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 설정 로더 테스트
|
||||
print("✅ 설정 로더 테스트")
|
||||
print("-" * 30)
|
||||
|
||||
network = settings.network_config
|
||||
print(f"네트워크 설정: {network}")
|
||||
print(f" - 서버 IP: {network.get('mac_mini_ip')}")
|
||||
print(f" - 서버 포트: {network.get('server_port')}")
|
||||
|
||||
paths = settings.paths_config
|
||||
print(f"경로 설정: {paths}")
|
||||
print(f" - 로컬 작업 경로: {paths.get('local_work_path')}")
|
||||
|
||||
print("-" * 30)
|
||||
print("설정 로드 완료!")
|
||||
Reference in New Issue
Block a user