Update
svn: r7086
This commit is contained in:
parent
002d180d88
commit
03e50b3e3a
@ -1,10 +1,12 @@
|
|||||||
2006-07-27 Alex Roitman <shura@gramps-project.org>
|
2006-07-27 Alex Roitman <shura@gramps-project.org>
|
||||||
|
* src/GrampsDb/_ReadGrdb.py: Re-map name formats on import.
|
||||||
* src/GrampsDb/_GrampsBSDDB.py (_load_metadata): Upgrade custom
|
* src/GrampsDb/_GrampsBSDDB.py (_load_metadata): Upgrade custom
|
||||||
name formats.
|
name formats.
|
||||||
* src/GrampsDb/_ReadXML.py (start_format): Attempt parsing the
|
* src/GrampsDb/_ReadXML.py (start_format): Attempt parsing the
|
||||||
active state for the custom name format.
|
active state for the custom name format; re-map format numbers on
|
||||||
|
import.
|
||||||
* src/GrampsDb/_WriteXML.py (write_name_formats): Write 4-tuple
|
* src/GrampsDb/_WriteXML.py (write_name_formats): Write 4-tuple
|
||||||
custom name formats;
|
custom name formats; Write formats in the beginning of data;
|
||||||
(_xml_version): Output as version 1.1.1.
|
(_xml_version): Output as version 1.1.1.
|
||||||
* data/grampsxml.rng: Update XML description for 1.1.1.
|
* data/grampsxml.rng: Update XML description for 1.1.1.
|
||||||
* data/grampsxml.dtd: Update XML description for 1.1.1.
|
* data/grampsxml.dtd: Update XML description for 1.1.1.
|
||||||
|
@ -51,8 +51,8 @@ DATABASE
|
|||||||
bookmarks
|
bookmarks
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!ELEMENT database (header, events?, people?, families?, sources?, places?,
|
<!ELEMENT database (header, name-formats?, events?, people?, families?,
|
||||||
objects?, repositories?, bookmark?, name-formats?)>
|
sources?, places?, objects?, repositories?, bookmark?)>
|
||||||
<!ATTLIST database xmlns CDATA #FIXED "http://gramps-project.org/xml/1.1.1/">
|
<!ATTLIST database xmlns CDATA #FIXED "http://gramps-project.org/xml/1.1.1/">
|
||||||
|
|
||||||
<!-- ************************************************************
|
<!-- ************************************************************
|
||||||
|
@ -46,6 +46,12 @@
|
|||||||
</element></optional>
|
</element></optional>
|
||||||
</element>
|
</element>
|
||||||
|
|
||||||
|
<optional><element name="name-formats">
|
||||||
|
<zeroOrMore><element name="format">
|
||||||
|
<ref name="format-content"/>
|
||||||
|
</element></zeroOrMore>
|
||||||
|
</element></optional>
|
||||||
|
|
||||||
<optional><element name="events">
|
<optional><element name="events">
|
||||||
<zeroOrMore><element name="event">
|
<zeroOrMore><element name="event">
|
||||||
<ref name="event-content"/>
|
<ref name="event-content"/>
|
||||||
@ -98,11 +104,6 @@
|
|||||||
</element></zeroOrMore>
|
</element></zeroOrMore>
|
||||||
</element></optional>
|
</element></optional>
|
||||||
|
|
||||||
<optional><element name="name-formats">
|
|
||||||
<zeroOrMore><element name="format">
|
|
||||||
<ref name="format-content"/>
|
|
||||||
</element></zeroOrMore>
|
|
||||||
</element></optional>
|
|
||||||
</element></start>
|
</element></start>
|
||||||
|
|
||||||
<define name="researcher-content">
|
<define name="researcher-content">
|
||||||
|
@ -41,6 +41,7 @@ from _GrampsBSDDB import GrampsBSDDB
|
|||||||
from QuestionDialog import ErrorDialog
|
from QuestionDialog import ErrorDialog
|
||||||
from Errors import HandleError
|
from Errors import HandleError
|
||||||
from BasicUtils import UpdateCallback
|
from BasicUtils import UpdateCallback
|
||||||
|
import NameDisplay
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -76,6 +77,15 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
|
|||||||
"by this version of GRAMPS."))
|
"by this version of GRAMPS."))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# If other_database contains its custom name formats,
|
||||||
|
# we need to do tricks to remap the format numbers
|
||||||
|
if len(other_database.name_formats) > 0:
|
||||||
|
formats_map = remap_name_formats(database,other_database)
|
||||||
|
NameDisplay.displayer.register_custom_formats(database.name_formats)
|
||||||
|
get_person = make_peron_name_remapper(other_database,formats_map)
|
||||||
|
else:
|
||||||
|
# No remapping necessary, proceed as usual
|
||||||
|
get_person = other_database.get_person_from_handle
|
||||||
|
|
||||||
# Prepare table and method definitions
|
# Prepare table and method definitions
|
||||||
tables = {
|
tables = {
|
||||||
@ -84,7 +94,7 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
|
|||||||
'add_obj' : database.add_person,
|
'add_obj' : database.add_person,
|
||||||
'find_next_gramps_id' :database.find_next_person_gramps_id,
|
'find_next_gramps_id' :database.find_next_person_gramps_id,
|
||||||
'other_get_from_handle':
|
'other_get_from_handle':
|
||||||
other_database.get_person_from_handle,
|
get_person,
|
||||||
'other_table': other_database.person_map,
|
'other_table': other_database.person_map,
|
||||||
},
|
},
|
||||||
'Family' : {'table' : database.family_map,
|
'Family' : {'table' : database.family_map,
|
||||||
@ -216,3 +226,37 @@ def import_table(id_table,add_obj,find_next_gramps_id,
|
|||||||
obj.gramps_id = gramps_id
|
obj.gramps_id = gramps_id
|
||||||
add_obj(obj,trans)
|
add_obj(obj,trans)
|
||||||
uc.update()
|
uc.update()
|
||||||
|
|
||||||
|
def remap_name_formats(database,other_database):
|
||||||
|
formats_map = {}
|
||||||
|
taken_numbers = [num for (num,name,fmt_str,active)
|
||||||
|
in database.name_formats]
|
||||||
|
for (number,name,fmt_str,act) in other_database.name_formats:
|
||||||
|
if number in taken_numbers:
|
||||||
|
new_number = -1
|
||||||
|
while new_number in taken_numbers:
|
||||||
|
new_number -= 1
|
||||||
|
taken_numbers.append(new_number)
|
||||||
|
formats_map[number] = new_number
|
||||||
|
else:
|
||||||
|
new_number = number
|
||||||
|
database.name_formats.append((new_number,name,fmt_str,act))
|
||||||
|
return formats_map
|
||||||
|
|
||||||
|
def remap_name(person,formats_map):
|
||||||
|
for name in [person.primary_name] + person.alternate_names:
|
||||||
|
try:
|
||||||
|
name.sort_as = formats_map[name.sort_as]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
name.display_as = formats_map[name.display_as]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def make_peron_name_remapper(other_database,formats_map):
|
||||||
|
def new_get_person(handle):
|
||||||
|
person = other_database.get_person_from_handle(handle)
|
||||||
|
remap_name(person,formats_map)
|
||||||
|
return person
|
||||||
|
return new_get_person
|
||||||
|
@ -330,6 +330,12 @@ class GrampsParser(UpdateCallback):
|
|||||||
self.lmap = {}
|
self.lmap = {}
|
||||||
self.media_file_map = {}
|
self.media_file_map = {}
|
||||||
|
|
||||||
|
# List of new name formats and a dict for remapping them
|
||||||
|
self.name_formats = []
|
||||||
|
self.name_formats_map = {}
|
||||||
|
self.taken_name_format_numbers = [num for (num,name,fmt_str,active)
|
||||||
|
in self.db.name_formats]
|
||||||
|
|
||||||
self.event = None
|
self.event = None
|
||||||
self.eventref = None
|
self.eventref = None
|
||||||
self.childref = None
|
self.childref = None
|
||||||
@ -611,6 +617,12 @@ class GrampsParser(UpdateCallback):
|
|||||||
self.p.CharacterDataHandler = self.characters
|
self.p.CharacterDataHandler = self.characters
|
||||||
self.p.ParseFile(file)
|
self.p.ParseFile(file)
|
||||||
|
|
||||||
|
if len(self.name_formats) > 0:
|
||||||
|
# add new name formats to the existing table
|
||||||
|
self.db.name_formats += self.name_formats
|
||||||
|
# Register new formats
|
||||||
|
NameDisplay.displayer.register_custom_formats(self.db.name_formats)
|
||||||
|
|
||||||
self.db.set_researcher(self.owner)
|
self.db.set_researcher(self.owner)
|
||||||
if self.home != None:
|
if self.home != None:
|
||||||
person = self.db.find_person_from_handle(self.home,self.trans)
|
person = self.db.find_person_from_handle(self.home,self.trans)
|
||||||
@ -845,7 +857,25 @@ class GrampsParser(UpdateCallback):
|
|||||||
name = attrs['name']
|
name = attrs['name']
|
||||||
fmt_str = attrs['fmt_str']
|
fmt_str = attrs['fmt_str']
|
||||||
active = bool(attrs.get('active',True))
|
active = bool(attrs.get('active',True))
|
||||||
self.db.name_formats.append((number,name,fmt_str,active))
|
|
||||||
|
if number in self.taken_name_format_numbers:
|
||||||
|
number = self.remap_name_format(number)
|
||||||
|
|
||||||
|
self.name_formats.append((number,name,fmt_str,active))
|
||||||
|
|
||||||
|
def remap_name_format(self,old_number):
|
||||||
|
if self.name_formats_map.has_key(old_number): # This should not happen
|
||||||
|
return self.name_formats_map[old_number]
|
||||||
|
# Find the lowest new number not taken yet:
|
||||||
|
new_number = -1
|
||||||
|
while new_number in self.taken_name_format_numbers:
|
||||||
|
new_number -= 1
|
||||||
|
# Add this to the taken list
|
||||||
|
self.taken_name_format_numbers.append(new_number)
|
||||||
|
# Set up the mapping entry
|
||||||
|
self.name_formats_map[old_number] = new_number
|
||||||
|
# Return new number
|
||||||
|
return new_number
|
||||||
|
|
||||||
def start_person(self,attrs):
|
def start_person(self,attrs):
|
||||||
self.update(self.p.CurrentLineNumber)
|
self.update(self.p.CurrentLineNumber)
|
||||||
@ -1025,8 +1055,19 @@ class GrampsParser(UpdateCallback):
|
|||||||
self.name.set_private = bool(attrs.get("priv"))
|
self.name.set_private = bool(attrs.get("priv"))
|
||||||
self.alt_name = bool(attrs.get("alt"))
|
self.alt_name = bool(attrs.get("alt"))
|
||||||
try:
|
try:
|
||||||
self.name.sort_as = int(attrs["sort"])
|
sort_as = int(attrs["sort"])
|
||||||
self.name.display_as = int(attrs["display"])
|
display_as = int(attrs["display"])
|
||||||
|
|
||||||
|
# check if these pointers need to be remapped
|
||||||
|
# and set the name attributes
|
||||||
|
if self.name_formats_map.has_key(sort_as):
|
||||||
|
self.name.sort_as = self.name_formats_map[sort_as]
|
||||||
|
else:
|
||||||
|
self.name.sort_as = sort_as
|
||||||
|
if self.name_formats_map.has_key(display_as):
|
||||||
|
self.name.sort_as = self.name_formats_map[display_as]
|
||||||
|
else:
|
||||||
|
self.name_display_as = display_as
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -230,6 +230,10 @@ class XmlWriter(UpdateCallback):
|
|||||||
self.g.write(" </researcher>\n")
|
self.g.write(" </researcher>\n")
|
||||||
self.g.write(" </header>\n")
|
self.g.write(" </header>\n")
|
||||||
|
|
||||||
|
# First write name formats: we need to know all formats
|
||||||
|
# by the time we get to person's names
|
||||||
|
self.write_name_formats()
|
||||||
|
|
||||||
if event_len > 0:
|
if event_len > 0:
|
||||||
self.g.write(" <events>\n")
|
self.g.write(" <events>\n")
|
||||||
sorted_keys = self.db.get_gramps_ids(EVENT_KEY)
|
sorted_keys = self.db.get_gramps_ids(EVENT_KEY)
|
||||||
@ -310,9 +314,6 @@ class XmlWriter(UpdateCallback):
|
|||||||
# Data is written, now write bookmarks.
|
# Data is written, now write bookmarks.
|
||||||
self.write_bookmarks()
|
self.write_bookmarks()
|
||||||
|
|
||||||
# Also write name formats
|
|
||||||
self.write_name_formats()
|
|
||||||
|
|
||||||
self.g.write("</database>\n")
|
self.g.write("</database>\n")
|
||||||
|
|
||||||
def write_bookmarks(self):
|
def write_bookmarks(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user