mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
module_loader: Split app initialization into separate steps
- Loading module is only for importing python modules and determining the order in which they should be loaded. - Initializing apps will create the instances which involves just creating the components of the apps. - Post initialization involves connecting to signals, running configuration fixes, etc. Tests: - All apps that have post initialization step have been tested. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
1147249bd8
commit
d2aee03c89
@ -112,6 +112,7 @@ def main():
|
|||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
menu.init()
|
menu.init()
|
||||||
module_loader.load_modules()
|
module_loader.load_modules()
|
||||||
|
module_loader.apps_init()
|
||||||
list_dependencies(arguments.list_dependencies)
|
list_dependencies(arguments.list_dependencies)
|
||||||
|
|
||||||
log.init()
|
log.init()
|
||||||
@ -129,6 +130,8 @@ def main():
|
|||||||
menu.init()
|
menu.init()
|
||||||
|
|
||||||
module_loader.load_modules()
|
module_loader.load_modules()
|
||||||
|
module_loader.apps_init()
|
||||||
|
module_loader.apps_post_init()
|
||||||
frontpage.add_custom_shortcuts()
|
frontpage.add_custom_shortcuts()
|
||||||
|
|
||||||
if arguments.setup is not False:
|
if arguments.setup is not False:
|
||||||
|
|||||||
@ -66,15 +66,9 @@ def load_modules():
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
logger.error('Unsatified dependency for module - %s', module_name)
|
logger.error('Unsatified dependency for module - %s', module_name)
|
||||||
|
|
||||||
logger.info('Initializing apps - %s', ', '.join(ordered_modules))
|
|
||||||
|
|
||||||
for module_name in ordered_modules:
|
for module_name in ordered_modules:
|
||||||
_initialize_module(module_name, modules[module_name])
|
|
||||||
loaded_modules[module_name] = modules[module_name]
|
loaded_modules[module_name] = modules[module_name]
|
||||||
|
|
||||||
logger.debug('App initialization completed.')
|
|
||||||
post_module_loading.send_robust(sender="module_loader")
|
|
||||||
|
|
||||||
|
|
||||||
def _insert_modules(module_name, module, remaining_modules, ordered_modules):
|
def _insert_modules(module_name, module, remaining_modules, ordered_modules):
|
||||||
"""Insert modules into a list based on dependency order"""
|
"""Insert modules into a list based on dependency order"""
|
||||||
@ -118,6 +112,13 @@ def _include_module_urls(module_import_path, module_name):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def apps_init():
|
||||||
|
"""Create apps by constructing them with components."""
|
||||||
|
logger.info('Initializing apps - %s', ', '.join(loaded_modules))
|
||||||
|
for module_name, module in loaded_modules.items():
|
||||||
|
_initialize_module(module_name, module)
|
||||||
|
|
||||||
|
|
||||||
def _initialize_module(module_name, module):
|
def _initialize_module(module_name, module):
|
||||||
"""Perform module initialization"""
|
"""Perform module initialization"""
|
||||||
|
|
||||||
@ -131,10 +132,6 @@ def _initialize_module(module_name, module):
|
|||||||
]
|
]
|
||||||
if module_classes and app_class:
|
if module_classes and app_class:
|
||||||
module.app = app_class[0][1]()
|
module.app = app_class[0][1]()
|
||||||
|
|
||||||
if module.setup_helper.get_state(
|
|
||||||
) != 'needs-setup' and module.app.is_enabled():
|
|
||||||
module.app.set_enabled(True)
|
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
logger.exception('Exception while running init for %s: %s', module,
|
logger.exception('Exception while running init for %s: %s', module,
|
||||||
exception)
|
exception)
|
||||||
@ -142,6 +139,27 @@ def _initialize_module(module_name, module):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def apps_post_init():
|
||||||
|
"""Run post initialization on each app."""
|
||||||
|
for module in loaded_modules.values():
|
||||||
|
if not hasattr(module, 'app') or not module.app:
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.app.post_init()
|
||||||
|
if module.setup_helper.get_state(
|
||||||
|
) != 'needs-setup' and module.app.is_enabled():
|
||||||
|
module.app.set_enabled(True)
|
||||||
|
except Exception as exception:
|
||||||
|
logger.exception('Exception while running post init for %s: %s',
|
||||||
|
module, exception)
|
||||||
|
if cfg.develop:
|
||||||
|
raise
|
||||||
|
|
||||||
|
logger.debug('App initialization completed.')
|
||||||
|
post_module_loading.send_robust(sender="module_loader")
|
||||||
|
|
||||||
|
|
||||||
def get_modules_to_load():
|
def get_modules_to_load():
|
||||||
"""Get the list of modules to be loaded"""
|
"""Get the list of modules to be loaded"""
|
||||||
global _modules_to_load
|
global _modules_to_load
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user