Exemplo n.º 1
0
    def start(self):
        access_levels = {}

        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in get_attrs(inst).items():
                if hasattr(method, "command"):
                    cmd_name, params, access_level, description, help_file, sub_command, extended_description = getattr(
                        method, "command")
                    handler = getattr(inst, name)
                    module = self.util.get_module_name(handler)
                    help_text = self.get_help_file(module, help_file)

                    command_key = self.get_command_key(
                        cmd_name.lower(),
                        sub_command.lower() if sub_command else "")
                    al = access_levels.get(command_key, None)
                    if al is not None and al != access_level.lower():
                        raise Exception(
                            "Different access levels specified for forms of command '%s'"
                            % command_key)
                    access_levels[command_key] = access_level

                    self.register(handler, cmd_name, params, access_level,
                                  description, module, help_text, sub_command,
                                  extended_description)
Exemplo n.º 2
0
    def start(self):
        access_levels = {}

        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in get_attrs(inst).items():
                if hasattr(method, "command"):
                    cmd_name, params, access_level, description, help_file, sub_command, extended_description = getattr(
                        method, "command")
                    handler = getattr(inst, name)
                    module = self.util.get_module_name(handler)
                    help_text = self.get_help_file(module, help_file)

                    # TODO move this check to register()
                    if len(inspect.signature(
                            handler).parameters) != len(params) + 1:
                        raise Exception(
                            "Incorrect number of arguments for handler '%s.%s()'"
                            % (handler.__module__, handler.__name__))

                    command_key = self.get_command_key(
                        cmd_name.lower(),
                        sub_command.lower() if sub_command else "")
                    al = access_levels.get(command_key, None)
                    if al is not None and al != access_level.lower():
                        raise Exception(
                            "Different access levels specified for forms of command '%s'"
                            % command_key)
                    access_levels[command_key] = access_level

                    self.register(handler, cmd_name, params, access_level,
                                  description, module, help_text, sub_command,
                                  extended_description)
Exemplo n.º 3
0
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "event"):
                 event_type, description = getattr(method, "event")
                 handler = getattr(inst, name)
                 module = self.util.get_module_name(handler)
                 self.register(handler, event_type, description, module)
Exemplo n.º 4
0
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "setting"):
                 setting_name, value, description, obj = getattr(method, "setting")
                 handler = getattr(inst, name)
                 module = self.util.get_module_name(handler)
                 self.register(setting_name, value, description, obj, module)
Exemplo n.º 5
0
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "command"):
                 cmd_name, params, access_level, description, help_file, sub_command = getattr(method, "command")
                 handler = getattr(inst, name)
                 module = self.util.get_module_name(handler)
                 help_text = self.get_help_file(module, help_file)
                 self.register(handler, cmd_name, params, access_level, description, module, help_text, sub_command)
Exemplo n.º 6
0
    def start(self):
        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in get_attrs(inst).items():
                if hasattr(method, "command"):
                    cmd_name, params, access_level, description, help_file, sub_command, extended_description, check_access, aliases = getattr(
                        method, "command")
                    handler = getattr(inst, name)
                    module = self.util.get_module_name(handler)
                    help_text = self.get_help_file(module, help_file)
                    self.register(handler, cmd_name, params, access_level,
                                  description, module, help_text, sub_command,
                                  extended_description, check_access)
                    if len(inspect.signature(
                            handler).parameters) != len(params) + 1:
                        raise Exception(
                            "Incorrect number of arguments for handler '%s.%s()'"
                            % (handler.__module__, handler.__name__))

                    if aliases:
                        for alias in aliases:
                            self.command_alias_service.add_alias(
                                alias, cmd_name)