gedcom import export for new name structure

svn: r16022
This commit is contained in:
Benny Malengier 2010-10-22 14:20:01 +00:00
parent 920535e3f6
commit ee91b33a43
5 changed files with 58 additions and 66 deletions

View File

@ -456,39 +456,3 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, SourceBase, NoteBase,
return '%s /%s/' % (firstname, surname)
else:
return '%s /%s/ %s' % (firstname, surname, suffix)
##
## #DEPRECATED METHODS
##
##
## def get_surname_prefix(self):
## """
## Return the prefix (or article) of a surname.
##
## The prefix is not used for sorting or grouping.
## """
## return self.prefix
##
## def set_surname_prefix(self, val):
## """
## Set the prefix (or article) of a surname.
##
## Examples of articles would be 'de' or 'van'.
## """
## self.prefix = val
##
## def get_patronymic(self):
## """Return the patronymic name for the Name instance."""
## return self.patronymic
##
## def set_patronymic(self, name):
## """Set the patronymic name for the Name instance."""
## self.patronymic = name
##
## def get_surname(self):
## """Return the surname (or last name) for the Name instance."""
## return self.surname
##
## def set_surname(self, name):
## """Set the surname (or last name) for the Name instance."""
## self.surname = name

View File

@ -185,7 +185,7 @@ class Surname(SecondaryObject):
"""Return if this surname is the primary surname"""
return self.primary
def set_primary(self, primary):
def set_primary(self, primary=True):
"""Set if this surname is the primary surname.replace
Use :class:`~gen.lib.surname.SurnameBase` to set the primary surname
via :method:`~gen.lib.surname.SurnameBase.set_primary_surname`

View File

@ -498,13 +498,11 @@ class GedcomWriter(UpdateCallback):
"""
Write the names associated with the person to the current level.
Since nicknames are now separate from the name structure, we search
the attribute list to see if we can find a nickname. Because we do
not know the mappings, we just take the first nickname we find, and
add it to the primary name.
All other names are assumed to not have a nickname, even if other
nicknames exist in the attribute list.
Since nicknames in version < 3.3 are separate from the name structure,
we search the attribute list to see if we can find a nickname.
Because we do not know the mappings, we just take the first nickname
we find, and add it to the primary name.
If a nickname is present in the name structure, it has precedence
"""
nicknames = [ attr.get_value() for attr in person.get_attribute_list()
@ -1187,7 +1185,7 @@ class GedcomWriter(UpdateCallback):
elif date.get_text():
self.__writeln(level, 'DATE', date.get_text())
def __person_name(self, name, nick):
def __person_name(self, name, attr_nick):
"""
n NAME <NAME_PERSONAL> {1:1}
+1 NPFX <NAME_PIECE_PREFIX> {0:1}
@ -1202,13 +1200,21 @@ class GedcomWriter(UpdateCallback):
gedcom_name = name.get_gedcom_name()
firstname = name.get_first_name().strip()
patron = name.get_patronymic().strip()
if patron:
firstname = "%s %s" % (firstname, patron)
surname = name.get_surname().replace('/', '?')
surprefix = name.get_surname_prefix().replace('/', '?')
surns = []
surprefs = []
for surn in name.get_surname_list():
surns.append(surn.get_surname().replace('/', '?'))
if surn.get_connector():
#we store connector with the surname
surns[-1] = surns[-1] + ' ' + surn.get_connector()
surprefs.append(surn.get_prefix().replace('/', '?'))
surname = ', '.join(surns)
surprefix = ', '.join(surprefs)
suffix = name.get_suffix()
title = name.get_title()
nick = name.get_nick_name()
if nick.strip() == '':
nick = attr_nick
self.__writeln(1, 'NAME', gedcom_name)
@ -1218,7 +1224,6 @@ class GedcomWriter(UpdateCallback):
self.__writeln(2, 'SPFX', surprefix)
if surname:
self.__writeln(2, 'SURN', surname)
if name.get_suffix():
self.__writeln(2, 'NSFX', suffix)
if name.get_title():

View File

