def _register(modules, config): print('Registering') for name, module in modules: print('- {}'.format(name)) try: module.register(config.get(name, dict())) print('-- success') _free() except AttributeError: print('-- no register method')
def _boot(modules, loop): print('Boot') for name, module in modules: print('- {}'.format(name)) try: module.boot(loop) print('-- success') _free() except AttributeError as e: print('-- no boot method')
def _cleanup(modules, loop): print('Cleanup') for name, module in modules: print('- {}'.format(name)) try: module.cleanup(loop) print('-- success') _free() except AttributeError as e: print('-- no cleanup method') loop.stop()
def accept_handler(conn): import modules.webserver.handle_request import sys client, addr = conn.accept() print('{} connected'.format(addr)) modules.webserver.handle_request.handle_request(client, routes) client.close() _free() del modules.webserver.handle_request del sys.modules['modules.webserver.handle_request'] _free()
def init(): print('Microconfig init') modules_enabled, config = load_config() _free() loop = asyncio.PollEventLoop() imported_modules = [] print('Importing modules') for name in modules_enabled: imported_modules.append((name, import_module(name))) print('- {}'.format(name)) _free() _register(imported_modules, config) _boot(imported_modules, loop) _free(verbose=True) _run(imported_modules, loop)