2007-12-09 Benny Malengier <benny.malengier@gramps-project.org>

Add support for name grouping import/export
	* src/GrampsDb/_GrampsDbWriteXML.py: write group table out
	* src/GrampsDb/_GrampsBSDDB.py: group table is no sec table, init it
		together with primary tables!
	* src/gen/db/base.py: obtain grouping keys
	* src/gen/db/dbdir.py: group table is no sec table, init it
		together with primary tables!
	* src/gen/utils/dbutils.py: grdb -> grdb copy of grouping table, 
		copy mediapath.
	* src/gen/proxy/proxybase.py: obtain grouping keys, add missing
		bookmark methods
	* src/gen/proxy/dbbase.py: add obtain grouping keys method
	* src/GrampsDbUtils/_ReadXML.py: read in group table
	* src/plugins/ReadGrdb.py: read in group table



svn: r9464
This commit is contained in:
Benny Malengier 2007-12-09 10:18:59 +00:00
parent ee1b05acef
commit 027036a8c5
10 changed files with 151 additions and 20 deletions

View File

@ -1,3 +1,19 @@
2007-12-09 Benny Malengier <benny.malengier@gramps-project.org>
Add support for name grouping import/export
* src/GrampsDb/_GrampsDbWriteXML.py: write group table out
* src/GrampsDb/_GrampsBSDDB.py: group table is no sec table, init it
together with primary tables!
* src/gen/db/base.py: obtain grouping keys
* src/gen/db/dbdir.py: group table is no sec table, init it
together with primary tables!
* src/gen/utils/dbutils.py: grdb -> grdb copy of grouping table,
copy mediapath.
* src/gen/proxy/proxybase.py: obtain grouping keys, add missing
bookmark methods
* src/gen/proxy/dbbase.py: add obtain grouping keys method
* src/GrampsDbUtils/_ReadXML.py: read in group table
* src/plugins/ReadGrdb.py: read in group table
2007-12-07 Douglas S. Blank <dblank@cs.brynmawr.edu> 2007-12-07 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/PluginUtils/Makefile.am: Missing _PluginsWindows.py * src/PluginUtils/Makefile.am: Missing _PluginsWindows.py
* po/test: new unittest dir * po/test: new unittest dir

View File

@ -165,8 +165,11 @@ class GrampsBSDDBDupCursor(GrampsBSDDBAssocCursor):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class GrampsBSDDB(GrampsDbBase, UpdateCallback): class GrampsBSDDB(GrampsDbBase, UpdateCallback):
"""GRAMPS database object. This object is a base class for other """ GRAMPS database object for Berkeley DB.
objects.""" This is replaced for internal use by gen/db/dbdir.py
However, this class is still used for import of the 2.2.x
GRDB format. In 3.0+ this format is no longer used.
"""
def __init__(self, use_txn = True): def __init__(self, use_txn = True):
"""creates a new GrampsDB""" """creates a new GrampsDB"""
@ -443,6 +446,15 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
self.reference_map = self.__open_table(self.full_name, "reference_map", self.reference_map = self.__open_table(self.full_name, "reference_map",
dbtype=db.DB_BTREE) dbtype=db.DB_BTREE)
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() self.__load_metadata()
gstats = self.metadata.get('gender_stats', default=None) gstats = self.metadata.get('gender_stats', default=None)
@ -587,11 +599,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",
@ -1189,6 +1196,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

View File

@ -342,8 +342,7 @@ class GrampsDbXmlWriter(UpdateCallback):
# Data is written, now write bookmarks. # Data is written, now write bookmarks.
self.write_bookmarks() self.write_bookmarks()
self.write_namemaps()
self.write_metadata()
self.g.write("</database>\n") self.g.write("</database>\n")
@ -357,6 +356,18 @@ class GrampsDbXmlWriter(UpdateCallback):
if mediapath is not None: if mediapath is not None:
self.write_line("mediapath", mediapath, 2) self.write_line("mediapath", mediapath, 2)
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())

View File

@ -394,9 +394,11 @@ 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),
"mediapath" : (None, self.stop_mediapath), "mediapath" : (None, self.stop_mediapath),
"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),
"noteref" : (self.start_noteref, None), "noteref" : (self.start_noteref, None),
@ -1170,6 +1172,21 @@ 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', '')

View File

