Exemple #1
0
 def dispatcher_event_thread(callback, interface):
     try:
         callback(interface)
     except:
         Logger.log_traceback(callback.im_self)
     finally:
         self._decrement_event_threads()
Exemple #2
0
    def dispatch_command(self, irc, msg, command, params):
        def dispatcher_command_thread(callback, interface, params):
            try:
                callback(interface, params)
            except:
                Logger.log_traceback(callback.im_self)
            finally:
                self._decrement_event_threads()

        params = Arguments(params)

        callbacks = self.get_command_callbacks(command)

        Logger.debug1("Found %d receiver(s) for command '%s'" % (len(callbacks), command))

        if callbacks:
            interface = IRCMessageController(irc, msg)

            for (obj, callback, privileged) in callbacks:
                try:
                    # This will abort instantly as soon as a command without access is found
                    if privileged:
                        if not self.acl.check_access(msg.source, command.lower()):
                            interface.reply("Access denied")
                            return

                    thread = threading.Thread(target = dispatcher_command_thread,
                                              kwargs = {"callback": callback, "interface": interface, "params": params})
                    self._increment_event_threads()
                    thread.start()
                except Exception as e:
                    Logger.log_traceback(callback.im_self)
Exemple #3
0
    def load_plugin(self, name, search_dir = None):
        name = name.strip()
        import_name = None

        if self._loaded_plugins.has_key(name):
            raise PluginLoadError("Plugin is already loaded")

        import_name = self.find_plugin(name, search_dir)

        if not import_name:
            raise PluginLoadError("No such plugin")

        basename = import_name.rpartition(".")[2]

        try:
            mod = __import__(import_name)
            cls = getattr(mod, basename)
        except Exception as e:
            # Remove the system-entry
            if import_name and sys.modules.has_key(import_name):
                del sys.modules[import_name]

            Logger.log_traceback(self)
            raise PluginLoadError("Failed to load " + import_name)

        # Find the plugin entry point
        for objname in dir(cls):
            obj = getattr(cls, objname)
            if objname != 'Plugin' and type(obj) == types.ClassType and issubclass(obj, Plugin):
                Logger.debug("Plugin entry is '%s'" % objname)
                instance = new.instance(obj)

                # Initialize plugin instance
                instance.store  = DatastoreController().get_store(basename)
                instance.event  = self._eventcontroller
                instance.config = self._config
                instance.nets   = IRCNetsController()
                instance.plugin = self
                instance.__init__()

                self._loaded_plugins[basename.lower()] = (basename, instance, import_name)

                return True

        del sys.modules[import_name]
        raise PluginLoadError("Unable to find entry point")
Exemple #4
0
 def dispatcher_event_thread(callback, params):
     try:
         callback(params)
     except:
         Logger.log_traceback(callback.im_self)
Exemple #5
0
    Logger.set_loglevel("DEBUGL2")

sim = Simulator()

sim.load_plugin("corecommands", "core")
sim.load_plugin("aclcommands", "core")

if options.plugins:
    plugins = options.plugins.split(",")

    for plugin in plugins:
        Logger.info("Loading %s" % plugin)
        try:
            sim.load_plugin(plugin)
        except Exception as e:
            Logger.log_traceback(sim)
            sys.exit(1)

command_tree = {
    "!load":   get_available_plugins,
    "!unload": get_loaded_plugins,
    "!reload": get_loaded_plugins,
}

shell = CommandShell()
shell.set_parse_tree(command_tree)

# Start simulator and wait for the initialization events to finish
sim.start()
sim.wait_for_events()
sim.flush()