NextERP-scripts/services/config.py
2025-04-08 09:49:25 +07:00

37 lines
1.1 KiB
Python

import os
import yaml
class Config:
def __init__(self, config_path="config/settings.yaml"):
self.config_path = config_path
self.settings = self.load_config()
def load_config(self):
if not os.path.exists(self.config_path):
raise FileNotFoundError(f"Config file not found at {self.config_path}")
with open(self.config_path, "r") as f:
return yaml.safe_load(f)
def get(self, section, key, default=None):
return self.settings.get(section, {}).get(key, default)
def get_instances(self):
"""Return the list of Odoo instances."""
return self.settings.get("odoo_instances", [])
def get_instance(self, name):
"""
Get a single instance configuration by name.
Args:
name (str): Name of the instance to retrieve
Returns:
dict: Instance configuration if found, None otherwise
"""
instances = self.get_instances()
for instance in instances:
if instance.get("name") == name:
return instance
return None