@ -262,7 +262,6 @@ class GrampsDbBase(GrampsDBCallback):
self.note_bookmarks = GrampsDbBookmarks() self.note_bookmarks = GrampsDbBookmarks()
self._bm_changes = 0 self._bm_changes = 0
self.path = "" self.path = ""
self.name_group = {}
self.surname_list = [] self.surname_list = []
def set_prefixes(self, person, media, family, source, place, event, def set_prefixes(self, person, media, family, source, place, event,
@ -1198,6 +1197,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

View File

@ -533,6 +533,14 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
if callback: if callback:
callback(37) callback(37)
self.name_group = db.DB(self.env)
self.name_group.set_flags(db.DB_DUP)
if self.readonly:
self.name_group.open(_mkname(self.full_name, NAME_GROUP), NAME_GROUP,
db.DB_HASH, flags=db.DB_RDONLY)
else:
self.name_group.open(_mkname(self.full_name, NAME_GROUP), NAME_GROUP,
db.DB_HASH, flags=self.__open_flags())
self.__load_metadata() self.__load_metadata()
gstats = self.metadata.get('gender_stats', default=None) gstats = self.metadata.get('gender_stats', default=None)
@ -696,11 +704,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
self.surnames.open(_mkname(self.full_name, SURNAMES), SURNAMES, self.surnames.open(_mkname(self.full_name, SURNAMES), SURNAMES,
db.DB_BTREE, flags=table_flags) db.DB_BTREE, flags=table_flags)
self.name_group = db.DB(self.env)
self.name_group.set_flags(db.DB_DUP)
self.name_group.open(_mkname(self.full_name, NAME_GROUP), 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(_mkname(self.full_name, IDTRANS), IDTRANS, self.id_trans.open(_mkname(self.full_name, IDTRANS), IDTRANS,
@ -1290,6 +1293,7 @@ class GrampsDBDir(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

View File

@ -533,6 +533,12 @@ class DbBase:
""" """
raise NotImplementedError raise NotImplementedError
def has_name_group_key(self, name):
"""
Return if a key exists in the name_group table
"""
raise NotImplementedError
def get_name_group_keys(self): def get_name_group_keys(self):
""" """
Returns the defined names that have been assigned to a default grouping Returns the defined names that have been assigned to a default grouping

View File

@ -67,6 +67,12 @@ class ProxyDbBase(DbBase):
""" """
return self.db.get_name_group_mapping(name) return self.db.get_name_group_mapping(name)
def has_name_group_key(self, name):
"""
Return if a key exists in the name_group table
"""
return self.db.has_name_group_key(name)
def get_name_group_keys(self): def get_name_group_keys(self):
""" """
Returns the defined names that have been assigned to a default grouping Returns the defined names that have been assigned to a default grouping
@ -446,3 +452,35 @@ class ProxyDbBase(DbBase):
def has_gramps_id(self, obj_key, gramps_id): def has_gramps_id(self, obj_key, gramps_id):
return self.db.has_gramps_ids(obj_key, gramps_id) return self.db.has_gramps_ids(obj_key, gramps_id)
def get_bookmarks(self):
"""returns the list of Person handles in the bookmarks"""
return self.bookmarks
def get_family_bookmarks(self):
"""returns the list of Person handles in the bookmarks"""
return self.family_bookmarks
def get_event_bookmarks(self):
"""returns the list of Person handles in the bookmarks"""
return self.event_bookmarks
def get_place_bookmarks(self):
"""returns the list of Person handles in the bookmarks"""
return self.place_bookmarks
def get_source_bookmarks(self):
"""returns the list of Person handles in the bookmarks"""
return self.source_bookmarks
def get_media_bookmarks(self):
"""returns the list of Person handles in the bookmarks"""
return self.media_bookmarks
def get_repo_bookmarks(self):
"""returns the list of Person handles in the bookmarks"""
return self.repo_bookmarks
def get_note_bookmarks(self):
"""returns the list of Note handles in the bookmarks"""
return self.note_bookmarks

View File

@ -251,7 +251,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']
@ -268,8 +268,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
@ -288,6 +294,10 @@ def db_copy(from_db,to_db,callback):
# Copy db owner # Copy db owner
to_db.owner = from_db.owner to_db.owner = from_db.owner
# Copy other selected metadata
if from_db.get_mediapath() is not None:
to_db.set_mediapath(from_db.get_mediapath())
def set_birth_death_index(db, person): def set_birth_death_index(db, person):
birth_ref_index = -1 birth_ref_index = -1
death_ref_index = -1 death_ref_index = -1

View File

@ -230,6 +230,22 @@ def importData(database, filename, callback=None, cl=0, use_trans=True):
database.repo_bookmarks.append_list(other_database.repo_bookmarks.get()) database.repo_bookmarks.append_list(other_database.repo_bookmarks.get())
database.note_bookmarks.append_list(other_database.note_bookmarks.get()) database.note_bookmarks.append_list(other_database.note_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()