mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-23 18:54:05 +01:00
utils: mark reset_module_dirs, load_plugin, get_protocol_module as private
This commit is contained in:
parent
1cdf16f5c9
commit
3e656cd943
@ -125,13 +125,13 @@ def rehash():
|
||||
|
||||
ircobj.log_setup()
|
||||
|
||||
utils.reset_module_dirs()
|
||||
utils._reset_module_dirs()
|
||||
|
||||
for network, sdata in new_conf['servers'].items():
|
||||
# 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()):
|
||||
try:
|
||||
proto = utils.get_protocol_module(sdata['protocol'])
|
||||
proto = utils._get_protocol_module(sdata['protocol'])
|
||||
|
||||
# API note: 2.0.x style of starting network connections
|
||||
world.networkobjects[network] = newirc = proto.Class(network)
|
||||
|
@ -106,7 +106,7 @@ def load(irc, source, args):
|
||||
return
|
||||
log.info('(%s) Loading plugin %r for %s', irc.name, name, irc.get_hostmask(source))
|
||||
try:
|
||||
world.plugins[name] = pl = utils.load_plugin(name)
|
||||
world.plugins[name] = pl = utils._load_plugin(name)
|
||||
except ImportError as e:
|
||||
if str(e) == ('No module named %r' % name):
|
||||
log.exception('Failed to load plugin %r: The plugin could not be found.', name)
|
||||
|
@ -143,11 +143,11 @@ def main():
|
||||
|
||||
# Load configured plugins
|
||||
to_load = conf.conf['plugins']
|
||||
utils.reset_module_dirs()
|
||||
utils._reset_module_dirs()
|
||||
|
||||
for plugin in to_load:
|
||||
try:
|
||||
world.plugins[plugin] = pl = utils.load_plugin(plugin)
|
||||
world.plugins[plugin] = pl = utils._load_plugin(plugin)
|
||||
except Exception as e:
|
||||
log.exception('Failed to load plugin %r: %s: %s', plugin, type(e).__name__, str(e))
|
||||
else:
|
||||
@ -164,7 +164,7 @@ def main():
|
||||
else:
|
||||
# Fetch the correct protocol module.
|
||||
try:
|
||||
proto = utils.get_protocol_module(protoname)
|
||||
proto = utils._get_protocol_module(protoname)
|
||||
|
||||
# Create and connect the network.
|
||||
world.networkobjects[network] = irc = proto.Class(network)
|
||||
|
@ -173,7 +173,7 @@ def reloadproto(irc, source, args):
|
||||
irc.error('Not enough arguments (needs 1: protocol module name)')
|
||||
return
|
||||
|
||||
proto = utils.get_protocol_module(name)
|
||||
proto = utils._get_protocol_module(name)
|
||||
importlib.reload(proto)
|
||||
|
||||
irc.reply("Done. You will have to manually disconnect and reconnect any network using the %r module for changes to apply." % name)
|
||||
|
16
utils.py
16
utils.py
@ -96,30 +96,30 @@ def expand_path(path):
|
||||
return os.path.expanduser(os.path.expandvars(path))
|
||||
expandpath = expand_path # Consistency with os.path
|
||||
|
||||
def reset_module_dirs():
|
||||
def _reset_module_dirs():
|
||||
"""
|
||||
(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['pylink'].get('plugin_dirs', [])]
|
||||
log.debug('reset_module_dirs: new pylinkirc.plugins.__path__: %s', plugins.__path__)
|
||||
log.debug('_reset_module_dirs: new pylinkirc.plugins.__path__: %s', plugins.__path__)
|
||||
protocols.__path__ = [protocols.__path__[0]] + [expandpath(path) for path in conf.conf['pylink'].get('protocol_dirs', [])]
|
||||
log.debug('reset_module_dirs: new pylinkirc.protocols.__path__: %s', protocols.__path__)
|
||||
resetModuleDirs = reset_module_dirs
|
||||
log.debug('_reset_module_dirs: new pylinkirc.protocols.__path__: %s', protocols.__path__)
|
||||
resetModuleDirs = _reset_module_dirs
|
||||
|
||||
def load_plugin(name):
|
||||
def _load_plugin(name):
|
||||
"""
|
||||
Imports and returns the requested plugin.
|
||||
"""
|
||||
return importlib.import_module(PLUGIN_PREFIX + name)
|
||||
loadPlugin = load_plugin
|
||||
loadPlugin = _load_plugin
|
||||
|
||||
def get_protocol_module(name):
|
||||
def _get_protocol_module(name):
|
||||
"""
|
||||
Imports and returns the protocol module requested.
|
||||
"""
|
||||
return importlib.import_module(PROTOCOL_PREFIX + name)
|
||||
getProtocolModule = get_protocol_module
|
||||
getProtocolModule = _get_protocol_module
|
||||
|
||||
def split_hostmask(mask):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user