diff --git a/ChangeLog b/ChangeLog index d91c8fe2b..325a45a1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-10-11 Benny Malengier + * src/GrampsDb/_GrampsDbBase.py: allow check without gid creation on all objects + * src/GrampsDb/_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 Alex Roitman * src/plugins/unused.glade: Do not translate gtk stock label id. diff --git a/src/GrampsDb/_GrampsDbBase.py b/src/GrampsDb/_GrampsDbBase.py index 789b52c32..3b017f6be 100644 --- a/src/GrampsDb/_GrampsDbBase.py +++ b/src/GrampsDb/_GrampsDbBase.py @@ -854,13 +854,15 @@ class GrampsDbBase(GrampsDBCallback): return self._find_from_handle(handle, transaction, Repository, self.repository_map, self.add_repository) - 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): """ @@ -872,48 +874,58 @@ 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 get_person_from_gramps_id(self, val): """ diff --git a/src/GrampsDb/_ReadXML.py b/src/GrampsDb/_ReadXML.py index 376c893e9..cb43156c5 100644 --- a/src/GrampsDb/_ReadXML.py +++ b/src/GrampsDb/_ReadXML.py @@ -673,13 +673,23 @@ 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: + #I think this code is wrong, place has no ref attribute 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']) @@ -925,6 +935,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"])) @@ -934,6 +945,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"])) @@ -1040,7 +1052,7 @@ 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 @@ -1066,7 +1078,7 @@ 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 @@ -1153,7 +1165,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) @@ -1166,7 +1178,8 @@ class GrampsParser(UpdateCallback): self.reporef = RelLib.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=None) except KeyError: repo = self.find_repo_by_gramps_id(self.map_rid(attrs['ref'])) handle = repo.handle @@ -1182,7 +1195,7 @@ class GrampsParser(UpdateCallback): self.objref = RelLib.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 @@ -1617,20 +1630,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 = RelLib.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: