Exemplo n.º 1
0
 def test_regexpidof(self):
     """
     Test RegExpIdOf rule.
     """
     rule = RegExpIdOf(['F000.'], use_regex=True)
     self.assertEqual(
         self.filter_with_rule(rule),
         set([
             b'LOTJQC78O5B4WQGJRP',
             b'UPTJQC4VPCABZUDB75',
             b'NBTJQCIX49EKOCIHBP',
             b'C9UJQCF6ETBTV2MRRV',
             b'74UJQCKV8R4NBNHCB',
             b'4BTJQCL4CHNA5OUTKF',
             b'48TJQCGNNIR5SJRCAK',
             b'4YTJQCTEH7PQUU4AD',
             b'MTTJQC05LKVFFLN01A',
         ]))
Exemplo n.º 2
0
    def get_filter(self):
        gid = str(self.filter_id.get_text()).strip()
        father = str(self.filter_father.get_text()).strip()
        mother = str(self.filter_mother.get_text()).strip()
        child = str(self.filter_child.get_text()).strip()
        note = str(self.filter_note.get_text()).strip()
        etype = self.filter_event.get_type().xml_str()
        rtype = self.filter_family.get_relationship().xml_str()
        regex = self.filter_regex.get_active()
        tag = self.tag.get_active() > 0
        generic = self.generic.get_active() > 0

        empty = not (gid or father or mother or child or note or regex or etype
                     or rtype or tag or generic)
        if empty:
            generic_filter = None
        else:
            generic_filter = GenericFamilyFilter()
            if gid:
                rule = RegExpIdOf([gid], use_regex=regex)
                generic_filter.add_rule(rule)

            if father:
                rule = RegExpFatherName([father], use_regex=regex)
                generic_filter.add_rule(rule)

            if mother:
                rule = RegExpMotherName([mother], use_regex=regex)
                generic_filter.add_rule(rule)

            if child:
                rule = RegExpChildName([child], use_regex=regex)
                generic_filter.add_rule(rule)

            if etype:
                rule = HasEvent([etype, '', '', '', ''], use_regex=regex)
                generic_filter.add_rule(rule)

            if rtype:
                rule = HasRelType([rtype], use_regex=regex)
                generic_filter.add_rule(rule)

            if note:
                rule = HasNoteRegexp([note], use_regex=regex)
                generic_filter.add_rule(rule)

            # check the Tag
            if tag:
                model = self.tag.get_model()
                node = self.tag.get_active_iter()
                attr = model.get_value(node, 0)
                rule = HasTag([attr])
                generic_filter.add_rule(rule)

        if self.generic.get_active() != 0:
            model = self.generic.get_model()
            node = self.generic.get_active_iter()
            obj = str(model.get_value(node, 0))
            rule = MatchesFilter([obj])
            generic_filter.add_rule(rule)

        return generic_filter