From bcc84b8618f641c77b0a599de9ab9d24432b8c29 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 2 Jul 2016 23:57:20 -0700 Subject: [PATCH] core: remove references to plugins/protocols_folder (#259) --- coremods/corecommands.py | 2 +- pylink | 2 +- utils.py | 12 ++++++++++-- world.py | 3 --- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/coremods/corecommands.py b/coremods/corecommands.py index ff23971..4c6b344 100644 --- a/coremods/corecommands.py +++ b/coremods/corecommands.py @@ -68,7 +68,7 @@ def load(irc, source, args): return log.info('(%s) Loading plugin %r for %s', irc.name, name, irc.getHostmask(source)) try: - world.plugins[name] = pl = utils.loadModuleFromFolder(name, world.plugins_folder) + world.plugins[name] = pl = utils.loadPlugin(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/pylink b/pylink index 5f5ce9a..495f997 100755 --- a/pylink +++ b/pylink @@ -45,7 +45,7 @@ if __name__ == '__main__': # dynamically depending on which were configured. for plugin in to_load: try: - world.plugins[plugin] = pl = utils.loadModuleFromFolder(plugin, world.plugins_folder) + world.plugins[plugin] = pl = utils.loadPlugin(plugin) except (OSError, ImportError) as e: log.exception('Failed to load plugin %r: %s: %s', plugin, type(e).__name__, str(e)) else: diff --git a/utils.py b/utils.py index 8433f86..50e9286 100644 --- a/utils.py +++ b/utils.py @@ -13,6 +13,8 @@ import collections from .log import log from . import world, conf +# This is just so protocols and plugins are importable. +from pylinkirc import protocols, plugins class NotAuthenticatedError(Exception): """ @@ -126,11 +128,17 @@ def loadModuleFromFolder(name, folder): m = importlib.machinery.SourceFileLoader(name, fullpath).load_module() return m -def getProtocolModule(protoname): +def loadPlugin(name): + """ + Imports and returns the requested plugin. + """ + return importlib.import_module('pylinkirc.plugins.' + name) + +def getProtocolModule(name): """ Imports and returns the protocol module requested. """ - return loadModuleFromFolder(protoname, world.protocols_folder) + return importlib.import_module('pylinkirc.protocols.' + name) def getDatabaseName(dbname): """ diff --git a/world.py b/world.py index f3b8ed6..b08346a 100644 --- a/world.py +++ b/world.py @@ -20,9 +20,6 @@ services = {} started = threading.Event() -plugins_folder = os.path.join(os.getcwd(), 'plugins') -protocols_folder = os.path.join(os.getcwd(), 'protocols') - version = "" source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!