From 3e656cd94370d884fbe93f6e397b9c42817fb8c0 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 2 Mar 2018 20:04:49 -0800 Subject: [PATCH] utils: mark reset_module_dirs, load_plugin, get_protocol_module as private --- coremods/control.py | 4 ++-- coremods/corecommands.py | 2 +- launcher.py | 6 +++--- plugins/networks.py | 2 +- utils.py | 16 ++++++++-------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/coremods/control.py b/coremods/control.py index c9a8242..1b6975b 100644 --- a/coremods/control.py +++ b/coremods/control.py @@ -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) diff --git a/coremods/corecommands.py b/coremods/corecommands.py index 17858d7..d5e350d 100644 --- a/coremods/corecommands.py +++ b/coremods/corecommands.py @@ -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) diff --git a/launcher.py b/launcher.py index 6293f03..766dc49 100644 --- a/launcher.py +++ b/launcher.py @@ -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) diff --git a/plugins/networks.py b/plugins/networks.py index 2130156..5720f08 100644 --- a/plugins/networks.py +++ b/plugins/networks.py @@ -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) diff --git a/utils.py b/utils.py index 9d95673..ecb1e91 100644 --- a/utils.py +++ b/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): """