1 # synarere -- a highly modular and stable IRC bot.
2 # Copyright (C) 2010 Michael Rodriguez.
3 # Rights to this code are documented in docs/LICENSE.
5 '''Module operations.'''
7 # Import required Python function.
8 from imp
import load_source
10 # Import required core modules.
11 import logger
, var
, event
17 mod
= load_source(module
, module
)
18 except ImportError, e
:
19 logger
.error('Unable to load module %s: %s' % (module
, e
))
22 # Check to make sure the module has init/fini functions.
23 if not hasattr(mod
, 'module_init'):
24 logger
.error('Unable to use module %s: No entry point has been defined.' % mod
.__name
__)
27 if not hasattr(mod
, 'module_fini'):
28 logger
.error('Unable to use module %s: No exit point has been defined.' % mod
.__name
__)
32 logger
.info('Module %s loaded.' % mod
.__name
__)
34 # Add the module to the loaded modules list.
35 var
.modules_loaded
.append(mod
)
36 event
.dispatch('OnModuleLoad', module
)
39 '''Unload a module.'''
41 # Make sure it is in the modules loaded list.
42 if module
not in var
.modules_loaded
:
43 logger
.warning('%s is not in the loaded modules list.' % module
)
48 # Remove the module from the loaded modules list.
49 var
.modules_loaded
.remove(module
)
50 event
.dispatch('OnModuleUnload', module
)
53 '''Load all modules listed in the configuration.'''
55 for i
in var
.conf
.get('module'):
61 event
.dispatch('OnLoadAllModules', name
)
64 '''Unload all loaded modules.'''
66 logger
.info('Unloading all modules.')
68 for i
in var
.modules_loaded
:
71 event
.dispatch('OnUnloadAllModules')