Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Added new logging to plugin loader class
Browse files Browse the repository at this point in the history
  • Loading branch information
izzy committed May 12, 2014
1 parent 1974cf5 commit 050850d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions bytebotpluginloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from sys import exit
from twisted.internet import reactor
from bytebot_log import *
from twisted.python import log

class ByteBotPluginLoader:
"""This class enables automatic loading and method calling for plugin
Expand All @@ -27,9 +29,12 @@ def __init__(self, plugins, plugin_path='plugins'):
__import__("%s.%s" % (path, plugin)).__dict__[plugin],
plugin
)()

log.msg("Loaded plugin '%s'" % plugin)
except Exception as e:
print("FATAL: Could not import plugin %s.%s" %
(path, plugin))
log.msg("FATAL: Could not import plugin %s.%s" %
(path, plugin),
level=LOG_ERROR)
exit(255)

def run(self, fn, args={}, threaded=True):
Expand All @@ -39,13 +44,23 @@ def run(self, fn, args={}, threaded=True):
args dictionary with arguments to call the method with
threaded if set to True, the functions will be run in a thread
"""
log.msg("Executing function %s on all plugins with args %s" %
(fn, args),
level=LOG_DEBUG)
for key, plugin in self.PLUGINS.iteritems():
try:
method = getattr(plugin, fn)
if not threaded:
log.msg("Execute | non-threaded | %s->%s" %
(plugin, method.__name__),
level=LOG_DEBUG)
method(**args)
else:
log.msg("Execute | threaded | %s->%s" %
(plugin, method.__name__),
level=LOG_DEBUG)
reactor.callInThread(method, **args)
except Exception as e:
print("WARNING: An error occured while executing %s in %s with %s" %
(fn, plugin, args))
log.msg("WARNING: An error occured while executing %s in %s with %s" %
(fn, plugin, args),
level=LOG_WARN)

0 comments on commit 050850d

Please sign in to comment.