Пример #1
0
 def cmdhelp(self):
     """ Combined Help structure for all extensions. """
     try:
         return self.__help
     except AttributeError:
         self.__help = Help(self.extensions, logger=self.logger)
         return self.__help
Пример #2
0
    def load_extensions(self):
        """ Load BofhdExtensions (commands and help texts).

        This will load and initialize the BofhdExtensions specified by the
        configuration.

        """
        self.extensions = getattr(self, 'extensions', set())
        for cls in self.extensions:
            # Reload existing modules
            reload(sys.modules[cls.__module__])
        self.extensions = set()

        self.classmap.clear()
        self.commands.clear()

        for module_name, class_name in self.__config.extensions():
            mod = Utils.dyn_import(module_name)
            # TODO: Make dyn_import support class name
            try:
                cls = getattr(mod, class_name)
            except AttributeError:
                raise ImportError("Module '{}' has no class '{}'"
                                  .format(module_name, class_name))
            self.extensions.add(cls)

            # Map commands to BofhdExtensions
            # NOTE: Any duplicate command will be overloaded by later
            #       BofhdExtensions.
            for rpc in cls.list_commands('all_commands').keys():
                self.classmap[rpc] = cls
            for rpc in cls.list_commands('hidden_commands').keys():
                self.classmap[rpc] = cls

        # Check that all calls are implemented
        for rpc in sorted(self.classmap.keys()):
            if not hasattr(self.classmap[rpc], rpc):
                self.logger.warn("Warning, command %r is not implemented", rpc)
        self.__help = Help(self.extensions, logger=self.logger)

        self._log_help_text_mismatch()
        self._log_command_mismatch()