From d382d7b0946aef2ef5a3ef628e631939c85583b0 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 19 Sep 2004 04:11:34 +0000 Subject: [PATCH] * src/GrampsInMemDB.py: new base class for in memory databases, such as XML or GEDCOM * src/GrampGEDDB.py: use new GrampsInMemDB base class * src/GrampXMLDB.py: use new GrampsInMemDB base class * src/Makefile.am: add GrampsInMemDB.py * src/ReadGedcom.py: remove debug statements svn: r3555 --- ChangeLog | 8 +++ src/GrampsBSDDB.py | 2 +- src/GrampsGEDDB.py | 60 +--------------- src/GrampsInMemDB.py | 160 +++++++++++++++++++++++++++++++++++++++++++ src/GrampsXMLDB.py | 68 +----------------- src/Makefile.am | 1 + src/ReadGedcom.py | 5 -- src/RelLib.py | 1 - src/plugins/Check.py | 2 +- 9 files changed, 177 insertions(+), 130 deletions(-) create mode 100644 src/GrampsInMemDB.py diff --git a/ChangeLog b/ChangeLog index e93e0104c..50ff07e70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-09-18 Don Allingham + * src/GrampsInMemDB.py: new base class for in memory databases, such + as XML or GEDCOM + * src/GrampGEDDB.py: use new GrampsInMemDB base class + * src/GrampXMLDB.py: use new GrampsInMemDB base class + * src/Makefile.am: add GrampsInMemDB.py + * src/ReadGedcom.py: remove debug statements + 2004-09-18 Alex Roitman * src/DateEdit.py (DateEdit): Take care of both the button and the LED pixmap now; Invoke DateEditorDialog if the button is pressed; diff --git a/src/GrampsBSDDB.py b/src/GrampsBSDDB.py index 8f9137345..9b0b25393 100644 --- a/src/GrampsBSDDB.py +++ b/src/GrampsBSDDB.py @@ -184,7 +184,7 @@ class GrampsBSDDB(GrampsDbBase): transaction.add(SOURCE_KEY,handle,old_data) self.source_map.delete(str(handle)) - def remove_family_handle(self,handle,transaction): + def remove_family(self,handle,transaction): if transaction != None: old_data = self.family_map.get(str(handle)) transaction.add(FAMILY_KEY,handle,old_data) diff --git a/src/GrampsGEDDB.py b/src/GrampsGEDDB.py index f5a39dbd2..4927cb138 100644 --- a/src/GrampsGEDDB.py +++ b/src/GrampsGEDDB.py @@ -21,7 +21,7 @@ # $Id$ from RelLib import * -from GrampsDbBase import * +from GrampsInMemDB import * import ReadGedcom import WriteGedcom @@ -31,27 +31,16 @@ import WriteGedcom # GrampsGEDDB # #------------------------------------------------------------------------- -class GrampsGEDDB(GrampsDbBase): +class GrampsGEDDB(GrampsInMemDB): """GRAMPS database object. This object is a base class for other objects.""" def __init__(self): """creates a new GrampsDB""" - GrampsDbBase.__init__(self) + GrampsInMemDB.__init__(self) def load(self,name,callback): - self.person_map = {} - self.family_map = {} - self.place_map = {} - self.source_map = {} - self.media_map = {} - self.event_map = {} - self.metadata = {} self.filename = name - self.id_trans = {} - self.eventnames = {} - self.undodb = [] - ReadGedcom.importData(self,name) self.bookmarks = self.metadata.get('bookmarks') @@ -63,46 +52,3 @@ class GrampsGEDDB(GrampsDbBase): writer = WriteGedcom.GedcomWriter(self,self.get_default_person()) writer.export_data(self.filename) - def get_surname_list(self): - a = {} - for person_id in self.get_person_handles(sort_handles=False): - p = self.get_person_from_handle(person_id) - a[p.get_primary_name().get_surname()] = 1 - vals = a.keys() - vals.sort() - return vals - - def get_person_event_type_list(self): - names = self.eventnames.keys() - a = {} - for name in names: - a[unicode(name)] = 1 - vals = a.keys() - vals.sort() - return vals - - def remove_person(self,handle,transaction): - self.genderStats.uncount_person (self.person_map[handle]) - if transaction != None: - old_data = self.person_map.get(handle) - transaction.add(PERSON_KEY,handle,old_data) - del self.person_map[handle] - - def remove_source(self,handle,transaction): - if transaction != None: - old_data = self.source_map.get(str(handle)) - transaction.add(SOURCE_KEY,handle,old_data) - del self.source_map[str(handle)] - - def remove_family_handle(self,handle,transaction): - if transaction != None: - old_data = self.family_map.get(str(handle)) - transaction.add(FAMILY_KEY,handle,old_data) - del self.family_map[str(handle)] - - def remove_event(self,handle,transaction): - if transaction != None: - old_data = self.event_map.get(str(handle)) - transaction.add(EVENT_KEY,handle,old_data) - del self.event_map[str(handle)] - diff --git a/src/GrampsInMemDB.py b/src/GrampsInMemDB.py new file mode 100644 index 000000000..38476cb3a --- /dev/null +++ b/src/GrampsInMemDB.py @@ -0,0 +1,160 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2004 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$ + +from RelLib import * +from GrampsDbBase import * + +import ReadGedcom +import WriteGedcom + +#------------------------------------------------------------------------- +# +# GrampsInMemDB +# +#------------------------------------------------------------------------- +class GrampsInMemDB(GrampsDbBase): + """GRAMPS database object. This object is a base class for other + objects.""" + + def __init__(self): + """creates a new GrampsDB""" + GrampsDbBase.__init__(self) + self.person_map = {} + self.family_map = {} + self.place_map = {} + self.source_map = {} + self.media_map = {} + self.event_map = {} + self.metadata = {} + self.filename = "" + self.id_trans = {} + self.pid_trans = {} + self.fid_trans = {} + self.sid_trans = {} + self.oid_trans = {} + self.eventnames = {} + self.undodb = [] + + def load(self,name,callback): + pass + + def close(self): + pass + + def get_surname_list(self): + a = {} + for person_id in self.get_person_handles(sort_handles=False): + p = self.get_person_from_handle(person_id) + a[p.get_primary_name().get_surname()] = 1 + vals = a.keys() + vals.sort() + return vals + + def get_person_event_type_list(self): + names = self.eventnames.keys() + a = {} + for name in names: + a[unicode(name)] = 1 + vals = a.keys() + vals.sort() + return vals + + def remove_person(self,handle,transaction): + self.genderStats.uncount_person (self.person_map[handle]) + if transaction != None: + old_data = self.person_map.get(handle) + transaction.add(PERSON_KEY,handle,old_data) + del self.id_trans[self.person_map[handle].get_gramps_id()] + del self.person_map[handle] + + def remove_source(self,handle,transaction): + if transaction != None: + old_data = self.source_map.get(str(handle)) + transaction.add(SOURCE_KEY,handle,old_data) + del self.sid_trans[self.source_map[handle].get_gramps_id()] + del self.source_map[str(handle)] + + def remove_family(self,handle,transaction): + if transaction != None: + old_data = self.family_map.get(str(handle)) + transaction.add(FAMILY_KEY,handle,old_data) + del self.fid_trans[self.family_map[handle].get_gramps_id()] + del self.family_map[str(handle)] + + def remove_event(self,handle,transaction): + if transaction != None: + old_data = self.event_map.get(str(handle)) + transaction.add(EVENT_KEY,handle,old_data) + del self.eid_trans[self.event_map[handle].get_gramps_id()] + del self.event_map[str(handle)] + + def remove_family(self,handle,transaction): + if transaction != None: + old_data = self.family_map.get(str(handle)) + transaction.add(EVENT_KEY,handle,old_data) + del self.fid_trans[self.family_map[handle].get_gramps_id()] + del self.family_map[str(handle)] + + def commit_person(self,person,transaction,change_time=None): + id = person.get_gramps_id() + self.id_trans[id] = person.get_handle() + GrampsDbBase.commit_person(self,person,transaction,change_time) + + def commit_place(self,place,transaction,change_time=None): + id = place.get_gramps_id() + self.pid_trans[id] = place.get_handle() + GrampsDbBase.commit_place(self,place,transaction,change_time) + + def commit_family(self,family,transaction,change_time=None): + id = family.get_gramps_id() + self.fid_trans[id] = family.get_handle() + GrampsDbBase.commit_family(self,family,transaction,change_time) + + def commit_media_object(self,obj,transaction,change_time=None): + id = obj.get_gramps_id() + self.oid_trans[id] = obj.get_handle() + GrampsDbBase.commit_media_object(self,obj,transaction,change_time) + + def commit_source(self,source,transaction,change_time=None): + id = source.get_gramps_id() + self.sid_trans[id] = source.get_handle() + GrampsDbBase.commit_source(self,source,transaction,change_time) + + def get_person_from_gramps_id(self,val): + handle = self.id_trans.get(str(val)) + return self.person_map[handle] + + def get_family_from_gramps_id(self,val): + handle = self.fid_trans.get(str(val)) + return self.family_map[handle] + + def get_place_from_gramps_id(self,val): + handle = self.pid_trans.get(str(val)) + return self.place_map[handle] + + def get_source_from_gramps_id(self,val): + handle = self.sid_trans.get(str(val)) + return self.source_map[handle] + + def get_object_from_gramps_id(self,val): + handle = self.oid_trans.get(str(val)) + return self.media_map[handle] diff --git a/src/GrampsXMLDB.py b/src/GrampsXMLDB.py index caf4b40ca..82949362a 100644 --- a/src/GrampsXMLDB.py +++ b/src/GrampsXMLDB.py @@ -21,45 +21,26 @@ # $Id$ from RelLib import * -from GrampsDbBase import * +from GrampsInMemDB import * import ReadXML import WriteXML -_UNDO_SIZE = 1000 - -#------------------------------------------------------------------------- -# -# ID regular expression -# -#------------------------------------------------------------------------- -_id_reg = compile("%\d+d") - #------------------------------------------------------------------------- # # GrampsXMLDB # #------------------------------------------------------------------------- -class GrampsXMLDB(GrampsDbBase): +class GrampsXMLDB(GrampsInMemDB): """GRAMPS database object. This object is a base class for other objects.""" def __init__(self): """creates a new GrampsDB""" - GrampsDbBase.__init__(self) + GrampsInMemDB.__init__(self) def load(self,name,callback): - self.person_map = {} - self.family_map = {} - self.place_map = {} - self.source_map = {} - self.media_map = {} - self.event_map = {} - self.metadata = {} - self.filename = name self.id_trans = {} - self.eventnames = {} - self.undodb = [] ReadXML.importData(self,name) @@ -71,46 +52,3 @@ class GrampsXMLDB(GrampsDbBase): def close(self): WriteXML.quick_write(self,self.filename) - def get_surname_list(self): - a = {} - for person_id in self.get_person_handles(sort_handles=False): - p = self.get_person_from_handle(person_id) - a[p.get_primary_name().get_surname()] = 1 - vals = a.keys() - vals.sort() - return vals - - def get_person_event_type_list(self): - names = self.eventnames.keys() - a = {} - for name in names: - a[unicode(name)] = 1 - vals = a.keys() - vals.sort() - return vals - - def remove_person(self,handle,transaction): - self.genderStats.uncount_person (self.person_map[handle]) - if transaction != None: - old_data = self.person_map.get(handle) - transaction.add(PERSON_KEY,handle,old_data) - del self.person_map[handle] - - def remove_source(self,handle,transaction): - if transaction != None: - old_data = self.source_map.get(str(handle)) - transaction.add(SOURCE_KEY,handle,old_data) - del self.source_map[str(handle)] - - def remove_family_handle(self,handle,transaction): - if transaction != None: - old_data = self.family_map.get(str(handle)) - transaction.add(FAMILY_KEY,handle,old_data) - del self.family_map[str(handle)] - - def remove_event(self,handle,transaction): - if transaction != None: - old_data = self.event_map.get(str(handle)) - transaction.add(EVENT_KEY,handle,old_data) - del self.event_map[str(handle)] - diff --git a/src/Makefile.am b/src/Makefile.am index 46e7b27df..83600fe2a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,6 +46,7 @@ gdir_PYTHON = \ GrampsCfg.py\ GrampsBSDDB.py\ GrampsDbBase.py\ + GrampsInMemDB.py\ GrampsXMLDB.py\ GrampsGEDDB.py\ GrampsMime.py\ diff --git a/src/ReadGedcom.py b/src/ReadGedcom.py index dad57408d..b3a0bc54d 100644 --- a/src/ReadGedcom.py +++ b/src/ReadGedcom.py @@ -1729,7 +1729,6 @@ class GedcomParser: stop = self.dp.parse(data2) dateobj.set(Date.QUAL_NONE, Date.MOD_RANGE, cal, start.get_start_date() + stop.get_start_date()) - print dateobj return dateobj match = spanRegexp.match(text) @@ -1751,7 +1750,6 @@ class GedcomParser: stop = self.dp.parse(data2) dateobj.set(Date.QUAL_NONE, Date.MOD_SPAN, cal, start.get_start_date() + stop.get_start_date()) - print dateobj return dateobj match = calRegexp.match(text) @@ -1764,10 +1762,8 @@ class GedcomParser: dateobj.set_calendar(Date.CAL_JULIAN) elif cal == "HEBREW": dateobj.set_calendar(Date.CAL_HEBREW) - print dateobj return dateobj else: - print text, self.dp.parse(text) return self.dp.parse(text) except IOError: return self.dp.set_text(text) @@ -1793,7 +1789,6 @@ class GedcomParser: prefix = self.db.iprefix index = 0 new_pmax = self.db.pmap_index - print self.added for pid in self.added.keys(): index = index + 1 if self.refn.has_key(pid): diff --git a/src/RelLib.py b/src/RelLib.py index 9b13107d5..8bef341ca 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -1408,7 +1408,6 @@ class LdsOrd(SourceNote): def get_date(self) : """returns a string representation of the date of the ordinance""" if self.date: - print self.dd return self.dd.display(self.date) return u"" diff --git a/src/plugins/Check.py b/src/plugins/Check.py index f1fe0afe7..c52dfa32c 100644 --- a/src/plugins/Check.py +++ b/src/plugins/Check.py @@ -243,7 +243,7 @@ class CheckIntegrity: child = self.db.get_person_from_handle(key) child.remove_parent_family_handle(family_handle) child.remove_family_handle(family_handle) - self.db.remove_family_handle(family_handle,self.trans) + self.db.remove_family(family_handle,self.trans) def check_parent_relationships(self): for key in self.db.get_family_handles():