From 927415ee88f94a39c4d23cba8c20bb4793c272e1 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 8 Aug 2013 22:51:44 +0000 Subject: [PATCH] Add regular expressions to rules svn: r22823 --- gramps/gen/filters/rules/__init__.py | 1 + gramps/gen/filters/rules/_hasattributebase.py | 3 +- gramps/gen/filters/rules/_hasnoteregexbase.py | 23 +++----- gramps/gen/filters/rules/_regexpidbase.py | 20 +++---- gramps/gen/filters/rules/citation/__init__.py | 1 - .../filters/rules/citation/_hasnoteregexp.py | 2 +- .../rules/citation/_matchespagesubstringof.py | 10 ++-- .../gen/filters/rules/citation/_regexpidof.py | 2 +- gramps/gen/filters/rules/event/__init__.py | 1 - .../gen/filters/rules/event/_hascitation.py | 2 +- gramps/gen/filters/rules/event/_hasdata.py | 27 ++++------ .../gen/filters/rules/event/_hasnoteregexp.py | 2 +- gramps/gen/filters/rules/event/_regexpidof.py | 2 +- gramps/gen/filters/rules/family/__init__.py | 10 ++-- .../filters/rules/family/_childregexpidof.py | 53 +++++++++++++++++++ .../filters/rules/family/_fatherregexpidof.py | 53 +++++++++++++++++++ .../gen/filters/rules/family/_hascitation.py | 2 +- .../filters/rules/family/_hasnoteregexp.py | 2 +- .../filters/rules/family/_motherregexpidof.py | 53 +++++++++++++++++++ .../gen/filters/rules/family/_regexpidof.py | 2 +- gramps/gen/filters/rules/media/__init__.py | 1 - .../gen/filters/rules/media/_hasnoteregexp.py | 3 +- gramps/gen/filters/rules/media/_regexpidof.py | 2 +- gramps/gen/filters/rules/note/__init__.py | 1 - gramps/gen/filters/rules/note/_hasnote.py | 1 + .../filters/rules/note/_matchesregexpof.py | 21 +++----- gramps/gen/filters/rules/note/_regexpidof.py | 2 +- gramps/gen/filters/rules/person/__init__.py | 1 - gramps/gen/filters/rules/person/_hasbirth.py | 17 +++--- gramps/gen/filters/rules/person/_hasdeath.py | 17 +++--- .../rules/person/_hasfamilyattribute.py | 4 +- .../filters/rules/person/_hasfamilyevent.py | 16 +++--- .../filters/rules/person/_hasnoteregexp.py | 2 +- .../gen/filters/rules/person/_regexpidof.py | 2 +- .../gen/filters/rules/person/_regexpname.py | 19 +++---- gramps/gen/filters/rules/place/__init__.py | 1 - .../gen/filters/rules/place/_hasnoteregexp.py | 2 +- gramps/gen/filters/rules/place/_regexpidof.py | 2 +- .../gen/filters/rules/repository/__init__.py | 1 - .../rules/repository/_hasnoteregexp.py | 3 +- .../repository/_matchesnamesubstringof.py | 10 ++-- .../filters/rules/repository/_regexpidof.py | 2 +- gramps/gen/filters/rules/source/__init__.py | 1 - .../filters/rules/source/_hasnoteregexp.py | 2 +- .../source/_hasrepositorycallnumberref.py | 16 +++--- .../rules/source/_matchestitlesubstringof.py | 10 ++-- .../gen/filters/rules/source/_regexpidof.py | 2 +- po/POTFILES.in | 3 ++ 48 files changed, 272 insertions(+), 163 deletions(-) create mode 100644 gramps/gen/filters/rules/family/_childregexpidof.py create mode 100644 gramps/gen/filters/rules/family/_fatherregexpidof.py create mode 100644 gramps/gen/filters/rules/family/_motherregexpidof.py diff --git a/gramps/gen/filters/rules/__init__.py b/gramps/gen/filters/rules/__init__.py index 8432c7a7b..249b12a4a 100644 --- a/gramps/gen/filters/rules/__init__.py +++ b/gramps/gen/filters/rules/__init__.py @@ -73,6 +73,7 @@ from ._rule import Rule from ._everything import Everything from ._hasgrampsid import HasGrampsId +from ._regexpidbase import RegExpIdBase from ._isprivate import IsPrivate from ._ispublic import IsPublic from ._hastextmatchingsubstringof import HasTextMatchingSubstringOf diff --git a/gramps/gen/filters/rules/_hasattributebase.py b/gramps/gen/filters/rules/_hasattributebase.py index 8bd8d7c56..7c2854dd1 100644 --- a/gramps/gen/filters/rules/_hasattributebase.py +++ b/gramps/gen/filters/rules/_hasattributebase.py @@ -51,6 +51,7 @@ class HasAttributeBase(Rule): description = "Matches objects with the given attribute " \ "of a particular value" category = _('General filters') + allow_regex = True def apply(self, db, obj): if not self.list[0]: @@ -61,5 +62,5 @@ class HasAttributeBase(Rule): name_match = attr.get_type() == specified_type if name_match: - return attr.get_value().upper().find(self.list[1].upper()) != -1 + return self.match_substring(1, attr.get_value()) return False diff --git a/gramps/gen/filters/rules/_hasnoteregexbase.py b/gramps/gen/filters/rules/_hasnoteregexbase.py index 3871b34b8..f71af94fb 100644 --- a/gramps/gen/filters/rules/_hasnoteregexbase.py +++ b/gramps/gen/filters/rules/_hasnoteregexbase.py @@ -37,30 +37,23 @@ _ = glocale.translation.gettext from . import Rule #------------------------------------------------------------------------- -# "People having notes that contain a substring" +# Objects having notes that contain a substring or match a regular expression #------------------------------------------------------------------------- class HasNoteRegexBase(Rule): - """People having notes containing .""" + """Objects having notes containing .""" - labels = [ _('Regular expression:')] - name = 'Objects having notes containing ' - description = "Matches objects whose notes contain text " \ - "matching a regular expression" + labels = [ _('Text:')] + name = 'Objects having notes containing ' + description = ("Matches objects whose notes contain a substring " + "or match a regular expression") category = _('General filters') - - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0],re.I|re.U|re.L) - except: - self.match = re.compile('') + allow_regex = True def apply(self, db, person): notelist = person.get_note_list() for notehandle in notelist: note = db.get_note_from_handle(notehandle) n = note.get() - if self.match.search(n) is not None: + if self.match_substring(0, n) is not None: return True return False diff --git a/gramps/gen/filters/rules/_regexpidbase.py b/gramps/gen/filters/rules/_regexpidbase.py index 90df14adb..509eae96c 100644 --- a/gramps/gen/filters/rules/_regexpidbase.py +++ b/gramps/gen/filters/rules/_regexpidbase.py @@ -43,22 +43,16 @@ from . import Rule #------------------------------------------------------------------------- class RegExpIdBase(Rule): """ - Rule that checks for an object whose GRAMPS ID matches regular expression. + Objects with a Gramps ID that contains a substring or matches a + regular expression. """ - labels = [ _('Regular expression:') ] + labels = [ _('Text:') ] name = 'Objects with ' - description = "Matches objects whose Gramps ID matches " \ - "the regular expression" + description = "Matches objects whose Gramps ID contains a substring " \ + "or matches a regular expression" category = _('General filters') - - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0], re.I|re.U|re.L) - except: - self.match = re.compile('') + allow_regex = True def apply(self, db, obj): - return self.match.search(obj.gramps_id) is not None + return self.match_substring(0, obj.gramps_id) diff --git a/gramps/gen/filters/rules/citation/__init__.py b/gramps/gen/filters/rules/citation/__init__.py index d29446045..67c523c12 100644 --- a/gramps/gen/filters/rules/citation/__init__.py +++ b/gramps/gen/filters/rules/citation/__init__.py @@ -52,7 +52,6 @@ editor_rule_list = [ HasGallery, HasIdOf, HasNote, - HasNoteMatchingSubstringOf, HasNoteRegexp, HasReferenceCountOf, HasSource, diff --git a/gramps/gen/filters/rules/citation/_hasnoteregexp.py b/gramps/gen/filters/rules/citation/_hasnoteregexp.py index 574eea080..a5d8553c1 100644 --- a/gramps/gen/filters/rules/citation/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/citation/_hasnoteregexp.py @@ -41,6 +41,6 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Citations having notes containing ') + name = _('Citations having notes containing ') description = _("Matches citations whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/citation/_matchespagesubstringof.py b/gramps/gen/filters/rules/citation/_matchespagesubstringof.py index aabe8910d..0ae76f25b 100644 --- a/gramps/gen/filters/rules/citation/_matchespagesubstringof.py +++ b/gramps/gen/filters/rules/citation/_matchespagesubstringof.py @@ -41,15 +41,13 @@ from .. import Rule class MatchesPageSubstringOf(Rule): """Citation Volume/Page title containing """ - labels = [ _('Substring:')] - name = _('Citation Volume/Page containing ') + labels = [ _('Text:')] + name = _('Citations with Volume/Page containing ') description = _("Matches citations whose Volume/Page contains a " "certain substring") category = _('General filters') + allow_regex = True def apply(self, db, object): """ Apply the filter """ - title = object.get_page() - if title.upper().find(self.list[0].upper()) != -1: - return True - return False + return self.match_substring(0, object.get_page()) diff --git a/gramps/gen/filters/rules/citation/_regexpidof.py b/gramps/gen/filters/rules/citation/_regexpidof.py index 7122704e1..8e2c2818a 100644 --- a/gramps/gen/filters/rules/citation/_regexpidof.py +++ b/gramps/gen/filters/rules/citation/_regexpidof.py @@ -47,6 +47,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Citations with matching regular expression') + name = _('Citations with Id containing ') description = _("Matches citations whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/event/__init__.py b/gramps/gen/filters/rules/event/__init__.py index e2a594409..653981d26 100644 --- a/gramps/gen/filters/rules/event/__init__.py +++ b/gramps/gen/filters/rules/event/__init__.py @@ -59,7 +59,6 @@ editor_rule_list = [ HasCitation, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, EventPrivate, diff --git a/gramps/gen/filters/rules/event/_hascitation.py b/gramps/gen/filters/rules/event/_hascitation.py index e4ed276a0..026c38559 100644 --- a/gramps/gen/filters/rules/event/_hascitation.py +++ b/gramps/gen/filters/rules/event/_hascitation.py @@ -50,7 +50,7 @@ class HasCitation(HasCitationBase): labels = [ _('Volume/Page:'), _('Date:'), _('Confidence level:')] - name = _('Event with the ') + name = _('Events with the ') description = _("Matches events with a citation of a particular " "value") diff --git a/gramps/gen/filters/rules/event/_hasdata.py b/gramps/gen/filters/rules/event/_hasdata.py index 67c98e7ee..99ae86694 100644 --- a/gramps/gen/filters/rules/event/_hasdata.py +++ b/gramps/gen/filters/rules/event/_hasdata.py @@ -50,14 +50,11 @@ class HasData(Rule): name = _('Events with ') description = _("Matches events with data of a particular value") category = _('General filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - + def prepare(self, dbase): self.event_type = self.list[0] self.date = self.list[1] - self.place = self.list[2] - self.description = self.list[3] if self.event_type: self.event_type = EventType() @@ -71,26 +68,24 @@ class HasData(Rule): # No match return False - ed = event.get_description().upper() - if self.description and ed.find(self.description.upper()) == -1: - # No match - return False - if self.date and not event.get_date_object().match(self.date): # No match return False - if self.place: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.place.upper()) == -1: + if self.list[2]: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(2, place.get_title()): # No match return False else: # No place attached to event return False + if not self.match_substring(3, event.get_description()): + # No match + return False + # All conditions matched return True diff --git a/gramps/gen/filters/rules/event/_hasnoteregexp.py b/gramps/gen/filters/rules/event/_hasnoteregexp.py index 1eb1f54f3..6a57d40cf 100644 --- a/gramps/gen/filters/rules/event/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/event/_hasnoteregexp.py @@ -40,6 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Events having notes containing ') + name = _('Events having notes containing ') description = _("Matches events whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/event/_regexpidof.py b/gramps/gen/filters/rules/event/_regexpidof.py index 00365ead1..70f2a37bf 100644 --- a/gramps/gen/filters/rules/event/_regexpidof.py +++ b/gramps/gen/filters/rules/event/_regexpidof.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Events with matching regular expression') + name = _('Events with Id containing ') description = _("Matches events whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/family/__init__.py b/gramps/gen/filters/rules/family/__init__.py index f61edbacf..98bd63894 100644 --- a/gramps/gen/filters/rules/family/__init__.py +++ b/gramps/gen/filters/rules/family/__init__.py @@ -54,10 +54,13 @@ from ._matchesfilter import MatchesFilter from ._matchessourceconfidence import MatchesSourceConfidence from ._fatherhasnameof import FatherHasNameOf from ._fatherhasidof import FatherHasIdOf +from ._fatherregexpidof import FatherRegExpIdOf from ._motherhasnameof import MotherHasNameOf from ._motherhasidof import MotherHasIdOf +from ._motherregexpidof import MotherRegExpIdOf from ._childhasnameof import ChildHasNameOf from ._childhasidof import ChildHasIdOf +from ._childregexpidof import ChildRegExpIdOf from ._changedsince import ChangedSince from ._hastag import HasTag from ._hastwins import HasTwins @@ -71,7 +74,6 @@ editor_rule_list = [ HasNote, RegExpIdOf, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, HasSourceOf, @@ -83,11 +85,11 @@ editor_rule_list = [ MatchesFilter, MatchesSourceConfidence, FatherHasNameOf, - FatherHasIdOf, + FatherRegExpIdOf, MotherHasNameOf, - MotherHasIdOf, + MotherRegExpIdOf, ChildHasNameOf, - ChildHasIdOf, + ChildRegExpIdOf, ChangedSince, HasTag, HasTwins, diff --git a/gramps/gen/filters/rules/family/_childregexpidof.py b/gramps/gen/filters/rules/family/_childregexpidof.py new file mode 100644 index 000000000..dd2b48ef9 --- /dev/null +++ b/gramps/gen/filters/rules/family/_childregexpidof.py @@ -0,0 +1,53 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from ....const import GRAMPS_LOCALE as glocale +_ = glocale.translation.gettext + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from .. import RegExpIdBase +from ._memberbase import child_base + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class ChildRegExpIdOf(RegExpIdBase): + """Rule that checks for a person with a specific GRAMPS ID""" + + labels = [ _('Person ID:') ] + name = _('Families having child with Id containing ') + description = _("Matches families where child has a specified " + "Gramps ID") + category = _('Child filters') + base_class = RegExpIdBase + apply = child_base diff --git a/gramps/gen/filters/rules/family/_fatherregexpidof.py b/gramps/gen/filters/rules/family/_fatherregexpidof.py new file mode 100644 index 000000000..fbe3d1097 --- /dev/null +++ b/gramps/gen/filters/rules/family/_fatherregexpidof.py @@ -0,0 +1,53 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from ....const import GRAMPS_LOCALE as glocale +_ = glocale.translation.gettext + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from .. import RegExpIdBase +from ._memberbase import father_base + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class FatherRegExpIdOf(RegExpIdBase): + """Rule that checks for a person with a specific GRAMPS ID""" + + labels = [ _('Person ID:') ] + name = _('Families having father with Id containing ') + description = _("Matches families whose father has a specified " + "Gramps ID") + category = _('Father filters') + base_class = RegExpIdBase + apply = father_base diff --git a/gramps/gen/filters/rules/family/_hascitation.py b/gramps/gen/filters/rules/family/_hascitation.py index 73990aa67..90349cda7 100644 --- a/gramps/gen/filters/rules/family/_hascitation.py +++ b/gramps/gen/filters/rules/family/_hascitation.py @@ -50,6 +50,6 @@ class HasCitation(HasCitationBase): labels = [ _('Volume/Page:'), _('Date:'), _('Confidence level:')] - name = _('Family with the ') + name = _('Families with the ') description = _("Matches families with a citation of a particular " "value") diff --git a/gramps/gen/filters/rules/family/_hasnoteregexp.py b/gramps/gen/filters/rules/family/_hasnoteregexp.py index 9ed08b5b8..d13a0759f 100644 --- a/gramps/gen/filters/rules/family/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/family/_hasnoteregexp.py @@ -40,7 +40,7 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Families having notes containing ') + name = _('Families having notes containing ') description = _("Matches families whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/family/_motherregexpidof.py b/gramps/gen/filters/rules/family/_motherregexpidof.py new file mode 100644 index 000000000..e5e5f66ca --- /dev/null +++ b/gramps/gen/filters/rules/family/_motherregexpidof.py @@ -0,0 +1,53 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from ....const import GRAMPS_LOCALE as glocale +_ = glocale.translation.gettext + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from .. import RegExpIdBase +from ._memberbase import mother_base + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class MotherRegExpIdOf(RegExpIdBase): + """Rule that checks for a person with a specific GRAMPS ID""" + + labels = [ _('Person ID:') ] + name = _('Families having mother with Id containing ') + description = _("Matches families whose mother has a specified " + "Gramps ID") + category = _('Mother filters') + base_class = RegExpIdBase + apply = mother_base diff --git a/gramps/gen/filters/rules/family/_regexpidof.py b/gramps/gen/filters/rules/family/_regexpidof.py index c9f4b1be6..584f19a43 100644 --- a/gramps/gen/filters/rules/family/_regexpidof.py +++ b/gramps/gen/filters/rules/family/_regexpidof.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Families with matching regular expression') + name = _('Families with Id containing ') description = _("Matches families whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/media/__init__.py b/gramps/gen/filters/rules/media/__init__.py index ff75b0355..304d6e624 100644 --- a/gramps/gen/filters/rules/media/__init__.py +++ b/gramps/gen/filters/rules/media/__init__.py @@ -47,7 +47,6 @@ editor_rule_list = [ HasIdOf, RegExpIdOf, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, HasSourceOf, diff --git a/gramps/gen/filters/rules/media/_hasnoteregexp.py b/gramps/gen/filters/rules/media/_hasnoteregexp.py index da94b4406..c9b05786c 100644 --- a/gramps/gen/filters/rules/media/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/media/_hasnoteregexp.py @@ -40,7 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Media objects having notes ' - 'containing ') + name = _('Media objects having notes containing ') description = _("Matches media objects whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/media/_regexpidof.py b/gramps/gen/filters/rules/media/_regexpidof.py index 4cf5debce..0339f3f45 100644 --- a/gramps/gen/filters/rules/media/_regexpidof.py +++ b/gramps/gen/filters/rules/media/_regexpidof.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Media Objects with matching regular expression') + name = _('Media objects with Id containing ') description = _("Matches media objects whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/note/__init__.py b/gramps/gen/filters/rules/note/__init__.py index 3f2e9a8e2..7536d9c6b 100644 --- a/gramps/gen/filters/rules/note/__init__.py +++ b/gramps/gen/filters/rules/note/__init__.py @@ -44,7 +44,6 @@ editor_rule_list = [ RegExpIdOf, HasNote, MatchesRegexpOf, - MatchesSubstringOf, HasReferenceCountOf, NotePrivate, MatchesFilter, diff --git a/gramps/gen/filters/rules/note/_hasnote.py b/gramps/gen/filters/rules/note/_hasnote.py index c49731eb0..8f2674b59 100644 --- a/gramps/gen/filters/rules/note/_hasnote.py +++ b/gramps/gen/filters/rules/note/_hasnote.py @@ -51,6 +51,7 @@ class HasNote(Rule): name = _('Notes matching parameters') description = _("Matches Notes with particular parameters") category = _('General filters') + allow_regex = True def prepare(self, dbase): if self.list[1]: diff --git a/gramps/gen/filters/rules/note/_matchesregexpof.py b/gramps/gen/filters/rules/note/_matchesregexpof.py index 86536a612..51eeb2d08 100644 --- a/gramps/gen/filters/rules/note/_matchesregexpof.py +++ b/gramps/gen/filters/rules/note/_matchesregexpof.py @@ -38,27 +38,20 @@ _ = glocale.translation.gettext from .. import Rule #------------------------------------------------------------------------- -# "Repos having notes that contain a substring" +# Notes that contain a substring or match a regular expression #------------------------------------------------------------------------- class MatchesRegexpOf(Rule): - labels = [ _('Regular expression:')] - name = _('Notes containing ') - description = _("Matches notes that contain text " - "which matches a regular expression") + labels = [ _('Text:')] + name = _('Notes containing ') + description = _("Matches notes that contain a substring " + "or match a regular expression") category = _('General filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0], re.I|re.U|re.L) - except: - self.match = re.compile('') - def apply(self, db, note): """ Apply the filter """ text = note.get() - if self.match.search(text) is not None: + if self.match_substring(0, text) is not None: return True return False diff --git a/gramps/gen/filters/rules/note/_regexpidof.py b/gramps/gen/filters/rules/note/_regexpidof.py index 4144a2dd2..38c72a73c 100644 --- a/gramps/gen/filters/rules/note/_regexpidof.py +++ b/gramps/gen/filters/rules/note/_regexpidof.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Notes with matching regular expression') + name = _('Notes with Id containing ') description = _("Matches notes whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/person/__init__.py b/gramps/gen/filters/rules/person/__init__.py index 921957679..1d290cd9a 100644 --- a/gramps/gen/filters/rules/person/__init__.py +++ b/gramps/gen/filters/rules/person/__init__.py @@ -187,7 +187,6 @@ editor_rule_list = [ HasTextMatchingSubstringOf, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, RegExpIdOf, Disconnected, ChangedSince, diff --git a/gramps/gen/filters/rules/person/_hasbirth.py b/gramps/gen/filters/rules/person/_hasbirth.py index 078571f77..c70f0ce21 100644 --- a/gramps/gen/filters/rules/person/_hasbirth.py +++ b/gramps/gen/filters/rules/person/_hasbirth.py @@ -50,9 +50,9 @@ class HasBirth(Rule): name = _('People with the ') description = _("Matches people with birth data of a particular value") category = _('Event filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) + def prepare(self, db): if self.list[0]: self.date = parser.parse(self.list[0]) else: @@ -69,9 +69,7 @@ class HasBirth(Rule): if event.get_type() != EventType.BIRTH: # No match: wrong type continue - ed = event.get_description().upper() - if self.list[2] \ - and ed.find(self.list[2].upper())==-1: + if not self.match_substring(2, event.get_description()): # No match: wrong description continue if self.date: @@ -79,11 +77,10 @@ class HasBirth(Rule): # No match: wrong date continue if self.list[1]: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.list[1].upper()) == -1: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(1, place.get_title()): # No match: wrong place continue else: diff --git a/gramps/gen/filters/rules/person/_hasdeath.py b/gramps/gen/filters/rules/person/_hasdeath.py index d77e4186f..5216b2da3 100644 --- a/gramps/gen/filters/rules/person/_hasdeath.py +++ b/gramps/gen/filters/rules/person/_hasdeath.py @@ -50,9 +50,9 @@ class HasDeath(Rule): name = _('People with the ') description = _("Matches people with death data of a particular value") category = _('Event filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) + def prepare(self, db): if self.list[0]: self.date = parser.parse(self.list[0]) else: @@ -69,9 +69,7 @@ class HasDeath(Rule): if event.get_type() != EventType.DEATH: # No match: wrong type continue - ed = event.get_description().upper() - if self.list[2] \ - and ed.find(self.list[2].upper())==-1: + if not self.match_substring(2, event.get_description()): # No match: wrong description continue if self.date: @@ -79,11 +77,10 @@ class HasDeath(Rule): # No match: wrong date continue if self.list[1]: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.list[1].upper()) == -1: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(1, place.get_title()): # No match: wrong place continue else: diff --git a/gramps/gen/filters/rules/person/_hasfamilyattribute.py b/gramps/gen/filters/rules/person/_hasfamilyattribute.py index c17c96c81..c68505aa6 100644 --- a/gramps/gen/filters/rules/person/_hasfamilyattribute.py +++ b/gramps/gen/filters/rules/person/_hasfamilyattribute.py @@ -48,6 +48,7 @@ class HasFamilyAttribute(Rule): description = _("Matches people with the family attribute " "of a particular value") category = _('General filters') + allow_regex = True def apply(self,db,person): if not self.list[0]: @@ -59,8 +60,7 @@ class HasFamilyAttribute(Rule): for attr in f.get_attribute_list(): if attr: name_match = self.list[0] == attr.get_type() - value_match = \ - attr.get_value().upper().find(self.list[1].upper()) != -1 + value_match = self.match_substring(1, attr.get_value()) if name_match and value_match: return True return False diff --git a/gramps/gen/filters/rules/person/_hasfamilyevent.py b/gramps/gen/filters/rules/person/_hasfamilyevent.py index 6a4a7fc9c..3131d8569 100644 --- a/gramps/gen/filters/rules/person/_hasfamilyevent.py +++ b/gramps/gen/filters/rules/person/_hasfamilyevent.py @@ -53,6 +53,7 @@ class HasFamilyEvent(Rule): name = _('People with the family ') description = _("Matches people with a family event of a particular value") category = _('Event filters') + allow_regex = True def prepare(self,db): self.date = None @@ -78,18 +79,17 @@ class HasFamilyEvent(Rule): specified_type.set_from_xml_str(self.list[0]) if event.type != specified_type: val = 0 - v = self.list[3] - if v and event.get_description().upper().find(v.upper())==-1: - val = 0 + if self.list[3]: + if not self.match_substring(3, event.get_description()): + val = 0 if self.date: if event.get_date_object().match(self.date): val = 0 if self.list[2]: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.list[2].upper()) == -1: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(2, place.get_title()): val = 0 else: val = 0 diff --git a/gramps/gen/filters/rules/person/_hasnoteregexp.py b/gramps/gen/filters/rules/person/_hasnoteregexp.py index 3eb944610..d8533c372 100644 --- a/gramps/gen/filters/rules/person/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/person/_hasnoteregexp.py @@ -40,7 +40,7 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('People having notes containing ') + name = _('People having notes containing ') description = _("Matches people whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/person/_regexpidof.py b/gramps/gen/filters/rules/person/_regexpidof.py index cd3d50bd5..43087fb99 100644 --- a/gramps/gen/filters/rules/person/_regexpidof.py +++ b/gramps/gen/filters/rules/person/_regexpidof.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('People with matching regular expression') + name = _('People with Id containing ') description = _("Matches people whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/person/_regexpname.py b/gramps/gen/filters/rules/person/_regexpname.py index af8fb203e..40c21ab75 100644 --- a/gramps/gen/filters/rules/person/_regexpname.py +++ b/gramps/gen/filters/rules/person/_regexpname.py @@ -45,25 +45,18 @@ import re class RegExpName(Rule): """Rule that checks for full or partial name matches""" - labels = [_('Expression:')] - name = _('People matching the ') - description = _("Matches people's names with a specified regular expression") + labels = [_('Text:')] + name = _('People with a name matching ') + description = _("Matches people's names with containing a substring or " + "matching a regular expression") category = _('General filters') - - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0],re.I|re.U|re.L) - except re.error: - #indicate error by matching everyone - self.match = re.compile('') + allow_regex = True def apply(self,db,person): for name in [person.get_primary_name()] + person.get_alternate_names(): for field in [name.first_name, name.get_surname(), name.suffix, name.title, name.nick, name.famnick, name.call]: - if self.match.search(field): + if self.match_substring(0, field): return True else: return False diff --git a/gramps/gen/filters/rules/place/__init__.py b/gramps/gen/filters/rules/place/__init__.py index 57d8071cc..f5cfcfb41 100644 --- a/gramps/gen/filters/rules/place/__init__.py +++ b/gramps/gen/filters/rules/place/__init__.py @@ -54,7 +54,6 @@ editor_rule_list = [ RegExpIdOf, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, HasSourceOf, diff --git a/gramps/gen/filters/rules/place/_hasnoteregexp.py b/gramps/gen/filters/rules/place/_hasnoteregexp.py index d4b4f17a6..aaf6fb594 100644 --- a/gramps/gen/filters/rules/place/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/place/_hasnoteregexp.py @@ -40,6 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Places having notes containing ') + name = _('Places having notes containing ') description = _("Matches places whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/place/_regexpidof.py b/gramps/gen/filters/rules/place/_regexpidof.py index a75e2b176..409f2c6cd 100644 --- a/gramps/gen/filters/rules/place/_regexpidof.py +++ b/gramps/gen/filters/rules/place/_regexpidof.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Places with matching regular expression') + name = _('Places with Id containing ') description = _("Matches places whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/repository/__init__.py b/gramps/gen/filters/rules/repository/__init__.py index b3c32f9eb..56638fe62 100644 --- a/gramps/gen/filters/rules/repository/__init__.py +++ b/gramps/gen/filters/rules/repository/__init__.py @@ -42,7 +42,6 @@ editor_rule_list = [ HasIdOf, RegExpIdOf, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, RepoPrivate, MatchesFilter, diff --git a/gramps/gen/filters/rules/repository/_hasnoteregexp.py b/gramps/gen/filters/rules/repository/_hasnoteregexp.py index cdfea90ff..3d079dbef 100644 --- a/gramps/gen/filters/rules/repository/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/repository/_hasnoteregexp.py @@ -40,7 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Repositories having notes ' - 'containing ') + name = _('Repositories having notes containing ') description = _("Matches repositories whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/repository/_matchesnamesubstringof.py b/gramps/gen/filters/rules/repository/_matchesnamesubstringof.py index 16f8e3f2b..980db2c3d 100644 --- a/gramps/gen/filters/rules/repository/_matchesnamesubstringof.py +++ b/gramps/gen/filters/rules/repository/_matchesnamesubstringof.py @@ -41,14 +41,12 @@ from .. import Rule class MatchesNameSubstringOf(Rule): """Repository name containing """ - labels = [ _('Substring:')] - name = _('Repository name containing ') + labels = [ _('Text:')] + name = _('Repositories with name containing ') description = _("Matches repositories whose name contains a certain substring") category = _('General filters') + allow_regex = True def apply(self, db, repository): """ Apply the filter """ - name = repository.get_name() - if name.upper().find(self.list[0].upper()) != -1: - return True - return False + return self.match_substring(0, repository.get_name()) diff --git a/gramps/gen/filters/rules/repository/_regexpidof.py b/gramps/gen/filters/rules/repository/_regexpidof.py index a10cd5ab5..e8d196059 100644 --- a/gramps/gen/filters/rules/repository/_regexpidof.py +++ b/gramps/gen/filters/rules/repository/_regexpidof.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Repositories with matching regular expression') + name = _('Repositories with Id containing ') description = _("Matches repositories whose Gramps ID matches " "the regular expression") diff --git a/gramps/gen/filters/rules/source/__init__.py b/gramps/gen/filters/rules/source/__init__.py index 696d8f5f7..31bf6d2f6 100644 --- a/gramps/gen/filters/rules/source/__init__.py +++ b/gramps/gen/filters/rules/source/__init__.py @@ -52,7 +52,6 @@ editor_rule_list = [ RegExpIdOf, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, SourcePrivate, MatchesFilter, diff --git a/gramps/gen/filters/rules/source/_hasnoteregexp.py b/gramps/gen/filters/rules/source/_hasnoteregexp.py index 9e83df3aa..91062f137 100644 --- a/gramps/gen/filters/rules/source/_hasnoteregexp.py +++ b/gramps/gen/filters/rules/source/_hasnoteregexp.py @@ -40,6 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Sources having notes containing ') + name = _('Sources having notes containing ') description = _("Matches sources whose notes contain text " "matching a regular expression") diff --git a/gramps/gen/filters/rules/source/_hasrepositorycallnumberref.py b/gramps/gen/filters/rules/source/_hasrepositorycallnumberref.py index 5533edf1a..e0178127d 100644 --- a/gramps/gen/filters/rules/source/_hasrepositorycallnumberref.py +++ b/gramps/gen/filters/rules/source/_hasrepositorycallnumberref.py @@ -42,19 +42,15 @@ from .. import Rule class HasRepositoryCallNumberRef(Rule): """Sources which reference repositories by a special Call Number""" - labels = [ _('Substring:')] - name = _('Sources with repository reference containing in "Call Number"') + labels = [ _('Text:')] + name = _('Sources with repository reference containing in "Call Number"') description = _("Matches sources with a repository reference\n" "containing a substring in \"Call Number\"") category = _('General filters') + allow_regex = True def apply(self, db, obj): - count = len(obj.get_reporef_list()) - if count > 0: - for RepoRef in obj.get_reporef_list(): - if len(RepoRef.call_number) > 0: - CallNumb = RepoRef.call_number - if CallNumb.upper().find(self.list[0].upper()) != -1: - return True - + for repo_ref in obj.get_reporef_list(): + if self.match_substring(0, repo_ref.call_number): + return True return False diff --git a/gramps/gen/filters/rules/source/_matchestitlesubstringof.py b/gramps/gen/filters/rules/source/_matchestitlesubstringof.py index 2d51a87c2..dd6c898a1 100644 --- a/gramps/gen/filters/rules/source/_matchestitlesubstringof.py +++ b/gramps/gen/filters/rules/source/_matchestitlesubstringof.py @@ -41,15 +41,13 @@ from .. import Rule class MatchesTitleSubstringOf(Rule): """Source title containing """ - labels = [ _('Substring:')] - name = _('Sources title containing ') + labels = [ _('Text:')] + name = _('Sources with title containing ') description = _("Matches sources whose title contains a " "certain substring") category = _('General filters') + allow_regex = True def apply(self, db, source): """ Apply the filter """ - title = source.get_title() - if title.upper().find(self.list[0].upper()) != -1: - return True - return False + return self.match_substring(0, source.get_title()) diff --git a/gramps/gen/filters/rules/source/_regexpidof.py b/gramps/gen/filters/rules/source/_regexpidof.py index 9b1911ed4..b71c5ef04 100644 --- a/gramps/gen/filters/rules/source/_regexpidof.py +++ b/gramps/gen/filters/rules/source/_regexpidof.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Sources with matching regular expression') + name = _('Sources with Id containing ') description = _("Matches sources whose Gramps ID matches " "the regular expression") diff --git a/po/POTFILES.in b/po/POTFILES.in index 3abde6112..683858b5b 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -81,9 +81,11 @@ gramps/gen/filters/rules/family/_allfamilies.py gramps/gen/filters/rules/family/_changedsince.py gramps/gen/filters/rules/family/_childhasidof.py gramps/gen/filters/rules/family/_childhasnameof.py +gramps/gen/filters/rules/family/_childregexpidof.py gramps/gen/filters/rules/family/_familyprivate.py gramps/gen/filters/rules/family/_fatherhasidof.py gramps/gen/filters/rules/family/_fatherhasnameof.py +gramps/gen/filters/rules/family/_fatherregexpidof.py gramps/gen/filters/rules/family/_hasattribute.py gramps/gen/filters/rules/family/_hascitation.py gramps/gen/filters/rules/family/_hasevent.py @@ -104,6 +106,7 @@ gramps/gen/filters/rules/family/_matchesfilter.py gramps/gen/filters/rules/family/_matchessourceconfidence.py gramps/gen/filters/rules/family/_motherhasidof.py gramps/gen/filters/rules/family/_motherhasnameof.py +gramps/gen/filters/rules/family/_motherregexpidof.py gramps/gen/filters/rules/family/_regexpchildname.py gramps/gen/filters/rules/family/_regexpfathername.py gramps/gen/filters/rules/family/_regexpidof.py