2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-03-25 05:54:37 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-11-07 21:59:27 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Change id IDs of all the elements in the database to conform to the
|
|
|
|
scheme specified in the database's prefix ids
|
|
|
|
"""
|
|
|
|
|
2005-03-25 05:54:37 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import re
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-03-25 05:54:37 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import Utils
|
|
|
|
from QuestionDialog import WarningDialog
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
_findint = re.compile('^[^\d]*(\d+)[^\d]*')
|
|
|
|
|
2004-05-17 06:36:09 +05:30
|
|
|
def runTool(db,active_person,callback,parent):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Changed person, family, object, source, and place ids"""
|
2005-03-25 05:54:37 +05:30
|
|
|
#FIXME -- Remove when the tool is back from the dead
|
|
|
|
WarningDialog(_('Tool currently unavailable'),
|
|
|
|
_('This tool has not yet been brought up to date '
|
|
|
|
'after transition to the database, sorry.'),parent.topWindow)
|
|
|
|
return
|
|
|
|
|
|
|
|
#FIXME
|
2002-10-20 19:55:16 +05:30
|
|
|
try:
|
|
|
|
ReorderIds(db,callback)
|
|
|
|
except:
|
|
|
|
import DisplayTrace
|
|
|
|
DisplayTrace.DisplayTrace()
|
|
|
|
|
2005-03-25 05:54:37 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Actual tool
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class ReorderIds:
|
|
|
|
|
|
|
|
def __init__(self,db,callback):
|
2003-06-16 10:27:25 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = db
|
|
|
|
|
2004-12-20 04:25:41 +05:30
|
|
|
self.reorder_person()
|
2004-07-28 07:59:07 +05:30
|
|
|
self.reorder(db.get_family_handle_map(),db.fprefix,None)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.reorder(db.get_object_map(),db.oprefix,None)
|
|
|
|
self.reorder(db.get_source_map(),db.sprefix,db.build_source_display)
|
2004-07-28 07:59:07 +05:30
|
|
|
self.reorder(db.get_place_handle_map(),db.pprefix,db.build_place_display)
|
2002-10-20 19:55:16 +05:30
|
|
|
callback(1)
|
2003-06-16 10:27:25 +05:30
|
|
|
|
2005-03-25 05:54:37 +05:30
|
|
|
def reorder_person(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
dups = []
|
2003-07-06 09:22:38 +05:30
|
|
|
newids = {}
|
2002-10-20 19:55:16 +05:30
|
|
|
key_list = []
|
|
|
|
|
|
|
|
# search all ids in the map
|
|
|
|
|
2004-12-20 04:25:41 +05:30
|
|
|
cursor = self.db.get_person_cursor()
|
|
|
|
data = cursor.first()
|
|
|
|
while data:
|
|
|
|
(handle,sdata) = data
|
|
|
|
|
|
|
|
gramps_id = sdata[1]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
# attempt to extract integer, if we can't, treat it as a
|
|
|
|
# duplicate
|
|
|
|
|
2004-12-20 04:25:41 +05:30
|
|
|
match = _findint.match(gramps_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
if match:
|
2004-10-26 08:50:38 +05:30
|
|
|
# get the integer, build the new handle. Make sure it
|
2002-10-20 19:55:16 +05:30
|
|
|
# hasn't already been chosen. If it has, put this
|
2004-10-26 08:50:38 +05:30
|
|
|
# in the duplicate handle list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-06-30 08:37:24 +05:30
|
|
|
try:
|
|
|
|
index = match.groups()[0]
|
2004-12-20 04:25:41 +05:30
|
|
|
newgramps_id = prefix % int(index)
|
|
|
|
if newgramps_id == gramps_id:
|
|
|
|
newids[newgramps_id] = gramps_id
|
2003-06-30 08:37:24 +05:30
|
|
|
continue
|
2004-12-20 04:25:41 +05:30
|
|
|
elif data_map.has_key(newgramps_id):
|
2004-10-26 08:50:38 +05:30
|
|
|
dups.append(handle)
|
2003-06-30 08:37:24 +05:30
|
|
|
else:
|
2004-12-20 04:25:41 +05:30
|
|
|
data = data_map[gramps_id]
|
|
|
|
data_map[newgramps_id] = data
|
|
|
|
newids[newgramps_id] = gramps_id
|
|
|
|
data.set_gramps_id(newgramps_id)
|
|
|
|
del data_map[gramps_id]
|
2003-06-30 08:37:24 +05:30
|
|
|
if update:
|
2004-12-20 04:25:41 +05:30
|
|
|
update(newgramps_id,gramps_id)
|
2003-06-30 08:37:24 +05:30
|
|
|
except:
|
2004-10-26 08:50:38 +05:30
|
|
|
dups.append(handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
dups.append(handle)
|
2004-12-20 04:25:41 +05:30
|
|
|
|
|
|
|
data = cursor.next()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
# go through the duplicates, looking for the first availble
|
2004-10-26 08:50:38 +05:30
|
|
|
# handle that matches the new scheme.
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
index = 0
|
2004-12-20 04:25:41 +05:30
|
|
|
for gramps_id in dups:
|
2002-10-20 19:55:16 +05:30
|
|
|
while 1:
|
2004-12-20 04:25:41 +05:30
|
|
|
newgramps_id = prefix % index
|
|
|
|
if not newids.has_key(newgramps_id):
|
2002-10-20 19:55:16 +05:30
|
|
|
break
|
|
|
|
index = index + 1
|
2004-12-20 04:25:41 +05:30
|
|
|
newids[newgramps_id] = newgramps_id
|
|
|
|
data = data_map[gramps_id]
|
|
|
|
data.set_gramps_id(newgramps_id)
|
|
|
|
data_map[newgramps_id] = data
|
2002-10-20 19:55:16 +05:30
|
|
|
if update:
|
2004-12-20 04:25:41 +05:30
|
|
|
update(newgramps_id,gramps_id)
|
|
|
|
del data_map[gramps_id]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-01-05 10:32:19 +05:30
|
|
|
from PluginMgr import register_tool
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
register_tool(
|
|
|
|
runTool,
|
|
|
|
_("Reorder gramps IDs"),
|
|
|
|
category=_("Database Processing"),
|
|
|
|
description=_("Reorders the gramps IDs according to gramps' default rules.")
|
|
|
|
)
|
|
|
|
|