From 967ef1c163e6e218d45d78c3a8832f83c9b089ed Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Tue, 9 Oct 2007 20:02:02 +0000 Subject: [PATCH] 2007-10-09 Benny Malengier * src/gen/db/base.py: allow not to create gramps_id on add * src/GrampsDbUtils/_ReadXML.py: on sourceref, don't create gramps_id * src/GrampsDb/_GrampsInMemDB.py: remove gid from memory map only if not None svn: r9119 --- ChangeLog | 5 ++ src/GrampsDb/_GrampsInMemDB.py | 2 +- src/GrampsDbUtils/_ReadXML.py | 4 +- src/gen/db/base.py | 126 +++++++++++++++++++++++---------- 4 files changed, 97 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04a092043..f4ec93733 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-10-09 Benny Malengier + * src/gen/db/base.py: allow not to create gramps_id on add + * src/GrampsDbUtils/_ReadXML.py: on sourceref, don't create gramps_id + * src/GrampsDb/_GrampsInMemDB.py: remove gid from memory map only if not None + 2007-10-09 Benny Malengier * src/GrampsDb/_GrampsInMemDB.py: correctly store global name grouping * src/GrampsDb/_GrampsBSDDB.py: correctly store global name grouping diff --git a/src/GrampsDb/_GrampsInMemDB.py b/src/GrampsDb/_GrampsInMemDB.py index 85cce36fb..1495032e5 100644 --- a/src/GrampsDb/_GrampsInMemDB.py +++ b/src/GrampsDb/_GrampsInMemDB.py @@ -252,7 +252,7 @@ class GrampsInMemDB(GrampsDbBase): old_data = db_map.get(obj.handle) if old_data: old_id = old_data[self.ID_INDEX] - if obj.gramps_id != old_id: + if old_id is not None and obj.gramps_id != old_id: del trans_map[old_id] trans_map[gid] = obj.handle return True diff --git a/src/GrampsDbUtils/_ReadXML.py b/src/GrampsDbUtils/_ReadXML.py index a0b6f94b8..a39da8fd8 100644 --- a/src/GrampsDbUtils/_ReadXML.py +++ b/src/GrampsDbUtils/_ReadXML.py @@ -1265,7 +1265,9 @@ class GrampsParser(UpdateCallback): self.source_ref = gen.lib.SourceRef() try: handle = attrs["hlink"].replace('_', '') - self.db.check_source_from_handle(handle, self.trans) + #create source object to obtain handle, gid is set in start_source + self.db.check_source_from_handle(handle, self.trans, + set_gid = False) except KeyError: source = self.find_source_by_gramps_id(self.map_sid(attrs["ref"])) handle = source.handle diff --git a/src/gen/db/base.py b/src/gen/db/base.py index be22d3869..1df4b31e0 100644 --- a/src/gen/db/base.py +++ b/src/gen/db/base.py @@ -260,7 +260,7 @@ class GrampsDbBase(GrampsDBCallback): self.repo_bookmarks = GrampsDbBookmarks() self.media_bookmarks = GrampsDbBookmarks() self.note_bookmarks = GrampsDbBookmarks() - self._bm_changes = 0 + self._bm_changes = 0 self.path = "" self.name_group = {} self.surname_list = [] @@ -816,12 +816,12 @@ class GrampsDbBase(GrampsDBCallback): return obj def __check_from_handle(self, handle, transaction, class_type, dmap, - add_func): + add_func, set_gid=True): handle = str(handle) if not dmap.has_key(handle): obj = class_type() obj.set_handle(handle) - add_func(obj, transaction) + add_func(obj, transaction, set_gid=set_gid) def find_person_from_handle(self, handle, transaction): """ @@ -895,14 +895,16 @@ class GrampsDbBase(GrampsDBCallback): self.__check_from_handle(handle, transaction, Person, self.person_map, self.add_person) - def check_source_from_handle(self, handle, transaction): + def check_source_from_handle(self, handle, transaction, set_gid=True): """ Checks whether a Source with the passed handle exists in the database. If no such Source exists, a new Source 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, Source, - self.source_map, self.add_source) - + self.source_map, self.add_source, + set_gid=set_gid) + def check_event_from_handle(self, handle, transaction): """ Checks whether an Event with the passed handle exists in the database. @@ -1028,7 +1030,7 @@ class GrampsDbBase(GrampsDBCallback): raise NotImplementedError def __add_object(self, obj, transaction, find_next_func, commit_func): - if not obj.gramps_id: + if find_next_func and not obj.gramps_id: obj.gramps_id = find_next_func() if not obj.handle: obj.handle = self.create_id() @@ -1037,41 +1039,65 @@ class GrampsDbBase(GrampsDBCallback): self.genderStats.count_person (obj) return obj.handle - def add_person(self, person, transaction): + def add_person(self, person, transaction, set_gid=True): """ Adds a Person to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(person, transaction, - self.find_next_person_gramps_id, - self.commit_person) + if set_gid: + return self.__add_object(person, transaction, + self.find_next_person_gramps_id, + self.commit_person) + else: + return self.__add_object(person, transaction, + None, + self.commit_person) - def add_family(self, family, transaction): + def add_family(self, family, transaction, set_gid=True): """ Adds a Family to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(family, transaction, - self.find_next_family_gramps_id, - self.commit_family) + if set_gid: + return self.__add_object(family, transaction, + self.find_next_family_gramps_id, + self.commit_family) + else: + return self.__add_object(family, transaction, + None, + self.commit_family) - def add_source(self, source, transaction): + def add_source(self, source, transaction, set_gid=True): """ Adds a Source to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(source, transaction, - self.find_next_source_gramps_id, + if set_gid: + return self.__add_object(source, transaction, + self.find_next_source_gramps_id, + self.commit_source) + else : + return self.__add_object(source, transaction, + None, self.commit_source) - def add_event(self, event, transaction): + def add_event(self, event, transaction, set_gid=True): """ Adds an Event to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(event, transaction, - self.find_next_event_gramps_id, - self.commit_event) + if set_gid: + return self.__add_object(event, transaction, + self.find_next_event_gramps_id, + self.commit_event) + else: + return self.__add_object(event, transaction, + None, + self.commit_event) def add_person_event(self, event, transaction): """ @@ -1091,41 +1117,65 @@ class GrampsDbBase(GrampsDBCallback): self.family_event_names.add(str(event.type)) return self.add_event(event, transaction) - def add_place(self, place, transaction): + def add_place(self, place, transaction, set_gid=True): """ Adds a Place to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(place, transaction, - self.find_next_place_gramps_id, - self.commit_place) + if set_gid: + return self.__add_object(place, transaction, + self.find_next_place_gramps_id, + self.commit_place) + else: + return self.__add_object(place, transaction, + None, + self.commit_place) - def add_object(self, obj, transaction): + def add_object(self, obj, transaction, set_gid=True): """ Adds a MediaObject to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(obj, transaction, - self.find_next_object_gramps_id, - self.commit_media_object) + if set_gid: + return self.__add_object(obj, transaction, + self.find_next_object_gramps_id, + self.commit_media_object) + else: + return self.__add_object(obj, transaction, + None, + self.commit_media_object) - def add_repository(self, obj, transaction): + def add_repository(self, obj, transaction, set_gid=True): """ Adds a Repository to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(obj, transaction, - self.find_next_repository_gramps_id, - self.commit_repository) + if set_gid: + return self.__add_object(obj, transaction, + self.find_next_repository_gramps_id, + self.commit_repository) + else: + return self.__add_object(obj, transaction, + None, + self.commit_repository) - def add_note(self, obj, transaction): + def add_note(self, obj, transaction, set_gid=True): """ Adds a Note to the database, assigning internal IDs if they have not already been defined. + If not set_gid, then gramps_id is not set """ - return self.__add_object(obj, transaction, - self.find_next_note_gramps_id, - self.commit_note) + if set_gid: + return self.__add_object(obj, transaction, + self.find_next_note_gramps_id, + self.commit_note) + else: + return self.__add_object(obj, transaction, + None, + self.commit_note) def get_name_group_mapping(self, name): """