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.
19 mod
= load_source(module
, module
)
20 except ImportError, e
:
21 logger
.error('load(): unable to load module %s: %s' % (module
, e
))
24 # Check to make sure the module has init/fini functions.
25 if not hasattr(mod
, 'module_init'):
26 logger
.error('load(): unable to use module %s: no entry point has been defined' % mod
.__name
__)
29 if not hasattr(mod
, 'module_fini'):
30 logger
.error('load(): unable to use module %s: no exit point has been defined' % mod
.__name
__)
34 logger
.info('load(): module %s loaded' % mod
.__name
__)
36 # Add the module to the loaded modules list.
37 var
.modules_loaded
.append(mod
)
40 '''Unload a module.'''
42 # Make sure it is in the modules loaded list.
43 if module
not in var
.modules_loaded
:
44 logger
.warning('unload(): %s is not in the loaded modules list' % module
)
49 # Remove the module from the loaded modules list.
50 var
.modules_loaded
.remove(module
)
53 '''Load all modules listed in the configuration.'''
56 for i
in var
.conf
.get('module'):
62 pass # Means they dont want modules.
65 '''Unload all loaded modules.'''
67 for i
in var
.modules_loaded
: