mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-26 12:14:24 +01:00
main: load plugins in a separate loop, and call the main() of loaded plugins if present
This commit is contained in:
parent
149921ac47
commit
5d5f556ee3
15
main.py
15
main.py
@ -98,12 +98,17 @@ class Irc():
|
|||||||
for plugin in to_load:
|
for plugin in to_load:
|
||||||
try:
|
try:
|
||||||
moduleinfo = imp.find_module(plugin, plugins_folder)
|
moduleinfo = imp.find_module(plugin, plugins_folder)
|
||||||
self.loaded.append(imp.load_source(plugin, moduleinfo[1]))
|
pl = imp.load_source(plugin, moduleinfo[1])
|
||||||
|
self.loaded.append(pl)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
if str(e).startswith('No module named'):
|
if str(e).startswith('No module named'):
|
||||||
log.error('Failed to load plugin %r: the plugin could not be found.', plugin)
|
log.error('Failed to load plugin %r: the plugin could not be found.', plugin)
|
||||||
else:
|
else:
|
||||||
log.error('Failed to load plugin %r: import error %s', plugin, str(e))
|
log.error('Failed to load plugin %r: import error %s', plugin, str(e))
|
||||||
|
else:
|
||||||
|
if hasattr(pl, 'main'):
|
||||||
|
log.debug('Calling main() function of plugin %r', pl)
|
||||||
|
pl.main(irc)
|
||||||
log.info("loaded plugins: %s", self.loaded)
|
log.info("loaded plugins: %s", self.loaded)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -124,5 +129,9 @@ if __name__ == '__main__':
|
|||||||
log.critical('Failed to load protocol module: import error %s', protoname, str(e))
|
log.critical('Failed to load protocol module: import error %s', protoname, str(e))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
else:
|
else:
|
||||||
utils.networkobjects[network] = irc = Irc(network, proto, conf.conf)
|
utils.networkobjects[network] = Irc(network, proto, conf.conf)
|
||||||
irc.load_plugins()
|
# This is a separate loop to make sure that ALL networks have their
|
||||||
|
# Irc objects added into utils.networkobjects, before we load any plugins
|
||||||
|
# that may require them.
|
||||||
|
for irc in utils.networkobjects.values():
|
||||||
|
irc.load_plugins()
|
||||||
|
Loading…
Reference in New Issue
Block a user