Fix reordering task for ZODB support

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

View File

@ -123,6 +123,11 @@ class Gramps:
# a GrampsXML or GrampsZODB
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)
@ -135,12 +140,6 @@ class Gramps:
self.change_sort(self.scol,self.sdir==GTK.SORT_DESCENDING)
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 string.upper(arg[-3:]) == "GED":
@ -624,6 +623,11 @@ class Gramps:
self.db = GrampsZODB()
else:
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.source_view.change_db(self.db)

View File

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

View File

@ -31,67 +31,81 @@ _ = intl.gettext
_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"""
make_new_ids(database.getPersonMap(),database.iprefix)
make_new_ids(database.getFamilyMap(),database.fprefix)
make_new_ids(database.getObjectMap(),database.oprefix)
make_new_ids(database.getSourceMap(),database.sprefix)
make_new_ids(database.getPlaceMap(),database.pprefix)
Utils.modified()
callback(1)
ReorderIds(db,callback)
class ReorderIds:
def make_new_ids(data_map,prefix):
"""Try to extract the old integer out of the id, and reuse it
if possible. Otherwise, blindly renumber those that can't."""
def __init__(self,db,callback):
self.db = db
dups = []
newids = []
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()
callback(1)
# search all ids in the map
for id in data_map.keys():
# attempt to extract integer, if we can't, treat it as a
# duplicate
def reorder(self,data_map,prefix,update):
"""Try to extract the old integer out of the id, and reuse it
if possible. Otherwise, blindly renumber those that can't."""
match = _findint.match(id)
if match:
# get the integer, build the new id. Make sure it
# hasn't already been chosen. If it has, put this
# in the duplicate id list
dups = []
newids = []
key_list = []
# search all ids in the map
for x in data_map.keys():
key_list.append(x)
for id in key_list:
index = match.groups()[0]
newid = prefix % int(index)
if newid == id:
continue
elif data_map.has_key(newid):
dups.append(id)
# attempt to extract integer, if we can't, treat it as a
# duplicate
match = _findint.match(id)
if match:
# get the integer, build the new id. Make sure it
# hasn't already been chosen. If it has, put this
# in the duplicate id list
index = match.groups()[0]
newid = prefix % int(index)
if newid == id:
continue
elif data_map.has_key(newid):
dups.append(id)
else:
newids.append(id)
data = data_map[id]
data.setId(newid)
data_map[newid] = data
del data_map[id]
if update:
update(newid,id)
else:
newids.append(id)
data = data_map[id]
data.setId(newid)
data_map[newid] = data
del data_map[id]
else:
dups.append(id)
dups.append(id)
# go through the duplicates, looking for the first availble
# id that matches the new scheme.
# go through the duplicates, looking for the first availble
# id that matches the new scheme.
index = 0
for id in dups:
while 1:
newid = prefix % index
if newid not in newids:
break
index = index + 1
newids.append(newid)
data = data_map[id]
data.setId(newid)
data_map[newid] = data
del data_map[id]
index = 0
for id in dups:
while 1:
newid = prefix % index
if newid not in newids:
break
index = index + 1
newids.append(newid)
data = data_map[id]
data.setId(newid)
data_map[newid] = data
if update:
update(newid,id)
del data_map[id]
#-------------------------------------------------------------------------
#