3
0
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:
James Lu 2018-03-02 20:04:49 -08:00
parent 1cdf16f5c9
commit 3e656cd943
5 changed files with 15 additions and 15 deletions

View File

@ -125,13 +125,13 @@ def rehash():
ircobj.log_setup() ircobj.log_setup()
utils.reset_module_dirs() utils._reset_module_dirs()
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()):
try: 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 # API note: 2.0.x style of starting network connections
world.networkobjects[network] = newirc = proto.Class(network) world.networkobjects[network] = newirc = proto.Class(network)

View File

@ -106,7 +106,7 @@ def load(irc, source, args):
return return
log.info('(%s) Loading plugin %r for %s', irc.name, name, irc.get_hostmask(source)) log.info('(%s) Loading plugin %r for %s', irc.name, name, irc.get_hostmask(source))
try: try:
world.plugins[name] = pl = utils.load_plugin(name) world.plugins[name] = pl = utils._load_plugin(name)
except ImportError as e: except ImportError as e:
if str(e) == ('No module named %r' % name): if str(e) == ('No module named %r' % name):
log.exception('Failed to load plugin %r: The plugin could not be found.', name) log.exception('Failed to load plugin %r: The plugin could not be found.', name)

View File

@ -143,11 +143,11 @@ def main():
# Load configured plugins # Load configured plugins
to_load = conf.conf['plugins'] to_load = conf.conf['plugins']
utils.reset_module_dirs() utils._reset_module_dirs()
for plugin in to_load: for plugin in to_load:
try: try:
world.plugins[plugin] = pl = utils.load_plugin(plugin) world.plugins[plugin] = pl = utils._load_plugin(plugin)
except Exception as e: except Exception as e:
log.exception('Failed to load plugin %r: %s: %s', plugin, type(e).__name__, str(e)) log.exception('Failed to load plugin %r: %s: %s', plugin, type(e).__name__, str(e))
else: else:
@ -164,7 +164,7 @@ def main():
else: else:
# Fetch the correct protocol module. # Fetch the correct protocol module.
try: try:
proto = utils.get_protocol_module(protoname) proto = utils._get_protocol_module(protoname)
# Create and connect the network. # Create and connect the network.
world.networkobjects[network] = irc = proto.Class(network) world.networkobjects[network] = irc = proto.Class(network)

View File

@ -173,7 +173,7 @@ def reloadproto(irc, source, args):
irc.error('Not enough arguments (needs 1: protocol module name)') irc.error('Not enough arguments (needs 1: protocol module name)')
return return
proto = utils.get_protocol_module(name) proto = utils._get_protocol_module(name)
importlib.reload(proto) 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) irc.reply("Done. You will have to manually disconnect and reconnect any network using the %r module for changes to apply." % name)

View File

@ -96,30 +96,30 @@ def expand_path(path):
return os.path.expanduser(os.path.expandvars(path)) return os.path.expanduser(os.path.expandvars(path))
expandpath = expand_path # Consistency with os.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. (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. # 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', [])] 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', [])] 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__) log.debug('_reset_module_dirs: new pylinkirc.protocols.__path__: %s', protocols.__path__)
resetModuleDirs = reset_module_dirs resetModuleDirs = _reset_module_dirs
def load_plugin(name): def _load_plugin(name):
""" """
Imports and returns the requested plugin. Imports and returns the requested plugin.
""" """
return importlib.import_module(PLUGIN_PREFIX + name) 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. Imports and returns the protocol module requested.
""" """
return importlib.import_module(PROTOCOL_PREFIX + name) return importlib.import_module(PROTOCOL_PREFIX + name)
getProtocolModule = get_protocol_module getProtocolModule = _get_protocol_module
def split_hostmask(mask): def split_hostmask(mask):
""" """