From 8e21af4a498968f0b96bafed11af5d5b68b2c2a5 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 23 May 2003 04:08:03 +0000 Subject: [PATCH] Catch loops in filters svn: r1583 --- src/Errors.py | 13 +++++++++++ src/GenericFilter.py | 35 ++++++++++++++++++++++++++++++ src/gramps_main.py | 8 +++++-- src/plugins/AncestorChart.py | 3 +++ src/plugins/AncestorReport.py | 3 +++ src/plugins/DesGraph.py | 3 +++ src/plugins/DescendReport.py | 3 +++ src/plugins/DetAncestralReport.py | 3 +++ src/plugins/FamilyGroup.py | 3 +++ src/plugins/FtmStyleAncestors.py | 3 +++ src/plugins/FtmStyleDescendants.py | 3 +++ src/plugins/GraphViz.py | 6 ++++- src/plugins/IndivComplete.py | 3 +++ src/plugins/IndivSummary.py | 3 +++ src/plugins/TimeLine.py | 3 +++ src/plugins/WebPage.py | 20 +++++++++++------ 16 files changed, 105 insertions(+), 10 deletions(-) diff --git a/src/Errors.py b/src/Errors.py index 80a799103..f769eaf1b 100644 --- a/src/Errors.py +++ b/src/Errors.py @@ -18,6 +18,19 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +class FilterError(Exception): + """Error used to report Filter errors""" + def __init__(self,value,value2=""): + Exception.__init__(self) + self.value = value + self.value2 = value2 + + def __str__(self): + return self.value + + def messages(self): + return (self.value,self.value2) + class DateError(Exception): """Error used to report Date errors""" def __init__(self,value=""): diff --git a/src/GenericFilter.py b/src/GenericFilter.py index 256d9838d..b112bc68a 100644 --- a/src/GenericFilter.py +++ b/src/GenericFilter.py @@ -51,6 +51,7 @@ import const import RelLib import Date import Calendar +import Errors from intl import gettext as _ from Utils import for_each_ancestor @@ -170,9 +171,19 @@ class IsDescendantOf(Rule): return 'Is a descendant of' def apply(self,db,p): + self.map = {} + self.orig = p return self.search(p) def search(self,p): + if self.map.has_key(p.getId()) == 1: + raise Errors.FilterError(_("Loop detected while applying filter"), + _("A relationship loop was detected between %s [%s]" + "and %s [%s]. This is probably due to an error in the " + "database.") % (self.orig.getPrimaryName().getName(), + self.orig.getId(), + p.getPrimaryName().getName(),p.getId())) + self.map[p.getId()] = 1 if p.getId() == self.list[0]: return 1 for (f,r1,r2) in p.getParentList(): @@ -197,10 +208,20 @@ class IsDescendantFamilyOf(Rule): return "Is a descendant family member of" def apply(self,db,p): + self.map = {} + self.orig = p return self.search(p,1) def search(self,p,val): + if self.map.has_key(p.getId()): + Errors.FilterError(_("Loop detected while applying filter"), + _("A relationship loop was detected between %s [%s]" + "and %s [%s]. This is probably due to an error in the " + "database.") % (self.orig.getPrimaryName().getName(), + self.orig.getId(), + p.getPrimaryName().getName(),p.getId())) if p.getId() == self.list[0]: + self.map[p.getId()] = 1 return 1 for (f,r1,r2) in p.getParentList(): for p1 in [f.getMother(),f.getFather()]: @@ -228,14 +249,28 @@ class IsAncestorOf(Rule): """Rule that checks for a person that is an ancestor of a specified person""" labels = [ _('ID:') ] + + def __init__(self,list): + Rule.__init__(self,list) + self.map = {} def name(self): return 'Is an ancestor of' def apply(self,db,p): + self.orig = p return self.search(p) def search(self,p): + if self.map.has_key(p.getId()) == 1: + raise Errors.FilterError(_("Loop detected while applying filter"), + _("A relationship loop was detected between %s [%s]" + "and %s [%s]. This is probably due to an error in the " + "database.") % (self.orig.getPrimaryName().getName(), + self.orig.getId(), + p.getPrimaryName().getName(),p.getId())) + self.map[p.getId()] = 1 + if p.getId() == self.list[0]: return 1 diff --git a/src/gramps_main.py b/src/gramps_main.py index 9d908c2af..c51e4c509 100755 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -956,6 +956,7 @@ class Gramps: else: GrampsCfg.save_last_file("") self.topWindow.set_resizable(gtk.TRUE) + self.goto_active_person(1) def cl_import(self,filename,format): if format == 'gedcom': @@ -1368,9 +1369,12 @@ class Gramps: def alpha_event(self,obj): self.load_person(self.active_person) - def goto_active_person(self): + def goto_active_person(self,first=0): if not self.active_person: - page = self.ptabs.get_current_page() + if first: + page = 0 + else: + page = self.ptabs.get_current_page() self.person_tree = self.pl_page[page] self.person_list = self.pl_page[page].tree self.person_model = self.pl_page[page].model diff --git a/src/plugins/AncestorChart.py b/src/plugins/AncestorChart.py index cb8e72dc6..90e2ce645 100644 --- a/src/plugins/AncestorChart.py +++ b/src/plugins/AncestorChart.py @@ -257,6 +257,9 @@ class AncestorChartDialog(Report.DrawReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/AncestorReport.py b/src/plugins/AncestorReport.py index b72222cf5..d0a3737c8 100644 --- a/src/plugins/AncestorReport.py +++ b/src/plugins/AncestorReport.py @@ -273,6 +273,9 @@ class AncestorReportDialog(Report.TextReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/DesGraph.py b/src/plugins/DesGraph.py index 13320a3b8..da673990a 100644 --- a/src/plugins/DesGraph.py +++ b/src/plugins/DesGraph.py @@ -346,6 +346,9 @@ class DescendantReportDialog(Report.DrawReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/DescendReport.py b/src/plugins/DescendReport.py index 321cd9711..3292ff51b 100644 --- a/src/plugins/DescendReport.py +++ b/src/plugins/DescendReport.py @@ -169,6 +169,9 @@ class DescendantReportDialog(Report.TextReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/DetAncestralReport.py b/src/plugins/DetAncestralReport.py index e30a917e8..19f989103 100644 --- a/src/plugins/DetAncestralReport.py +++ b/src/plugins/DetAncestralReport.py @@ -762,6 +762,9 @@ class DetAncestorReportDialog(TextReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/FamilyGroup.py b/src/plugins/FamilyGroup.py index c12187097..34e64d403 100644 --- a/src/plugins/FamilyGroup.py +++ b/src/plugins/FamilyGroup.py @@ -451,6 +451,9 @@ class FamilyGroupDialog(Report.TextReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/FtmStyleAncestors.py b/src/plugins/FtmStyleAncestors.py index 3bc37e861..9a9db9726 100644 --- a/src/plugins/FtmStyleAncestors.py +++ b/src/plugins/FtmStyleAncestors.py @@ -761,6 +761,9 @@ class FtmAncestorReportDialog(Report.TextReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/FtmStyleDescendants.py b/src/plugins/FtmStyleDescendants.py index 954bb7392..79861f0b7 100644 --- a/src/plugins/FtmStyleDescendants.py +++ b/src/plugins/FtmStyleDescendants.py @@ -1155,6 +1155,9 @@ class FtmDescendantReportDialog(Report.TextReportDialog): except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except: import DisplayTrace DisplayTrace.DisplayTrace() diff --git a/src/plugins/GraphViz.py b/src/plugins/GraphViz.py index d0ac2f982..b8ba02738 100644 --- a/src/plugins/GraphViz.py +++ b/src/plugins/GraphViz.py @@ -268,7 +268,11 @@ class GraphVizDialog(Report.ReportDialog): file = open(self.target_path,"w") - ind_list = self.filter.apply(self.db, self.db.getPersonMap().values()) + try: + ind_list = self.filter.apply(self.db, self.db.getPersonMap().values()) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) write_dot(file, ind_list, self.orien, width, height, self.tb_margin, self.lr_margin, self.hpages, diff --git a/src/plugins/IndivComplete.py b/src/plugins/IndivComplete.py index 114413d4b..16090fa68 100644 --- a/src/plugins/IndivComplete.py +++ b/src/plugins/IndivComplete.py @@ -543,6 +543,9 @@ class IndivSummaryDialog(Report.TextReportDialog): self.doc, self.filter, act) MyReport.setup() MyReport.write_report() + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) diff --git a/src/plugins/IndivSummary.py b/src/plugins/IndivSummary.py index 1c3f24aa8..667c27a95 100644 --- a/src/plugins/IndivSummary.py +++ b/src/plugins/IndivSummary.py @@ -383,6 +383,9 @@ class IndivSummaryDialog(Report.TextReportDialog): MyReport = IndivSummary(self.db, self.person, self.target_path, self.doc) MyReport.setup() MyReport.write_report() + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) diff --git a/src/plugins/TimeLine.py b/src/plugins/TimeLine.py index 22f61e5a5..369489f83 100644 --- a/src/plugins/TimeLine.py +++ b/src/plugins/TimeLine.py @@ -409,6 +409,9 @@ class TimeLineDialog(Report.DrawReportDialog): self.doc, self.filter, title, sort_func) MyReport.setup() MyReport.write_report() + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) except Errors.ReportError, msg: (m1,m2) = msg.messages() ErrorDialog(m1,m2) diff --git a/src/plugins/WebPage.py b/src/plugins/WebPage.py index 501a46425..4387cff8f 100644 --- a/src/plugins/WebPage.py +++ b/src/plugins/WebPage.py @@ -1145,13 +1145,19 @@ class WebReportDialog(Report.ReportDialog): #------------------------------------------------------------------------ def make_report(self): """Create the object that will produce the web pages.""" - MyReport = WebReport(self.db, self.person, self.target_path, - self.max_gen, self.photos, self.filter, - self.restrict, self.private, self.srccomments, - self.include_link, self.selected_style, - self.img_dir_text,self.template_name, - self.use_id,self.id_link,self.use_gendex, - self.html_ext) + + try: + MyReport = WebReport(self.db, self.person, self.target_path, + self.max_gen, self.photos, self.filter, + self.restrict, self.private, self.srccomments, + self.include_link, self.selected_style, + self.img_dir_text,self.template_name, + self.use_id,self.id_link,self.use_gendex, + self.html_ext) + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) + MyReport.write_report() #------------------------------------------------------------------------