import logging
from caspia.gateway import config
from caspia.meadow.client import Gateway
from caspia.meadow.services.base import ServiceBase
from caspia.toolbox import storage
from .services import MockService
logger = logging.getLogger(__name__)
[docs]class CaspiaGateway(Gateway):
def __init__(self, *, name, connection, config_path, storage_path):
super().__init__(name, connection=connection)
self.config_path = config_path
self.storage_path = storage_path
self.storage = storage.ShelveStorage(str(storage_path))
[docs] def load_services(self):
hwid_map = config.load_hwid(self.config_path)
for cfg in config.iterate_service_configs(self.config_path, hwid_map.keys()):
cls = ServiceBase.get_subclass(cfg['type'], mixin=MockService)
storage_name = 'service.{}.'.format(cfg['name'])
store = storage.ProxyStorage(self.storage, storage_name)
sinstance = cls(config=cfg, storage=store)
self.add(sinstance)