Exemplo n.º 1
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, extended_description, obj = getattr(method, "setting")
                 self.register(inst.module_name, setting_name, value, obj, description, 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)
                    help_text = self.get_help_file(inst.module_name, 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, inst.module_name, help_text,
                                  sub_command, extended_description)
Exemplo n.º 3
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.º 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, "event"):
                 attrs = getattr(method, "event")
                 handler = getattr(inst, name)
                 self.register(handler, attrs.event_type, attrs.description, inst.module_name, attrs.is_hidden, attrs.is_enabled)
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, "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.º 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, "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.º 7
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.º 8
0
    def post_start(self):
        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in inst.__class__.__dict__.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)

        # remove events that are no longer registered
        self.db.exec("DELETE FROM event_config WHERE verified = 0")

        self.db.exec(
            "DELETE FROM timer_event WHERE handler NOT IN (SELECT handler FROM event_config WHERE event_type = ?)",
            ["timer"])
Exemplo n.º 9
0
    def post_start(self):
        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in self.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)

        # process deferred register calls
        for args in self.deferred_register:
            self.do_register(**args)

        self.db.exec("DELETE FROM command_config WHERE verified = 0")
Exemplo n.º 10
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)