mirror of
https://github.com/jlu5/PyLink.git
synced 2025-10-14 07:27:25 +02:00
core: implement module loading from user-defined directories
Closes #350.
This commit is contained in:
parent
805a0502d2
commit
f6d9765f87
@ -106,6 +106,8 @@ def _rehash():
|
|||||||
|
|
||||||
# TODO: update file loggers here too.
|
# TODO: update file loggers here too.
|
||||||
|
|
||||||
|
utils.resetModuleDirs()
|
||||||
|
|
||||||
for network, sdata in new_conf['servers'].items():
|
for network, sdata in new_conf['servers'].items():
|
||||||
# Connect any new networks or disconnected networks if they aren't already.
|
# Connect any new networks or disconnected networks if they aren't already.
|
||||||
if (network not in world.networkobjects) or (not world.networkobjects[network].connection_thread.is_alive()):
|
if (network not in world.networkobjects) or (not world.networkobjects[network].connection_thread.is_alive()):
|
||||||
|
@ -54,6 +54,11 @@ bot:
|
|||||||
# extra service bots.
|
# extra service bots.
|
||||||
#spawn_services: true
|
#spawn_services: true
|
||||||
|
|
||||||
|
# Defines extra directories to look up plugins and protocol modules in.
|
||||||
|
# Environment variables (e.g. $HOME) and home folders (~) are expanded here, in that order.
|
||||||
|
#plugin_dirs: ["~/my-plugins", "~/pylink-contrib-modules/plugins"]
|
||||||
|
#protocol_dirs: ["~/pylink-contrib-modules/protocols"]
|
||||||
|
|
||||||
login:
|
login:
|
||||||
# NOTE: for users migrating from PyLink < 1.1, the old login:user/login:password settings
|
# NOTE: for users migrating from PyLink < 1.1, the old login:user/login:password settings
|
||||||
# have been deprecated. We strongly recommend migrating to the new "accounts:" block below, as
|
# have been deprecated. We strongly recommend migrating to the new "accounts:" block below, as
|
||||||
|
1
pylink
1
pylink
@ -62,6 +62,7 @@ if __name__ == '__main__':
|
|||||||
# Import plugins first globally, because they can listen for events
|
# Import plugins first globally, because they can listen for events
|
||||||
# that happen before the connection phase.
|
# that happen before the connection phase.
|
||||||
to_load = conf.conf['plugins']
|
to_load = conf.conf['plugins']
|
||||||
|
utils.resetModuleDirs()
|
||||||
# Here, we override the module lookup and import the plugins
|
# Here, we override the module lookup and import the plugins
|
||||||
# dynamically depending on which were configured.
|
# dynamically depending on which were configured.
|
||||||
for plugin in to_load:
|
for plugin in to_load:
|
||||||
|
22
utils.py
22
utils.py
@ -14,11 +14,12 @@ import argparse
|
|||||||
|
|
||||||
from .log import log
|
from .log import log
|
||||||
from . import world, conf
|
from . import world, conf
|
||||||
# This is just so protocols and plugins are importable.
|
|
||||||
|
# Load the protocol and plugin packages.
|
||||||
from pylinkirc import protocols, plugins
|
from pylinkirc import protocols, plugins
|
||||||
|
|
||||||
PLUGIN_PREFIX = 'pylinkirc.plugins.'
|
PLUGIN_PREFIX = plugins.__name__ + '.'
|
||||||
PROTOCOL_PREFIX = 'pylinkirc.protocols.'
|
PROTOCOL_PREFIX = protocols.__name__ + '.'
|
||||||
NORMALIZEWHITESPACE_RE = re.compile(r'\s+')
|
NORMALIZEWHITESPACE_RE = re.compile(r'\s+')
|
||||||
|
|
||||||
class NotAuthorizedError(Exception):
|
class NotAuthorizedError(Exception):
|
||||||
@ -147,6 +148,21 @@ def applyModes(irc, target, changedmodes):
|
|||||||
log.warning("(%s) utils.applyModes is deprecated. Use irc.applyModes() instead!", irc.name)
|
log.warning("(%s) utils.applyModes is deprecated. Use irc.applyModes() instead!", irc.name)
|
||||||
return irc.applyModes(target, changedmodes)
|
return irc.applyModes(target, changedmodes)
|
||||||
|
|
||||||
|
def expandpath(path):
|
||||||
|
"""
|
||||||
|
Returns a path expanded with environment variables and home folders (~) expanded, in that order."""
|
||||||
|
return os.path.expanduser(os.path.expandvars(path))
|
||||||
|
|
||||||
|
def resetModuleDirs():
|
||||||
|
"""
|
||||||
|
(Re)sets custom protocol module and plugin directories to the ones specified in the config.
|
||||||
|
"""
|
||||||
|
# Note: This assumes that the first element of the package path is the default one.
|
||||||
|
plugins.__path__ = [plugins.__path__[0]] + [expandpath(path) for path in conf.conf['bot'].get('plugin_dirs', [])]
|
||||||
|
log.debug('resetModuleDirs: new pylinkirc.plugins.__path__: %s', plugins.__path__)
|
||||||
|
protocols.__path__ = [protocols.__path__[0]] + [expandpath(path) for path in conf.conf['bot'].get('protocol_dirs', [])]
|
||||||
|
log.debug('resetModuleDirs: new pylinkirc.protocols.__path__: %s', protocols.__path__)
|
||||||
|
|
||||||
def loadPlugin(name):
|
def loadPlugin(name):
|
||||||
"""
|
"""
|
||||||
Imports and returns the requested plugin.
|
Imports and returns the requested plugin.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user