3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-17 23:52:49 +01:00

utils: rename remaining functions to snake case (#476)

This commit is contained in:
James Lu 2017-08-28 20:28:10 -07:00
parent 43b6566aa8
commit 3922d44173

View File

@ -85,40 +85,45 @@ def isHostmask(text):
log.warning('utils.isHostmask() is deprecated since PyLink 2.0, use irc.is_hostmask() instead.') log.warning('utils.isHostmask() is deprecated since PyLink 2.0, use irc.is_hostmask() instead.')
return _proto_utils_class.is_hostmask(text) return _proto_utils_class.is_hostmask(text)
def expandpath(path): def expand_path(path):
""" """
Returns a path expanded with environment variables and home folders (~) expanded, in that order.""" Returns a path expanded with environment variables and home folders (~) expanded, in that order."""
return os.path.expanduser(os.path.expandvars(path)) return os.path.expanduser(os.path.expandvars(path))
expandpath = expand_path # Consistency with os.path
def resetModuleDirs(): 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('resetModuleDirs: 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('resetModuleDirs: new pylinkirc.protocols.__path__: %s', protocols.__path__) log.debug('reset_module_dirs: new pylinkirc.protocols.__path__: %s', protocols.__path__)
resetModuleDirs = reset_module_dirs
def loadPlugin(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
def getProtocolModule(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
def splitHostmask(mask): def split_hostmask(mask):
""" """
Returns a nick!user@host hostmask split into three fields: nick, user, and host. Returns a nick!user@host hostmask split into three fields: nick, user, and host.
""" """
nick, identhost = mask.split('!', 1) nick, identhost = mask.split('!', 1)
ident, host = identhost.split('@', 1) ident, host = identhost.split('@', 1)
return [nick, ident, host] return [nick, ident, host]
splitHostmask = split_hostmask
class ServiceBot(): class ServiceBot():
""" """
@ -520,7 +525,7 @@ class ServiceBot():
self._show_command_help(irc, cmd, private=True, shortform=True) self._show_command_help(irc, cmd, private=True, shortform=True)
self.reply(irc, 'End of command listing.', private=True) self.reply(irc, 'End of command listing.', private=True)
def registerService(name, *args, **kwargs): def register_service(name, *args, **kwargs):
"""Registers a service bot.""" """Registers a service bot."""
name = name.lower() name = name.lower()
if name in world.services: if name in world.services:
@ -534,8 +539,9 @@ def registerService(name, *args, **kwargs):
world.services[name] = sbot = ServiceBot(name, *args, **kwargs) world.services[name] = sbot = ServiceBot(name, *args, **kwargs)
sbot.spawn() sbot.spawn()
return sbot return sbot
registerService = register_service
def unregisterService(name): def unregister_service(name):
"""Unregisters an existing service bot.""" """Unregisters an existing service bot."""
name = name.lower() name = name.lower()
@ -554,8 +560,9 @@ def unregisterService(name):
ircobj.proto.quit(uid, "Service unloaded.") ircobj.proto.quit(uid, "Service unloaded.")
del world.services[name] del world.services[name]
unregisterService = unregister_service
def wrapArguments(prefix, args, length, separator=' ', max_args_per_line=0): def wrap_arguments(prefix, args, length, separator=' ', max_args_per_line=0):
""" """
Takes a static prefix and a list of arguments, and returns a list of strings Takes a static prefix and a list of arguments, and returns a list of strings
with the arguments wrapped across multiple lines. This is useful for breaking up with the arguments wrapped across multiple lines. This is useful for breaking up
@ -563,7 +570,7 @@ def wrapArguments(prefix, args, length, separator=' ', max_args_per_line=0):
""" """
strings = [] strings = []
assert args, "wrapArguments: no arguments given" assert args, "wrap_arguments: no arguments given"
buf = prefix buf = prefix
@ -571,7 +578,7 @@ def wrapArguments(prefix, args, length, separator=' ', max_args_per_line=0):
while args: while args:
assert len(prefix+args[0]) <= length, \ assert len(prefix+args[0]) <= length, \
"wrapArguments: Argument %r is too long for the given length %s" % (args[0], length) "wrap_arguments: Argument %r is too long for the given length %s" % (args[0], length)
# Add arguments until our buffer is up to the length limit. # Add arguments until our buffer is up to the length limit.
if (len(buf + args[0]) + 1) <= length and ((not max_args_per_line) or len(buf.split(' ')) < max_args_per_line): if (len(buf + args[0]) + 1) <= length and ((not max_args_per_line) or len(buf.split(' ')) < max_args_per_line):
@ -586,6 +593,7 @@ def wrapArguments(prefix, args, length, separator=' ', max_args_per_line=0):
strings.append(buf) strings.append(buf)
return strings return strings
wrapArguments = wrap_arguments
class IRCParser(argparse.ArgumentParser): class IRCParser(argparse.ArgumentParser):
""" """