Fix reordering task for ZODB support

svn: r1015
This commit is contained in:
Don Allingham 2002-05-31 04:04:33 +00:00
parent 4bac61b9e3
commit d7f0b5e424
3 changed files with 75 additions and 90 deletions

View File

@ -123,6 +123,11 @@ class Gramps:
# a GrampsXML or GrampsZODB # a GrampsXML or GrampsZODB
self.db = GrampsDB() self.db = GrampsDB()
self.db.set_iprefix(GrampsCfg.iprefix)
self.db.set_oprefix(GrampsCfg.oprefix)
self.db.set_fprefix(GrampsCfg.fprefix)
self.db.set_sprefix(GrampsCfg.sprefix)
self.db.set_pprefix(GrampsCfg.pprefix)
(self.scol,self.sdir) = GrampsCfg.get_sort_cols("person",self.scol,self.sdir) (self.scol,self.sdir) = GrampsCfg.get_sort_cols("person",self.scol,self.sdir)
@ -136,12 +141,6 @@ class Gramps:
self.change_sort(self.scol,self.sdir==GTK.SORT_DESCENDING) self.change_sort(self.scol,self.sdir==GTK.SORT_DESCENDING)
self.set_sort_arrow(self.scol,self.sdir) self.set_sort_arrow(self.scol,self.sdir)
self.db.set_iprefix(GrampsCfg.iprefix)
self.db.set_oprefix(GrampsCfg.oprefix)
self.db.set_fprefix(GrampsCfg.fprefix)
self.db.set_sprefix(GrampsCfg.sprefix)
self.db.set_pprefix(GrampsCfg.pprefix)
if arg != None: if arg != None:
if string.upper(arg[-3:]) == "GED": if string.upper(arg[-3:]) == "GED":
self.read_gedcom(arg) self.read_gedcom(arg)
@ -624,6 +623,11 @@ class Gramps:
self.db = GrampsZODB() self.db = GrampsZODB()
else: else:
self.db = GrampsXML() self.db = GrampsXML()
self.db.set_iprefix(GrampsCfg.iprefix)
self.db.set_oprefix(GrampsCfg.oprefix)
self.db.set_fprefix(GrampsCfg.fprefix)
self.db.set_sprefix(GrampsCfg.sprefix)
self.db.set_pprefix(GrampsCfg.pprefix)
self.place_view.change_db(self.db) self.place_view.change_db(self.db)
self.source_view.change_db(self.db) self.source_view.change_db(self.db)

View File

@ -49,14 +49,8 @@ def runTool(database,active_person,callback):
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class CheckIntegrity: class CheckIntegrity:
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def __init__(self,db): def __init__(self,db):
self.db = db self.db = db
self.bad_photo = [] self.bad_photo = []
@ -65,11 +59,6 @@ class CheckIntegrity:
self.broken_parent_links = [] self.broken_parent_links = []
self.fam_rel = [] self.fam_rel = []
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def check_for_broken_family_links(self): def check_for_broken_family_links(self):
self.broken_links = [] self.broken_links = []
family_list = self.db.getFamilyMap().values()[:] family_list = self.db.getFamilyMap().values()[:]
@ -96,23 +85,12 @@ class CheckIntegrity:
Utils.modified() Utils.modified()
self.broken_links.append((child,family)) self.broken_links.append((child,family))
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def cleanup_missing_photos(self): def cleanup_missing_photos(self):
for photo in self.db.getObjectMap().values(): for photo in self.db.getObjectMap().values():
if not os.path.isfile(photo.getPath()): if not os.path.isfile(photo.getPath()):
self.bad_photo.append(photo) self.bad_photo.append(photo)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def cleanup_empty_families(self,automatic): def cleanup_empty_families(self,automatic):
family_list = self.db.getFamilyMap().values()[:] family_list = self.db.getFamilyMap().values()[:]
for family in family_list: for family in family_list:
if family.getFather() == None and family.getMother() == None: if family.getFather() == None and family.getMother() == None:
@ -125,13 +103,7 @@ class CheckIntegrity:
child.removeAltFamily(family) child.removeAltFamily(family)
self.db.deleteFamily(family) self.db.deleteFamily(family)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def check_parent_relationships(self): def check_parent_relationships(self):
for family in self.db.getFamilyMap().values(): for family in self.db.getFamilyMap().values():
father = family.getFather() father = family.getFather()
mother = family.getMother() mother = family.getMother()
@ -156,11 +128,6 @@ class CheckIntegrity:
family.setFather(mother) family.setFather(mother)
family.setMother(father) family.setMother(father)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def report(self): def report(self):
photos = len(self.bad_photo) photos = len(self.bad_photo)
efam = len(self.empty_family) efam = len(self.empty_family)

View File

@ -31,27 +31,37 @@ _ = intl.gettext
_findint = re.compile('^[^\d]*(\d+)[^\d]*') _findint = re.compile('^[^\d]*(\d+)[^\d]*')
def runTool(database,active_person,callback): def runTool(db,active_person,callback):
"""Changed person, family, object, source, and place ids""" """Changed person, family, object, source, and place ids"""
ReorderIds(db,callback)
make_new_ids(database.getPersonMap(),database.iprefix) class ReorderIds:
make_new_ids(database.getFamilyMap(),database.fprefix)
make_new_ids(database.getObjectMap(),database.oprefix) def __init__(self,db,callback):
make_new_ids(database.getSourceMap(),database.sprefix) self.db = db
make_new_ids(database.getPlaceMap(),database.pprefix)
self.reorder(db.getPersonMap(),db.iprefix,db.buildPersonDisplay)
self.reorder(db.getFamilyMap(),db.fprefix,None)
self.reorder(db.getObjectMap(),db.oprefix,None)
self.reorder(db.getSourceMap(),db.sprefix,db.buildSourceDisplay)
self.reorder(db.getPlaceMap(),db.pprefix,db.buildPlaceDisplay)
Utils.modified() Utils.modified()
callback(1) callback(1)
def reorder(self,data_map,prefix,update):
def make_new_ids(data_map,prefix):
"""Try to extract the old integer out of the id, and reuse it """Try to extract the old integer out of the id, and reuse it
if possible. Otherwise, blindly renumber those that can't.""" if possible. Otherwise, blindly renumber those that can't."""
dups = [] dups = []
newids = [] newids = []
key_list = []
# search all ids in the map # search all ids in the map
for id in data_map.keys():
for x in data_map.keys():
key_list.append(x)
for id in key_list:
# attempt to extract integer, if we can't, treat it as a # attempt to extract integer, if we can't, treat it as a
# duplicate # duplicate
@ -74,6 +84,8 @@ def make_new_ids(data_map,prefix):
data.setId(newid) data.setId(newid)
data_map[newid] = data data_map[newid] = data
del data_map[id] del data_map[id]
if update:
update(newid,id)
else: else:
dups.append(id) dups.append(id)
@ -91,6 +103,8 @@ def make_new_ids(data_map,prefix):
data = data_map[id] data = data_map[id]
data.setId(newid) data.setId(newid)
data_map[newid] = data data_map[newid] = data
if update:
update(newid,id)
del data_map[id] del data_map[id]
#------------------------------------------------------------------------- #-------------------------------------------------------------------------