* src/ReadXML.py: prevent duplicate place names on import
* src/ReadGedcom.py: prevent duplicate place names on import svn: r4879
This commit is contained in:
parent
ccfd1e57b4
commit
53cc3c990d
@ -1,3 +1,7 @@
|
||||
2005-06-26 Don Allingham <don@gramps-project.org>
|
||||
* src/ReadXML.py: prevent duplicate place names on import
|
||||
* src/ReadGedcom.py: prevent duplicate place names on import
|
||||
|
||||
2005-06-26 Julio Sanchez <jsanchez@users.sourceforge.net>
|
||||
* src/GenericFilter.py: Fix uninitialized ancestor_cache in
|
||||
HasCommonAncestorWithFilterMatch, fix or-ing filters
|
||||
|
@ -32,6 +32,7 @@ import re
|
||||
import string
|
||||
import const
|
||||
import time
|
||||
import sets
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -279,6 +280,15 @@ class GedcomParser:
|
||||
self.lid2id = {}
|
||||
self.fid2id = {}
|
||||
|
||||
self.place_names = sets.Set()
|
||||
cursor = dbase.get_place_cursor()
|
||||
data = cursor.next()
|
||||
while data:
|
||||
(handle,val) = data
|
||||
self.place_names.add(val[2])
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
|
||||
self.f = open(filename,"rU")
|
||||
self.filename = filename
|
||||
self.index = 0
|
||||
@ -742,16 +752,35 @@ class GedcomParser:
|
||||
self.sid2id[gramps_id] = intid
|
||||
return source
|
||||
|
||||
def find_or_create_place(self,gramps_id):
|
||||
def find_or_create_place(self,title):
|
||||
place = RelLib.Place()
|
||||
intid = self.lid2id.get(gramps_id)
|
||||
|
||||
# check to see if we've encountered this name before
|
||||
# if we haven't we need to get a new GRAMPS ID
|
||||
intid = self.lid2id.get(title)
|
||||
if intid == None:
|
||||
new_id = self.db.find_next_place_gramps_id()
|
||||
else:
|
||||
new_id = None
|
||||
|
||||
# check to see if the name already existed in the database
|
||||
# if it does, create a new name by appending the GRAMPS ID.
|
||||
# generate a GRAMPS ID if needed
|
||||
|
||||
if title in self.place_names:
|
||||
if not new_id:
|
||||
new_id = self.db.find_next_place_gramps_id()
|
||||
pname = "%s [%s]" % (title,new_id)
|
||||
else:
|
||||
pname = title
|
||||
|
||||
if self.db.place_map.has_key(intid):
|
||||
place.unserialize(self.db.place_map.get(intid))
|
||||
else:
|
||||
intid = create_id()
|
||||
place.set_handle(intid)
|
||||
place.set_title(gramps_id)
|
||||
place.set_gramps_id(self.db.find_next_place_gramps_id())
|
||||
place.set_title(pname)
|
||||
place.set_gramps_id(new_id)
|
||||
self.db.add_place(place,self.trans)
|
||||
self.lid2id[gramps_id] = intid
|
||||
return place
|
||||
|
@ -26,6 +26,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import sets
|
||||
import gtk
|
||||
import shutil
|
||||
from xml.parsers.expat import ExpatError, ParserCreate
|
||||
@ -172,87 +173,6 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
|
||||
except (IOError,OSError),msg:
|
||||
ErrorDialog(_('Could not copy file'),str(msg))
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# def remove_clicked():
|
||||
# # File is lost => remove all references and the object itself
|
||||
# mobj = database.find_object_from_handle(NewMediaID)
|
||||
# for fid in database.get_family_handles():
|
||||
# p = database.get_family_from_handle(fid)
|
||||
# nl = p.get_media_list()
|
||||
# for o in nl:
|
||||
# if o.get_reference() == mobj:
|
||||
# nl.remove(o)
|
||||
# p.set_media_list(nl)
|
||||
# for key in database.get_person_handles(sort_handles=False):
|
||||
# p = database.find_person_from_handle(key)
|
||||
# nl = p.get_media_list()
|
||||
# for o in nl:
|
||||
# if o.get_reference_handle() == mobj.get_handle():
|
||||
# nl.remove(o)
|
||||
# p.set_media_list(nl)
|
||||
# for key in database.get_source_handles():
|
||||
# p = database.find_source_from_handle(key)
|
||||
# nl = p.get_media_list()
|
||||
# for o in nl:
|
||||
# if o.get_reference_handle() == mobj.get_handle():
|
||||
# nl.remove(o)
|
||||
# p.set_media_list(nl)
|
||||
# for key in database.get_place_handles():
|
||||
# p = database.find_place_from_handle(key)
|
||||
# nl = p.get_media_list()
|
||||
# for o in nl:
|
||||
# if o.get_reference() == mobj:
|
||||
# nl.remove(o)
|
||||
# p.set_media_list(nl)
|
||||
# database.remove_object(NewMediaID)
|
||||
|
||||
|
||||
# def leave_clicked():
|
||||
# # File is lost => do nothing, leave as is
|
||||
# pass
|
||||
|
||||
# def select_clicked():
|
||||
# # File is lost => select a file to replace the lost one
|
||||
# def fs_close_window(obj):
|
||||
# pass
|
||||
|
||||
# def fs_ok_clicked(obj):
|
||||
# name = fs_top.get_filename()
|
||||
# if os.path.isfile(name):
|
||||
# shutil.copyfile(name,newfile)
|
||||
# try:
|
||||
# shutil.copystat(name,newfile)
|
||||
# except:
|
||||
# pass
|
||||
|
||||
# choose = gtk.FileChooserDialog('Select file',
|
||||
# None,
|
||||
# gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
# (gtk.STOCK_CANCEL,
|
||||
# gtk.RESPONSE_CANCEL,
|
||||
# gtk.STOCK_OPEN,
|
||||
# gtk.RESPONSE_OK))
|
||||
|
||||
# filter = gtk.FileFilter()
|
||||
# filter.set_name(_('All files'))
|
||||
# filter.add_pattern('*')
|
||||
# choose.add_filter(filter)
|
||||
|
||||
# response = choose.run()
|
||||
# if response == gtk.RESPONSE_OK:
|
||||
# name = fs_top.get_filename()
|
||||
# if os.path.isfile(name):
|
||||
# shutil.copyfile(name,newfile)
|
||||
# try:
|
||||
# shutil.copystat(name,newfile)
|
||||
# except:
|
||||
# pass
|
||||
# choose.destroy()
|
||||
|
||||
# del parser
|
||||
# return 1
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Remove extraneous spaces
|
||||
@ -287,6 +207,15 @@ class GrampsParser:
|
||||
self.change = change
|
||||
self.dp = DateHandler.parser
|
||||
|
||||
self.place_names = sets.Set()
|
||||
cursor = database.get_place_cursor()
|
||||
data = cursor.next()
|
||||
while data:
|
||||
(handle,val) = data
|
||||
self.place_names.add(val[2])
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
|
||||
self.ord = None
|
||||
self.objref = None
|
||||
self.object = None
|
||||
@ -615,6 +544,7 @@ class GrampsParser:
|
||||
title = attrs['title']
|
||||
if title == "":
|
||||
title = attrs['id']
|
||||
|
||||
self.placeobj.set_title(title)
|
||||
self.locations = 0
|
||||
if self.callback != None and self.count % self.increment == 0:
|
||||
@ -1156,6 +1086,11 @@ class GrampsParser:
|
||||
if self.placeobj.get_title() == "":
|
||||
loc = self.placeobj.get_main_location()
|
||||
self.placeobj.set_title(build_place_title(loc))
|
||||
|
||||
title = self.placeobj.get_title()
|
||||
if title in self.place_names:
|
||||
self.placeobj.set_title(title + " [%s]" % self.placeobj.get_gramps_id())
|
||||
|
||||
self.db.commit_place(self.placeobj,self.trans,self.change)
|
||||
self.placeobj = None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user