Plug module and submodules

This commit is contained in:
Benjamin Bohard 2020-03-26 16:25:02 +01:00
parent 93b61176d8
commit e472282a33
4 changed files with 25 additions and 13 deletions

View File

@ -4,6 +4,6 @@ setup(
name='risotto',
version='0.1',
packages=['risotto' ],
scripts=['script/risotto.py'],
scripts=['script/risotto_server.py'],
package_dir={"": "src"},
)

View File

@ -17,7 +17,7 @@ from . import services
extra_routes = {}
RISOTTO_MODULES = services.get_list()
RISOTTO_MODULES = services.get_services_list()
def create_context(request):

View File

@ -13,25 +13,37 @@ from .logger import log
from pkg_resources import iter_entry_points
class Services():
modules_list = []
services = {}
modules_loaded = False
services_loaded = False
def load_services(self):
for entry_point in iter_entry_points(group='risotto_services'):
self.services.setdefault(entry_point.name, [])
self.services_loaded = True
def load_modules(self):
for entry_point in iter_entry_points(group='risotto_services'):
setattr(self, entry_point.name, entry_point.load())
for entry_point in iter_entry_points(group='risotto_modules'):
service_name, module_name = entry_point.name.split('.')
setattr(self, module_name, entry_point.load())
self.services[service_name].append(module_name)
self.modules_loaded = True
def list_modules(self):
for entry_point in iter_entry_points(group='risotto_services'):
self.modules_list.append(entry_point.name)
def get_services(self):
if not self.services_loaded:
self.load_services()
return [(s, getattr(self, s)) for s in self.services]
def get_modules(self):
if not self.modules_loaded:
self.load_modules()
return [(m, getattr(self, m)) for m in self.modules_list]
return [(m, getattr(self, m)) for s in self.get_modules_list()]
def get_list(self):
return self.modules_list
def get_services_list(self):
return self.services.keys()
def get_modules_list(self):
return [m for s in self.services for m in self.services[s]]
def link_to_dispatcher(self,
dispatcher,
@ -47,7 +59,7 @@ class Services():
services = Services()
services.list_modules()
services.load_services()
setattr(risotto, 'services', services)
def register(uris: str,
@ -74,7 +86,7 @@ class RegisterDispatcher:
# postgresql pool
self.pool = None
# load tiramisu objects
self.risotto_modules = services.get_list()
self.risotto_modules = services.get_services_list()
messages, self.option = get_messages(self.risotto_modules)
# list of uris with informations: {"v1": {"module_name.xxxxx": yyyyyy}}
self.messages = {}