@ -1672,16 +1672,25 @@ class GedcomParser(UpdateCallback):
match = SURNAME_RE.match(text)
if match:
#/surname/ extra, we assume extra is given name
names = match.groups()
name.set_first_name(names[1].strip())
name.set_surname(names[0].strip())
surn = gen.lib.Surname()
surn.set_surname(names[0].strip())
surn.set_primary()
name.set_surname_list([surn])
else:
try:
names = NAME_RE.match(text).groups()
# given /surname/ extra, we assume extra is suffix
name.set_first_name(names[0].strip())
name.set_surname(names[2].strip())
surn = gen.lib.Surname()
surn.set_surname(names[2].strip())
surn.set_primary()
name.set_surname_list([surn])
name.set_suffix(names[4].strip())
except:
# something strange, set as first name
name.set_first_name(text.strip())
return name
@ -3163,7 +3172,13 @@ class GedcomParser(UpdateCallback):
@param state: The current state
@type state: CurrentState
"""
state.name.set_surname_prefix(line.data.strip())
if state.name.get_surname_list():
state.name.get_surname_list()[0].set_prefix(line.data.strip())
else:
surn = gen.lib.Surname()
surn.set_prefix(line.data.strip())
surn.set_primary()
state.name.set_surname_list([surn])
self.__skip_subordinate_levels(state.level+1)
def __name_surn(self, line, state):
@ -3173,7 +3188,13 @@ class GedcomParser(UpdateCallback):
@param state: The current state
@type state: CurrentState
"""
state.name.set_surname(line.data.strip())
if state.name.get_surname_list():
state.name.get_surname_list()[0].set_surname(line.data.strip())
else:
surn = gen.lib.Surname()
surn.set_surname(line.data.strip())
surn.set_primary()
state.name.set_surname_list([surn])
self.__skip_subordinate_levels(state.level+1)
def __name_marnm(self, line, state):
@ -3187,7 +3208,10 @@ class GedcomParser(UpdateCallback):
data = text.split()
if len(data) == 1:
name = gen.lib.Name(state.person.primary_name)
name.set_surname(data[0].strip())
surn = gen.lib.Surname()
surn.set_surname(data[0].strip())
surn.set_primary()
name.set_surname_list([surn])
name.set_type(gen.lib.NameType.MARRIED)
state.person.add_alternate_name(name)
elif len(data) > 1:
@ -3202,8 +3226,12 @@ class GedcomParser(UpdateCallback):
@param state: The current state
@type state: CurrentState
"""
if state.name.get_suffix() == "":
if state.name.get_suffix() == "" or state.name.get_suffix() == line.data:
#suffix might be set before when parsing name string
state.name.set_suffix(line.data)
else:
#previously set suffix different, to not loose information, append
state.name.set_suffix(state.name.get_suffix() + ' ' + line.data)
self.__skip_subordinate_levels(state.level+1)
def __name_nick(self, line, state):
@ -3213,10 +3241,7 @@ class GedcomParser(UpdateCallback):
@param state: The current state
@type state: CurrentState
"""
attr = gen.lib.Attribute()
attr.set_type(gen.lib.AttributeType.NICKNAME)
attr.set_value(line.data)
state.person.add_attribute(attr)
state.name.set_nick_name(line.data.strip())
self.__skip_subordinate_levels(state.level+1)
def __name_aka(self, line, state):

View File

@ -77,6 +77,7 @@ prefix_list = [
"um", "una", "uno", "der", "ter", "te", "die",
]
connector_list = ['e', 'y', ]
_title_re = re.compile(r"^ ([A-Za-z][A-Za-z]+\.) \s+ (.+) $", re.VERBOSE)
_nick_re = re.compile(r"(.+) \s* [(\"] (.+) [)\"]", re.VERBOSE)
@ -308,10 +309,7 @@ class PatchNames(tool.BatchTool, ManagedWindow.ManagedWindow):
name = p.get_primary_name()
name.set_first_name(grp[1].strip())
nick_name = grp[2].strip()
attr = gen.lib.Attribute()
attr.set_type(gen.lib.AttributeType.NICKNAME)
attr.set_value(nick_name)
p.add_attribute(attr)
name.set_nick_name(nick_name)
self.db.commit_person(p, trans)
for grp in self.title_list: