2007-10-11 Benny Malengier <benny.malengier@gramps-project.org>

* 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



svn: r9149
This commit is contained in:
Benny Malengier 2007-10-11 21:40:30 +00:00
parent 36d767dda5
commit c503010ac0
3 changed files with 77 additions and 35 deletions

View File

@ -1,3 +1,8 @@
2007-10-11 Benny Malengier <benny.malengier@gramps-project.org>
* 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 <shura@gramps-project.org> 2007-10-11 Alex Roitman <shura@gramps-project.org>
* src/plugins/unused.glade: Do not translate gtk stock label id. * src/plugins/unused.glade: Do not translate gtk stock label id.

View File

@ -854,13 +854,15 @@ class GrampsDbBase(GrampsDBCallback):
return self._find_from_handle(handle, transaction, Repository, return self._find_from_handle(handle, transaction, Repository,
self.repository_map, self.add_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. 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 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._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): def check_source_from_handle(self, handle, transaction, set_gid=True):
""" """
@ -872,48 +874,58 @@ class GrampsDbBase(GrampsDBCallback):
self.source_map, self.add_source, self.source_map, self.add_source,
set_gid=set_gid) 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. 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 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._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 Checks whether a MediaObject with the passed handle exists in
the database. If no such MediaObject exists, a new Object is the database. If no such MediaObject exists, a new Object is
added to the database. 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._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. 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 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._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. 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 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._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 Checks whether a Repository with the passed handle exists in the
database. If no such Repository exists, a new Repository is added database. If no such Repository exists, a new Repository is added
to the database. 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._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): def get_person_from_gramps_id(self, val):
""" """

View File

@ -673,13 +673,23 @@ class GrampsParser(UpdateCallback):
self.ord.set_family_handle(handle) self.ord.set_family_handle(handle)
def start_place(self,attrs): def start_place(self,attrs):
"""A reference to a place in an object: event or lds_ord
"""
try: try:
self.placeobj = self.db.find_place_from_handle( handle = attrs['hlink'].replace('_','')
attrs['hlink'].replace('_',''),self.trans) self.db.check_place_from_handle(handle,self.trans,set_gid = False)
except KeyError: except KeyError:
#I think this code is wrong, place has no ref attribute
gramps_id = self.map_pid(attrs['ref']) gramps_id = self.map_pid(attrs['ref'])
self.placeobj = self.find_place_by_gramps_id(gramps_id) place = self.find_place_by_gramps_id(gramps_id)
self.placeobj.private = bool(attrs.get("priv")) 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): def start_placeobj(self,attrs):
gramps_id = self.map_pid(attrs['id']) gramps_id = self.map_pid(attrs['id'])
@ -925,6 +935,7 @@ class GrampsParser(UpdateCallback):
def start_father(self,attrs): def start_father(self,attrs):
try: try:
handle = attrs['hlink'].replace('_','') handle = attrs['hlink'].replace('_','')
#all persons exist before father tag is encountered
self.db.check_person_from_handle(handle,self.trans) self.db.check_person_from_handle(handle,self.trans)
except KeyError: except KeyError:
person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"])) person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
@ -934,6 +945,7 @@ class GrampsParser(UpdateCallback):
def start_mother(self,attrs): def start_mother(self,attrs):
try: try:
handle = attrs['hlink'].replace('_','') handle = attrs['hlink'].replace('_','')
#all persons exist before mother tag is encountered
self.db.check_person_from_handle(handle,self.trans) self.db.check_person_from_handle(handle,self.trans)
except KeyError: except KeyError:
person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"])) person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
@ -1040,7 +1052,7 @@ class GrampsParser(UpdateCallback):
def start_childof(self,attrs): def start_childof(self,attrs):
try: try:
handle = attrs["hlink"].replace('_','') 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: except KeyError:
family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"]))
handle = family.handle handle = family.handle
@ -1066,7 +1078,7 @@ class GrampsParser(UpdateCallback):
def start_parentin(self,attrs): def start_parentin(self,attrs):
try: try:
handle = attrs["hlink"].replace('_','') 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: except KeyError:
family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"]))
handle = family.handle handle = family.handle
@ -1153,7 +1165,7 @@ class GrampsParser(UpdateCallback):
def start_source(self,attrs): def start_source(self,attrs):
self.update(self.p.CurrentLineNumber) 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: try:
self.source = self.db.find_source_from_handle( self.source = self.db.find_source_from_handle(
attrs['handle'].replace('_',''),self.trans) attrs['handle'].replace('_',''),self.trans)
@ -1166,7 +1178,8 @@ class GrampsParser(UpdateCallback):
self.reporef = RelLib.RepoRef() self.reporef = RelLib.RepoRef()
try: try:
handle = attrs['hlink'].replace('_','') 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: except KeyError:
repo = self.find_repo_by_gramps_id(self.map_rid(attrs['ref'])) repo = self.find_repo_by_gramps_id(self.map_rid(attrs['ref']))
handle = repo.handle handle = repo.handle
@ -1182,7 +1195,7 @@ class GrampsParser(UpdateCallback):
self.objref = RelLib.MediaRef() self.objref = RelLib.MediaRef()
try: try:
handle = attrs['hlink'].replace('_','') 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: except KeyError:
obj = self.find_object_by_gramps_id(self.map_oid(attrs['ref'])) obj = self.find_object_by_gramps_id(self.map_oid(attrs['ref']))
handle = obj.handle handle = obj.handle
@ -1617,20 +1630,32 @@ class GrampsParser(UpdateCallback):
self.db.commit_person(person,self.trans,self.change) self.db.commit_person(person,self.trans,self.change)
def stop_place(self,tag): def stop_place(self,tag):
if self.placeobj == None: """end of a reference to place, should do nothing ...
if self.place_map.has_key(tag): Note, if we encounter <place>blabla</place> this method is called
self.placeobj = self.place_map[tag] with tag='blabla
else: """
self.placeobj = RelLib.Place() ##place = None
self.placeobj.set_title(tag) ##handle = None
if self.ord: ##if self.place_ref == None: #todo, add place_ref in start and init
self.ord.set_place_handle(self.placeobj.get_handle()) ## #legacy cody? I see no reason for this, but it was present
elif self.object: ## if self.place_map.has_key(tag):
self.object.set_place_handle(self.placeobj.get_handle()) ## place = self.place_map[tag]
else: ## handle = place.get_handle()
self.event.set_place_handle(self.placeobj.get_handle()) ## place = None
self.db.commit_place(self.placeobj,self.trans,self.change) ## else:
self.placeobj = None ## 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): def stop_date(self,tag):
if tag: if tag: