2007-11-24 Benny Malengier <benny.malengier@gramps-project.org>
Add support for name grouping import/export * src/GrampsDb/_GrampsDbBase.py: obtain grouping keys * src/GrampsDb/_ReadXML.py: read in group table * src/GrampsDb/_DbUtils.py: grdb -> grdb copy of grouping table * src/GrampsDb/_ReadGrdb.py: read in group table * src/GrampsDb/_WriteXML.py: write group table out * src/GrampsDb/_GrampsBSDDB.py: group table is no sec table, init it together with primary tables! svn: r9457
This commit is contained in:
parent
b7d7a060f5
commit
e385af623d
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2007-11-24 Benny Malengier <benny.malengier@gramps-project.org>
|
||||||
|
Add support for name grouping import/export
|
||||||
|
* src/GrampsDb/_GrampsDbBase.py: obtain grouping keys
|
||||||
|
* src/GrampsDb/_ReadXML.py: read in group table
|
||||||
|
* src/GrampsDb/_DbUtils.py: grdb -> grdb copy of grouping table
|
||||||
|
* src/GrampsDb/_ReadGrdb.py: read in group table
|
||||||
|
* src/GrampsDb/_WriteXML.py: write group table out
|
||||||
|
* src/GrampsDb/_GrampsBSDDB.py: group table is no sec table, init it
|
||||||
|
together with primary tables!
|
||||||
|
|
||||||
2007-11-28 Jim Sack <jgsack@san.rr.com>
|
2007-11-28 Jim Sack <jgsack@san.rr.com>
|
||||||
* src/GrampsDb/_ReadGedcom.py : #1399 remove trail whitespace (readahead)
|
* src/GrampsDb/_ReadGedcom.py : #1399 remove trail whitespace (readahead)
|
||||||
fixes discarded reference due to bogus handles that get created
|
fixes discarded reference due to bogus handles that get created
|
||||||
|
@ -242,7 +242,7 @@ def db_copy(from_db,to_db,callback):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Start batch transaction to use async TXN and other tricks
|
# Start batch transaction to use async TXN and other tricks
|
||||||
trans = to_db.transaction_begin("",batch=True)
|
trans = to_db.transaction_begin("", batch=True)
|
||||||
|
|
||||||
for table_name in tables.keys():
|
for table_name in tables.keys():
|
||||||
cursor_func = tables[table_name]['cursor_func']
|
cursor_func = tables[table_name]['cursor_func']
|
||||||
@ -259,8 +259,14 @@ def db_copy(from_db,to_db,callback):
|
|||||||
uc.update()
|
uc.update()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
# Copy name grouping
|
||||||
|
group_map = from_db.get_name_group_keys()
|
||||||
|
for key in group_map:
|
||||||
|
value = from_db.get_name_group_mapping(key)
|
||||||
|
to_db.set_name_group_mapping(key, value)
|
||||||
|
|
||||||
# Commit batch transaction: does nothing, except undoing the tricks
|
# Commit batch transaction: does nothing, except undoing the tricks
|
||||||
to_db.transaction_commit(trans,"")
|
to_db.transaction_commit(trans, "")
|
||||||
|
|
||||||
# Copy bookmarks over:
|
# Copy bookmarks over:
|
||||||
# we already know that there's no overlap in handles anywhere
|
# we already know that there's no overlap in handles anywhere
|
||||||
|
@ -399,8 +399,16 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
dbtype=db.DB_BTREE)
|
dbtype=db.DB_BTREE)
|
||||||
callback(37)
|
callback(37)
|
||||||
|
|
||||||
self._load_metadata()
|
self.name_group = db.DB(self.env)
|
||||||
|
self.name_group.set_flags(db.DB_DUP)
|
||||||
|
if self.readonly:
|
||||||
|
self.name_group.open(self.full_name, "name_group",
|
||||||
|
db.DB_HASH, flags=db.DB_RDONLY)
|
||||||
|
else:
|
||||||
|
self.name_group.open(self.full_name, "name_group",
|
||||||
|
db.DB_HASH, flags=self.open_flags())
|
||||||
|
|
||||||
|
self._load_metadata()
|
||||||
gstats = self.metadata.get('gender_stats',default=None)
|
gstats = self.metadata.get('gender_stats',default=None)
|
||||||
|
|
||||||
if not self.readonly:
|
if not self.readonly:
|
||||||
@ -529,11 +537,6 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
self.surnames.open(self.full_name, "surnames", db.DB_BTREE,
|
self.surnames.open(self.full_name, "surnames", db.DB_BTREE,
|
||||||
flags=table_flags)
|
flags=table_flags)
|
||||||
|
|
||||||
self.name_group = db.DB(self.env)
|
|
||||||
self.name_group.set_flags(db.DB_DUP)
|
|
||||||
self.name_group.open(self.full_name, "name_group",
|
|
||||||
db.DB_HASH, flags=table_flags)
|
|
||||||
|
|
||||||
self.id_trans = db.DB(self.env)
|
self.id_trans = db.DB(self.env)
|
||||||
self.id_trans.set_flags(db.DB_DUP)
|
self.id_trans.set_flags(db.DB_DUP)
|
||||||
self.id_trans.open(self.full_name, "idtrans",
|
self.id_trans.open(self.full_name, "idtrans",
|
||||||
@ -1117,6 +1120,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
self.media_map = None
|
self.media_map = None
|
||||||
self.event_map = None
|
self.event_map = None
|
||||||
self.surnames = None
|
self.surnames = None
|
||||||
|
self.name_group = None
|
||||||
self.env = None
|
self.env = None
|
||||||
self.metadata = None
|
self.metadata = None
|
||||||
self.db_is_open = False
|
self.db_is_open = False
|
||||||
|
@ -1135,6 +1135,12 @@ class GrampsDbBase(GrampsDBCallback):
|
|||||||
"""
|
"""
|
||||||
return [unicode(k) for k in self.name_group.keys()]
|
return [unicode(k) for k in self.name_group.keys()]
|
||||||
|
|
||||||
|
def has_name_group_key(self, name):
|
||||||
|
"""
|
||||||
|
Return if a key exists in the name_group table
|
||||||
|
"""
|
||||||
|
return self.name_group.has_key(str(name))
|
||||||
|
|
||||||
def set_name_group_mapping(self, name, group):
|
def set_name_group_mapping(self, name, group):
|
||||||
"""
|
"""
|
||||||
Sets the default grouping name for a surname. Needs to be overridden
|
Sets the default grouping name for a surname. Needs to be overridden
|
||||||
|
@ -196,6 +196,22 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
|
|||||||
database.media_bookmarks.append_list(other_database.media_bookmarks.get())
|
database.media_bookmarks.append_list(other_database.media_bookmarks.get())
|
||||||
database.repo_bookmarks.append_list(other_database.repo_bookmarks.get())
|
database.repo_bookmarks.append_list(other_database.repo_bookmarks.get())
|
||||||
|
|
||||||
|
# Copy grouping table
|
||||||
|
group_map = other_database.get_name_group_keys()
|
||||||
|
name_len = len(group_map)
|
||||||
|
if name_len > 0:
|
||||||
|
for key in group_map:
|
||||||
|
value = other_database.get_name_group_mapping(key)
|
||||||
|
if database.has_name_group_key(key) :
|
||||||
|
present = database.get_name_group_mapping(key)
|
||||||
|
if not value == present:
|
||||||
|
msg = _("Your family tree groups name %s together"
|
||||||
|
" with %s, did not change this grouping to %s") % (
|
||||||
|
key, present, value)
|
||||||
|
print msg
|
||||||
|
else:
|
||||||
|
database.set_name_group_mapping(key, value)
|
||||||
|
|
||||||
# close the other database and clean things up
|
# close the other database and clean things up
|
||||||
other_database.close()
|
other_database.close()
|
||||||
|
|
||||||
|
@ -393,8 +393,10 @@ class GrampsParser(UpdateCallback):
|
|||||||
"gender" : (None, self.stop_gender),
|
"gender" : (None, self.stop_gender),
|
||||||
"header" : (None, None),
|
"header" : (None, None),
|
||||||
"last" : (self.start_last, self.stop_last),
|
"last" : (self.start_last, self.stop_last),
|
||||||
|
"map" : (self.start_namemap, None),
|
||||||
"mother" : (self.start_mother,None),
|
"mother" : (self.start_mother,None),
|
||||||
"name" : (self.start_name, self.stop_name),
|
"name" : (self.start_name, self.stop_name),
|
||||||
|
"namemaps" : (None, None),
|
||||||
"nick" : (None, self.stop_nick),
|
"nick" : (None, self.stop_nick),
|
||||||
"note" : (self.start_note, self.stop_note),
|
"note" : (self.start_note, self.stop_note),
|
||||||
"p" : (None, self.stop_ptag),
|
"p" : (None, self.stop_ptag),
|
||||||
@ -451,6 +453,9 @@ class GrampsParser(UpdateCallback):
|
|||||||
"rname" : (None, self.stop_rname),
|
"rname" : (None, self.stop_rname),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def errmsg(self, msg):
|
||||||
|
log.warning(msg)
|
||||||
|
|
||||||
def find_person_by_gramps_id(self,gramps_id):
|
def find_person_by_gramps_id(self,gramps_id):
|
||||||
intid = self.gid2id.get(gramps_id)
|
intid = self.gid2id.get(gramps_id)
|
||||||
if intid:
|
if intid:
|
||||||
@ -1112,6 +1117,22 @@ class GrampsParser(UpdateCallback):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def start_namemap(self, attrs):
|
||||||
|
type = attrs.get('type')
|
||||||
|
|
||||||
|
key = attrs['key']
|
||||||
|
value = attrs['value']
|
||||||
|
if type == 'group_as':
|
||||||
|
if self.db.has_name_group_key(key) :
|
||||||
|
present = self.db.get_name_group_mapping(key)
|
||||||
|
if not value == present:
|
||||||
|
msg = _("Your family tree groups name %s together"
|
||||||
|
" with %s, did not change this grouping to %s") % (
|
||||||
|
key, present, value)
|
||||||
|
self.errmsg(msg)
|
||||||
|
else:
|
||||||
|
self.db.set_name_group_mapping(key, value)
|
||||||
|
|
||||||
def start_last(self,attrs):
|
def start_last(self,attrs):
|
||||||
self.name.prefix = attrs.get('prefix','')
|
self.name.prefix = attrs.get('prefix','')
|
||||||
self.name.group_as = attrs.get('group','')
|
self.name.group_as = attrs.get('group','')
|
||||||
|
@ -321,9 +321,22 @@ class XmlWriter(UpdateCallback):
|
|||||||
|
|
||||||
# Data is written, now write bookmarks.
|
# Data is written, now write bookmarks.
|
||||||
self.write_bookmarks()
|
self.write_bookmarks()
|
||||||
|
self.write_namemaps()
|
||||||
|
|
||||||
self.g.write("</database>\n")
|
self.g.write("</database>\n")
|
||||||
|
|
||||||
|
def write_namemaps(self):
|
||||||
|
group_map = self.db.get_name_group_keys()
|
||||||
|
name_len = len(group_map)
|
||||||
|
|
||||||
|
if name_len > 0:
|
||||||
|
self.g.write(" <namemaps>\n")
|
||||||
|
for key in group_map:
|
||||||
|
value = self.db.get_name_group_mapping(key)
|
||||||
|
self.g.write(' <map type="group_as" key="%s" value="%s"/>\n'
|
||||||
|
% (key, value) )
|
||||||
|
self.g.write(" </namemaps>\n")
|
||||||
|
|
||||||
def write_bookmarks(self):
|
def write_bookmarks(self):
|
||||||
bm_person_len = len(self.db.bookmarks.get())
|
bm_person_len = len(self.db.bookmarks.get())
|
||||||
bm_family_len = len(self.db.family_bookmarks.get())
|
bm_family_len = len(self.db.family_bookmarks.get())
|
||||||
|
Loading…
Reference in New Issue
Block a user