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

@@ -262,7 +262,6 @@ class GrampsDbBase(GrampsDBCallback):
self.note_bookmarks = GrampsDbBookmarks()
self._bm_changes = 0
self.path = ""
self.name_group = {}
self.surname_list = []
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()]
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):
"""
Sets the default grouping name for a surname. Needs to be overridden

View File

@@ -532,7 +532,15 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
dbtype=db.DB_BTREE)
if callback:
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()
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,
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.set_flags(db.DB_DUP)
self.id_trans.open(_mkname(self.full_name, IDTRANS), IDTRANS,
@@ -1290,6 +1293,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
self.media_map = None
self.event_map = None
self.surnames = None
self.name_group = None
self.env = None
self.metadata = None
self.db_is_open = False

View File

@@ -533,6 +533,12 @@ class DbBase:
"""
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):
"""
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)
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):
"""
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):
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
trans = to_db.transaction_begin("",batch=True)
trans = to_db.transaction_begin("", batch=True)
for table_name in tables.keys():
cursor_func = tables[table_name]['cursor_func']
@@ -268,8 +268,14 @@ def db_copy(from_db,to_db,callback):
uc.update()
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
to_db.transaction_commit(trans,"")
to_db.transaction_commit(trans, "")
# Copy bookmarks over:
# 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
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):
birth_ref_index = -1
death_ref_index = -1