parent
d7cba793cf
commit
159601d635
@ -1018,12 +1018,6 @@ class DbReadBase:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def has_gramps_id(self, obj_key, gramps_id):
|
||||
"""
|
||||
Returns True if the key exists in table given a table name
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def has_citation_gramps_id(self, gramps_id):
|
||||
"""
|
||||
Return True if the Gramps ID exists in the Citation table.
|
||||
|
@ -1268,16 +1268,6 @@ class DummyDb(M_A_M_B("NewBaseClass", (DbReadBase, Callback, object,), {})):
|
||||
LOG.warning("database is closed")
|
||||
return False
|
||||
|
||||
def has_gramps_id(self, obj_key, gramps_id):
|
||||
"""
|
||||
Returns True if the key exists in table given a table name
|
||||
|
||||
Not used in current codebase
|
||||
"""
|
||||
if not self.db_is_open:
|
||||
LOG.warning("database is closed")
|
||||
return False
|
||||
|
||||
def has_name_group_key(self, name):
|
||||
"""
|
||||
Return if a key exists in the name_group table.
|
||||
|
@ -1021,7 +1021,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
||||
Helper function for find_next_<object>_gramps_id methods
|
||||
"""
|
||||
index = prefix % map_index
|
||||
while self.has_gramps_id(obj_key, index):
|
||||
while self._has_gramps_id(obj_key, index):
|
||||
map_index += 1
|
||||
index = prefix % map_index
|
||||
map_index += 1
|
||||
@ -1402,35 +1402,35 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
||||
#
|
||||
################################################################
|
||||
|
||||
def has_gramps_id(self, obj_key, gramps_id):
|
||||
def _has_gramps_id(self, obj_key, gramps_id):
|
||||
raise NotImplementedError
|
||||
|
||||
def has_person_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(PERSON_KEY, gramps_id)
|
||||
return self._has_gramps_id(PERSON_KEY, gramps_id)
|
||||
|
||||
def has_family_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(FAMILY_KEY, gramps_id)
|
||||
return self._has_gramps_id(FAMILY_KEY, gramps_id)
|
||||
|
||||
def has_source_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(SOURCE_KEY, gramps_id)
|
||||
return self._has_gramps_id(SOURCE_KEY, gramps_id)
|
||||
|
||||
def has_citation_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(CITATION_KEY, gramps_id)
|
||||
return self._has_gramps_id(CITATION_KEY, gramps_id)
|
||||
|
||||
def has_event_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(EVENT_KEY, gramps_id)
|
||||
return self._has_gramps_id(EVENT_KEY, gramps_id)
|
||||
|
||||
def has_media_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(MEDIA_KEY, gramps_id)
|
||||
return self._has_gramps_id(MEDIA_KEY, gramps_id)
|
||||
|
||||
def has_place_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(PLACE_KEY, gramps_id)
|
||||
return self._has_gramps_id(PLACE_KEY, gramps_id)
|
||||
|
||||
def has_repository_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(REPOSITORY_KEY, gramps_id)
|
||||
return self._has_gramps_id(REPOSITORY_KEY, gramps_id)
|
||||
|
||||
def has_note_gramps_id(self, gramps_id):
|
||||
return self.has_gramps_id(NOTE_KEY, gramps_id)
|
||||
return self._has_gramps_id(NOTE_KEY, gramps_id)
|
||||
|
||||
################################################################
|
||||
#
|
||||
|
@ -936,9 +936,6 @@ class ProxyDbBase(DbReadBase):
|
||||
"""returns the default media path of the database"""
|
||||
return self.db.get_mediapath()
|
||||
|
||||
def has_gramps_id(self, obj_key, gramps_id):
|
||||
return self.db.has_gramps_id(obj_key, gramps_id)
|
||||
|
||||
def get_bookmarks(self):
|
||||
"""returns the list of Person handles in the bookmarks"""
|
||||
return self.bookmarks
|
||||
|
@ -1179,23 +1179,6 @@ class DbBsddbRead(DbReadBase, Callback):
|
||||
iter_tags = _f(get_tag_cursor, Tag)
|
||||
del _f
|
||||
|
||||
def has_gramps_id(self, obj_key, gramps_id):
|
||||
key2table = {
|
||||
PERSON_KEY: self.id_trans,
|
||||
FAMILY_KEY: self.fid_trans,
|
||||
SOURCE_KEY: self.sid_trans,
|
||||
CITATION_KEY: self.cid_trans,
|
||||
EVENT_KEY: self.eid_trans,
|
||||
MEDIA_KEY: self.oid_trans,
|
||||
PLACE_KEY: self.pid_trans,
|
||||
REPOSITORY_KEY: self.rid_trans,
|
||||
NOTE_KEY: self.nid_trans,
|
||||
}
|
||||
|
||||
table = key2table[obj_key]
|
||||
gramps_id = gramps_id.encode('utf-8')
|
||||
return table.get(gramps_id, txn=self.txn) is not None
|
||||
|
||||
def find_initial_person(self):
|
||||
person = self.get_default_person()
|
||||
if not person:
|
||||
|
@ -123,7 +123,6 @@ class DbTest(unittest.TestCase):
|
||||
"get_url_types",
|
||||
"has_event_handle",
|
||||
"has_family_handle",
|
||||
"has_gramps_id",
|
||||
"has_name_group_key",
|
||||
"has_note_handle",
|
||||
"has_media_handle",
|
||||
|
@ -827,7 +827,7 @@ class DBAPI(DbGeneric):
|
||||
self.dbapi.execute(sql, [handle])
|
||||
return self.dbapi.fetchone() is not None
|
||||
|
||||
def has_gramps_id(self, obj_key, gramps_id):
|
||||
def _has_gramps_id(self, obj_key, gramps_id):
|
||||
table = KEY_TO_NAME_MAP[obj_key]
|
||||
sql = "SELECT 1 FROM %s WHERE gramps_id = ?" % table
|
||||
self.dbapi.execute(sql, [gramps_id])
|
||||
|
@ -854,9 +854,18 @@ class GrampsParser(UpdateCallback):
|
||||
self.db.find_next_repository_gramps_id,
|
||||
'reference',
|
||||
self.db.find_next_note_gramps_id][key]
|
||||
has_gramps_id = [self.db.has_person_gramps_id,
|
||||
self.db.has_family_gramps_id,
|
||||
self.db.has_source_gramps_id,
|
||||
self.db.has_event_gramps_id,
|
||||
self.db.has_media_gramps_id,
|
||||
self.db.has_place_gramps_id,
|
||||
self.db.has_repository_gramps_id,
|
||||
'reference',
|
||||
self.db.has_note_gramps_id][key]
|
||||
|
||||
gramps_id = self.legalize_id(id_, key, id2id_map, id2user_format,
|
||||
find_next_gramps_id)
|
||||
find_next_gramps_id, has_gramps_id)
|
||||
handle = id2handle_map.get(gramps_id)
|
||||
if handle:
|
||||
raw = get_raw_obj_data(handle)
|
||||
@ -874,7 +883,7 @@ class GrampsParser(UpdateCallback):
|
||||
return handle
|
||||
|
||||
def legalize_id(self, id_, key, gramps_ids, id2user_format,
|
||||
find_next_gramps_id):
|
||||
find_next_gramps_id, has_gramps_id):
|
||||
"""
|
||||
Given an import id, adjust it so that it fits with the existing data.
|
||||
|
||||
@ -894,7 +903,7 @@ class GrampsParser(UpdateCallback):
|
||||
"""
|
||||
gramps_id = id2user_format(id_)
|
||||
if gramps_id is None or not gramps_ids.get(id_):
|
||||
if gramps_id is None or self.db.has_gramps_id(key, gramps_id):
|
||||
if gramps_id is None or has_gramps_id(gramps_id):
|
||||
gramps_ids[id_] = find_next_gramps_id()
|
||||
else:
|
||||
gramps_ids[id_] = gramps_id
|
||||
@ -1116,7 +1125,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "place", self.placeobj)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), PLACE_KEY,
|
||||
self.pidswap, self.db.pid2user_format,
|
||||
self.db.find_next_place_gramps_id)
|
||||
self.db.find_next_place_gramps_id,
|
||||
self.db.has_place_gramps_id)
|
||||
self.placeobj.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_place = self.db.get_place_from_handle(orig_handle)
|
||||
@ -1254,7 +1264,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "event", self.event)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), EVENT_KEY,
|
||||
self.eidswap, self.db.eid2user_format,
|
||||
self.db.find_next_event_gramps_id)
|
||||
self.db.find_next_event_gramps_id,
|
||||
self.db.has_event_gramps_id)
|
||||
self.event.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_event = self.db.get_event_from_handle(orig_handle)
|
||||
@ -1451,7 +1462,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "person", self.person)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), PERSON_KEY,
|
||||
self.idswap, self.db.id2user_format,
|
||||
self.db.find_next_person_gramps_id)
|
||||
self.db.find_next_person_gramps_id,
|
||||
self.db.has_person_gramps_id)
|
||||
self.person.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_person = self.db.get_person_from_handle(orig_handle)
|
||||
@ -1585,7 +1597,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "family", self.family)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), FAMILY_KEY,
|
||||
self.fidswap, self.db.fid2user_format,
|
||||
self.db.find_next_family_gramps_id)
|
||||
self.db.find_next_family_gramps_id,
|
||||
self.db.has_family_gramps_id)
|
||||
self.family.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_family = self.db.get_family_from_handle(orig_handle)
|
||||
@ -1865,7 +1878,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "note", self.note)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), NOTE_KEY,
|
||||
self.nidswap, self.db.nid2user_format,
|
||||
self.db.find_next_note_gramps_id)
|
||||
self.db.find_next_note_gramps_id,
|
||||
self.db.has_note_gramps_id)
|
||||
self.note.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_note = self.db.get_note_from_handle(orig_handle)
|
||||
@ -2062,7 +2076,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "citation", self.citation)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), CITATION_KEY,
|
||||
self.cidswap, self.db.cid2user_format,
|
||||
self.db.find_next_citation_gramps_id)
|
||||
self.db.find_next_citation_gramps_id,
|
||||
self.db.has_citation_gramps_id)
|
||||
self.citation.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_citation = self.db.get_citation_from_handle(orig_handle)
|
||||
@ -2116,7 +2131,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "source", self.source)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), SOURCE_KEY,
|
||||
self.sidswap, self.db.sid2user_format,
|
||||
self.db.find_next_source_gramps_id)
|
||||
self.db.find_next_source_gramps_id,
|
||||
self.db.has_source_gramps_id)
|
||||
self.source.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_source = self.db.get_source_from_handle(orig_handle)
|
||||
@ -2195,7 +2211,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "media", self.object)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), MEDIA_KEY,
|
||||
self.oidswap, self.db.oid2user_format,
|
||||
self.db.find_next_media_gramps_id)
|
||||
self.db.find_next_media_gramps_id,
|
||||
self.db.has_media_gramps_id)
|
||||
self.object.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_media = self.db.get_media_from_handle(orig_handle)
|
||||
@ -2232,7 +2249,8 @@ class GrampsParser(UpdateCallback):
|
||||
self.inaugurate(orig_handle, "repository", self.repo)
|
||||
gramps_id = self.legalize_id(attrs.get('id'), REPOSITORY_KEY,
|
||||
self.ridswap, self.db.rid2user_format,
|
||||
self.db.find_next_repository_gramps_id)
|
||||
self.db.find_next_repository_gramps_id,
|
||||
self.db.has_repository_gramps_id)
|
||||
self.repo.set_gramps_id(gramps_id)
|
||||
if is_merge_candidate:
|
||||
orig_repo = self.db.get_repository_from_handle(orig_handle)
|
||||
|
Loading…
Reference in New Issue
Block a user