Esempio n. 1
0
    def parse_triple(self, var_name, op_name, value, rule = None):
        '''Parse the rule from elements.

        Raise ParsingError on error.  The object state is undefined after an
        error.  rule may be omitted if var_name never specifies
        audit.AUDIT_ARCH.

        '''
        self.var = audit.audit_name_to_field(var_name)
        if self.var == -1:
            raise ParsingError(_('Unknown field "%s"') % var_name)
        try:
            self.op = self.__op_name_map[op_name]
        except KeyError:
            raise ParsingError(_('Unknown operator "%s"') % op_name)
        self.value = self.get_field_type(self.var).parse_value(value, self.op,
                                                               rule)
Esempio n. 2
0
    def __rule_field_var_changed(self, *_):
        it = self.rule_field_var.get_active_iter()
        util.set_sensitive_all(it is not None,
                               self.rule_field_op, self.rule_field_value,
                               self.rule_field_add)
        if it is None:
            self.rule_field_var_info.set_text('')
            return
        name = self.field_var_store.get_value(it, 0)
        try:
            var = audit.audit_name_to_field(name)
        except OSError:
            var = None

        it = self.rule_field_op.get_active_iter()
        if it:
            old_op = self.field_op_store.get_value(it, 0)
        else:
            old_op = None
        self.field_op_store.clear()
        self.field_value_store.clear()
        if var is not None:
            field_type = Field.get_field_type(var)
            ops = field_type.usual_operators(var)
            for op in ops:
                self.field_op_store.append((op,))
            if set(ops) != set(Field.all_operators):
                self.field_op_store.append(('',))
                for op in Field.all_operators:
                    if op not in ops:
                        self.field_op_store.append((op,))
            for hint in field_type.hints():
                self.field_value_store.append((hint,))
        else:
            for op in Field.all_operators:
                self.field_op_store.append((op,))
        if old_op is not None:
            util.set_combo_option(self.rule_field_op, old_op)
        self.rule_field_var_info.set_text(field_help.field_help(var))