mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-25 04:02:45 +01:00
49 lines
1.7 KiB
Python
Executable File
49 lines
1.7 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import os
|
|
import sys
|
|
|
|
# This must be done before conf imports, so we get the real conf instead of testing one.
|
|
os.chdir(os.path.dirname(__file__))
|
|
import world
|
|
world.testing = False
|
|
|
|
import conf
|
|
from log import log
|
|
import classes
|
|
import utils
|
|
import coreplugin
|
|
|
|
if __name__ == '__main__':
|
|
log.info('PyLink %s starting...', world.version)
|
|
|
|
# Write a PID file.
|
|
with open('%s.pid' % conf.confname, 'w') as f:
|
|
f.write(str(os.getpid()))
|
|
|
|
# Import plugins first globally, because they can listen for events
|
|
# that happen before the connection phase.
|
|
to_load = conf.conf['plugins']
|
|
# Here, we override the module lookup and import the plugins
|
|
# dynamically depending on which were configured.
|
|
for plugin in to_load:
|
|
try:
|
|
world.plugins[plugin] = pl = utils.loadModuleFromFolder(plugin, world.plugins_folder)
|
|
except ImportError as e:
|
|
if str(e) == ('No module named %r' % plugin):
|
|
log.error('Failed to load plugin %r: The plugin could not be found.', plugin)
|
|
else:
|
|
log.error('Failed to load plugin %r: ImportError: %s', plugin, str(e))
|
|
else:
|
|
if hasattr(pl, 'main'):
|
|
log.debug('Calling main() function of plugin %r', pl)
|
|
pl.main()
|
|
|
|
for network in conf.conf['servers']:
|
|
proto = utils.getProtoModule(conf.conf['servers'][network]['protocol'])
|
|
world.networkobjects[network] = irc = classes.Irc(network, proto, conf.conf)
|
|
log.debug('Calling main() function of coreplugin on network %s', irc.name)
|
|
coreplugin.main(irc)
|
|
world.started.set()
|
|
log.info("loaded plugins: %s", world.plugins)
|