Plug module and submodules
This commit is contained in:
parent
93b61176d8
commit
e472282a33
2
setup.py
2
setup.py
@ -4,6 +4,6 @@ setup(
|
|||||||
name='risotto',
|
name='risotto',
|
||||||
version='0.1',
|
version='0.1',
|
||||||
packages=['risotto' ],
|
packages=['risotto' ],
|
||||||
scripts=['script/risotto.py'],
|
scripts=['script/risotto_server.py'],
|
||||||
package_dir={"": "src"},
|
package_dir={"": "src"},
|
||||||
)
|
)
|
||||||
|
@ -17,7 +17,7 @@ from . import services
|
|||||||
extra_routes = {}
|
extra_routes = {}
|
||||||
|
|
||||||
|
|
||||||
RISOTTO_MODULES = services.get_list()
|
RISOTTO_MODULES = services.get_services_list()
|
||||||
|
|
||||||
|
|
||||||
def create_context(request):
|
def create_context(request):
|
||||||
|
@ -13,25 +13,37 @@ from .logger import log
|
|||||||
from pkg_resources import iter_entry_points
|
from pkg_resources import iter_entry_points
|
||||||
|
|
||||||
class Services():
|
class Services():
|
||||||
modules_list = []
|
services = {}
|
||||||
modules_loaded = False
|
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):
|
def load_modules(self):
|
||||||
for entry_point in iter_entry_points(group='risotto_services'):
|
for entry_point in iter_entry_points(group='risotto_modules'):
|
||||||
setattr(self, entry_point.name, entry_point.load())
|
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
|
self.modules_loaded = True
|
||||||
|
|
||||||
def list_modules(self):
|
def get_services(self):
|
||||||
for entry_point in iter_entry_points(group='risotto_services'):
|
if not self.services_loaded:
|
||||||
self.modules_list.append(entry_point.name)
|
self.load_services()
|
||||||
|
return [(s, getattr(self, s)) for s in self.services]
|
||||||
|
|
||||||
def get_modules(self):
|
def get_modules(self):
|
||||||
if not self.modules_loaded:
|
if not self.modules_loaded:
|
||||||
self.load_modules()
|
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):
|
def get_services_list(self):
|
||||||
return self.modules_list
|
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,
|
def link_to_dispatcher(self,
|
||||||
dispatcher,
|
dispatcher,
|
||||||
@ -47,7 +59,7 @@ class Services():
|
|||||||
|
|
||||||
|
|
||||||
services = Services()
|
services = Services()
|
||||||
services.list_modules()
|
services.load_services()
|
||||||
setattr(risotto, 'services', services)
|
setattr(risotto, 'services', services)
|
||||||
|
|
||||||
def register(uris: str,
|
def register(uris: str,
|
||||||
@ -74,7 +86,7 @@ class RegisterDispatcher:
|
|||||||
# postgresql pool
|
# postgresql pool
|
||||||
self.pool = None
|
self.pool = None
|
||||||
# load tiramisu objects
|
# load tiramisu objects
|
||||||
self.risotto_modules = services.get_list()
|
self.risotto_modules = services.get_services_list()
|
||||||
messages, self.option = get_messages(self.risotto_modules)
|
messages, self.option = get_messages(self.risotto_modules)
|
||||||
# list of uris with informations: {"v1": {"module_name.xxxxx": yyyyyy}}
|
# list of uris with informations: {"v1": {"module_name.xxxxx": yyyyyy}}
|
||||||
self.messages = {}
|
self.messages = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user