From a0c9947dbd637be433f892e965ccb00951861075 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Thu, 11 Oct 2007 22:41:03 +0000 Subject: [PATCH] 2007-10-11 Benny Malengier * src/gen/db/base.py: allow check without gid creation on all objects * src/GrampsDbUtils/_ReadXML.py: on reference read, don't create gid. This also patches a privacy setting error on placeobj in place tag section svn: r9151 --- ChangeLog | 5 +++ src/GrampsDbUtils/_ReadXML.py | 77 ++++++++++++++++++++++++----------- src/gen/db/base.py | 42 ++++++++++++------- 3 files changed, 86 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index be2fd9c2c..22e49a9a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-10-11 Benny Malengier + * src/gen/db/base.py: allow check without gid creation on all objects + * src/GrampsDbUtils/_ReadXML.py: on reference read, don't create gid. + This also patches a privacy setting error on placeobj in place tag section + 2007-10-11 Benny Malengier * src/DateHandler/__init__.py: use portuguese date handler diff --git a/src/GrampsDbUtils/_ReadXML.py b/src/GrampsDbUtils/_ReadXML.py index a39da8fd8..b9280ab5d 100644 --- a/src/GrampsDbUtils/_ReadXML.py +++ b/src/GrampsDbUtils/_ReadXML.py @@ -704,13 +704,24 @@ class GrampsParser(UpdateCallback): self.ord.set_family_handle(handle) def start_place(self, attrs): + """A reference to a place in an object: event or lds_ord + """ try: - self.placeobj = self.db.find_place_from_handle( - attrs['hlink'].replace('_', ''), self.trans) + handle = attrs['hlink'].replace('_', '') + self.db.check_place_from_handle(handle, self.trans, + set_gid = False) except KeyError: + #legacy, before hlink there was ref gramps_id = self.map_pid(attrs['ref']) - self.placeobj = self.find_place_by_gramps_id(gramps_id) - self.placeobj.private = bool(attrs.get("priv")) + place = self.find_place_by_gramps_id(gramps_id) + handle = place.handle + + if self.ord: + self.ord.set_place_handle(handle) + elif self.object: + self.object.set_place_handle(handle) + else: + self.event.set_place_handle(handle) def start_placeobj(self, attrs): gramps_id = self.map_pid(attrs['id']) @@ -961,6 +972,7 @@ class GrampsParser(UpdateCallback): def start_father(self, attrs): try: handle = attrs['hlink'].replace('_', '') + #all persons exist before father tag is encountered self.db.check_person_from_handle(handle, self.trans) except KeyError: person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"])) @@ -970,6 +982,7 @@ class GrampsParser(UpdateCallback): def start_mother(self, attrs): try: handle = attrs['hlink'].replace('_', '') + #all persons exist before mother tag is encountered self.db.check_person_from_handle(handle, self.trans) except KeyError: person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"])) @@ -1076,7 +1089,8 @@ class GrampsParser(UpdateCallback): def start_childof(self, attrs): try: handle = attrs["hlink"].replace('_', '') - self.db.check_family_from_handle(handle, self.trans) + self.db.check_family_from_handle(handle, self.trans, + set_gid = False) except KeyError: family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) handle = family.handle @@ -1102,7 +1116,8 @@ class GrampsParser(UpdateCallback): def start_parentin(self, attrs): try: handle = attrs["hlink"].replace('_', '') - self.db.check_family_from_handle(handle, self.trans) + self.db.check_family_from_handle(handle, self.trans, + set_gid = False) except KeyError: family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) handle = family.handle @@ -1222,7 +1237,7 @@ class GrampsParser(UpdateCallback): def start_noteref(self, attrs): handle = attrs['hlink'].replace('_', '') - self.db.check_note_from_handle(handle, self.trans) + self.db.check_note_from_handle(handle, self.trans, set_gid = False) if self.source_ref: self.source_ref.add_note(handle) @@ -1305,7 +1320,7 @@ class GrampsParser(UpdateCallback): def start_source(self, attrs): self.update(self.p.CurrentLineNumber) - gramps_id = self.map_sid(attrs["id"]) + gramps_id = self.map_sid(attrs["id"]) #avoid double id's on import try: self.source = self.db.find_source_from_handle( attrs['handle'].replace('_', ''), self.trans) @@ -1318,7 +1333,8 @@ class GrampsParser(UpdateCallback): self.reporef = gen.lib.RepoRef() try: handle = attrs['hlink'].replace('_', '') - self.db.check_repository_from_handle(handle, self.trans) + self.db.check_repository_from_handle(handle, self.trans + set_gid = False) except KeyError: repo = self.find_repo_by_gramps_id(self.map_rid(attrs['ref'])) handle = repo.handle @@ -1335,7 +1351,8 @@ class GrampsParser(UpdateCallback): self.objref = gen.lib.MediaRef() try: handle = attrs['hlink'].replace('_', '') - self.db.check_object_from_handle(handle, self.trans) + self.db.check_object_from_handle(handle, self.trans + set_gid = False) except KeyError: obj = self.find_object_by_gramps_id(self.map_oid(attrs['ref'])) handle = obj.handle @@ -1782,20 +1799,32 @@ class GrampsParser(UpdateCallback): self.db.commit_person(person, self.trans, self.change) def stop_place(self, tag): - if self.placeobj == None: - if self.place_map.has_key(tag): - self.placeobj = self.place_map[tag] - else: - self.placeobj = gen.lib.Place() - self.placeobj.set_title(tag) - if self.ord: - self.ord.set_place_handle(self.placeobj.get_handle()) - elif self.object: - self.object.set_place_handle(self.placeobj.get_handle()) - else: - self.event.set_place_handle(self.placeobj.get_handle()) - self.db.commit_place(self.placeobj, self.trans, self.change) - self.placeobj = None + """end of a reference to place, should do nothing ... + Note, if we encounter blabla this method is called + with tag='blabla + """ + ##place = None + ##handle = None + ##if self.place_ref == None: #todo, add place_ref in start and init + ## #legacy cody? I see no reason for this, but it was present + ## if self.place_map.has_key(tag): + ## place = self.place_map[tag] + ## handle = place.get_handle() + ## place = None + ## else: + ## place = RelLib.Place() + ## place.set_title(tag) + ## handle = place.get_handle() + ## if self.ord: + ## self.ord.set_place_handle(handle) + ## elif self.object: + ## self.object.set_place_handle(handle) + ## else: + ## self.event.set_place_handle(handle) + ## if place : + ## self.db.commit_place(self.placeobj,self.trans,self.change) + ##self.place_ref = None + pass def stop_date(self, tag): if tag: diff --git a/src/gen/db/base.py b/src/gen/db/base.py index 2ab3191d1..1d93097c9 100644 --- a/src/gen/db/base.py +++ b/src/gen/db/base.py @@ -887,13 +887,15 @@ class GrampsDbBase(GrampsDBCallback): return self.find_from_handle(handle, transaction, Note, self.note_map, self.add_note) - def check_person_from_handle(self, handle, transaction): + def check_person_from_handle(self, handle, transaction, set_gid=True): """ Checks whether a Person with the passed handle exists in the database. If no such Person exists, a new Person is added to the database. + If set_gid then a new gramps_id is created, if not, None is used. """ self.__check_from_handle(handle, transaction, Person, - self.person_map, self.add_person) + self.person_map, self.add_person, + set_gid = set_gid) def check_source_from_handle(self, handle, transaction, set_gid=True): """ @@ -905,57 +907,69 @@ class GrampsDbBase(GrampsDBCallback): self.source_map, self.add_source, set_gid=set_gid) - def check_event_from_handle(self, handle, transaction): + def check_event_from_handle(self, handle, transaction, set_gid=True): """ Checks whether an Event with the passed handle exists in the database. If no such Event exists, a new Event is added to the database. + If set_gid then a new gramps_id is created, if not, None is used. """ self.__check_from_handle(handle, transaction, Event, - self.event_map, self.add_event) + self.event_map, self.add_event, + set_gid=set_gid) - def check_object_from_handle(self, handle, transaction): + def check_object_from_handle(self, handle, transaction, set_gid=True): """ Checks whether a MediaObject with the passed handle exists in the database. If no such MediaObject exists, a new Object is added to the database. + If set_gid then a new gramps_id is created, if not, None is used. """ self.__check_from_handle(handle, transaction, MediaObject, - self.media_map, self.add_object) + self.media_map, self.add_object, + set_gid=set_gid) - def check_place_from_handle(self, handle, transaction): + def check_place_from_handle(self, handle, transaction, set_gid=True): """ Checks whether a Place with the passed handle exists in the database. If no such Place exists, a new Place is added to the database. + If set_gid then a new gramps_id is created, if not, None is used. """ self.__check_from_handle(handle, transaction, Place, - self.place_map, self.add_place) + self.place_map, self.add_place, + set_gid=set_gid) - def check_family_from_handle(self, handle, transaction): + def check_family_from_handle(self, handle, transaction, set_gid=True): """ Checks whether a Family with the passed handle exists in the database. If no such Family exists, a new Family is added to the database. + If set_gid then a new gramps_id is created, if not, None is used. """ self.__check_from_handle(handle, transaction, Family, - self.family_map, self.add_family) + self.family_map, self.add_family, + set_gid=set_gid) - def check_repository_from_handle(self, handle, transaction): + def check_repository_from_handle(self, handle, transaction, set_gid=True): """ Checks whether a Repository with the passed handle exists in the database. If no such Repository exists, a new Repository is added to the database. + If set_gid then a new gramps_id is created, if not, None is used. """ self.__check_from_handle(handle, transaction, Repository, - self.repository_map, self.add_repository) + self.repository_map, self.add_repository, + set_gid=set_gid) - def check_note_from_handle(self, handle, transaction): + def check_note_from_handle(self, handle, transaction, set_gid=True): """ Checks whether a Note with the passed handle exists in the database. If no such Note exists, a new Note is added to the database. + If set_gid then a new gramps_id is created, if not, None is used. """ self.__check_from_handle(handle, transaction, Note, - self.note_map, self.add_note) + self.note_map, self.add_note, + set_gid=set_gid) def get_person_from_gramps_id(self, val): """