From 27c38018fa966e6664aca36b8cb547916a08067b Mon Sep 17 00:00:00 2001 From: Paul Culley Date: Wed, 7 Aug 2019 13:48:49 -0500 Subject: [PATCH] Fix GEDCOM importer to properly handle multiple surnames per 5.5.1 (#862) Fixes #11228 --- data/tests/exp_sample_ged.ged | 8 ++++---- data/tests/imp_sample.ged | 4 ++-- data/tests/imp_sample.gramps | 7 ++++--- gramps/plugins/export/exportgedcom.py | 8 +++++--- gramps/plugins/lib/libgedcom.py | 23 ++++++++++++++--------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/data/tests/exp_sample_ged.ged b/data/tests/exp_sample_ged.ged index 3d8e2b10e..ebbb780ac 100644 --- a/data/tests/exp_sample_ged.ged +++ b/data/tests/exp_sample_ged.ged @@ -2,8 +2,8 @@ 1 SOUR Gramps 2 VERS 5.0.2 2 NAME Gramps -1 DATE 5 MAR 2019 -2 TIME 09:11:15 +1 DATE 31 JUL 2019 +2 TIME 10:58:33 1 SUBM @SUBM@ 1 FILE C:\Users\prc\AppData\Roaming\gramps\temp\exp_sample_ged.ged 1 COPR Copyright (c) 2019 Alex Roitman,,,. @@ -885,7 +885,7 @@ 0 @I0046@ INDI 1 NAME Tom /Von Tester y tested/ 2 GIVN Tom -2 SPFX Von, +2 SPFX Von 2 SURN Tester y, tested 2 NICK TesterNickname 1 SEX M @@ -1420,7 +1420,7 @@ 0 @N0018@ NOTE Another Citation Note 0 @N0019@ NOTE A bad photo for sure 0 @O0000@ OBJE -1 FILE c:\msys64\mingw64\share\gramps\tests\O0.jpg +1 FILE c:\users\prc\workspace\grampsm\main\data\tests\O0.jpg 2 FORM jpg 2 TITL Michael O'Toole 2015-11 1 NOTE @N0019@ diff --git a/data/tests/imp_sample.ged b/data/tests/imp_sample.ged index cf534864c..99d15e7b3 100644 --- a/data/tests/imp_sample.ged +++ b/data/tests/imp_sample.ged @@ -50,9 +50,9 @@ 0 @I0@ INDI 1 NAME Anna /Hansdotter/ 2 GIVN Anna +2 SURN Hansdotter, Smith +2 SPFX Vrow, huh 2 SURN Hansdotter -2 SPFX Vrow -2 SURN Smith 2 _AKA Anna Smith 2 _AKA Hanna 2 NOTE Hans daughter? N0000 diff --git a/data/tests/imp_sample.gramps b/data/tests/imp_sample.gramps index 93a1285d2..4cc712888 100644 --- a/data/tests/imp_sample.gramps +++ b/data/tests/imp_sample.gramps @@ -3,7 +3,7 @@ "http://gramps-project.org/xml/1.7.1/grampsxml.dtd">
- + Alex Roitman,,, Not Provided @@ -617,7 +617,8 @@ F Anna - Smith + Hansdotter + Smith @@ -1704,7 +1705,7 @@ Unknown tag Line 1109: - + Objects referenced by this note were missing in a file imported on 12/25/1999 12:00:00 AM. diff --git a/gramps/plugins/export/exportgedcom.py b/gramps/plugins/export/exportgedcom.py index e928f5eaf..919948c14 100644 --- a/gramps/plugins/export/exportgedcom.py +++ b/gramps/plugins/export/exportgedcom.py @@ -1290,15 +1290,17 @@ class GedcomWriter(UpdateCallback): firstname = name.get_first_name().strip() surns = [] - surprefs = [] + surprefix = '' 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) + if name.get_surname_list(): + # GEDCOM only supports a single surname prefix + surn = name.get_surname_list()[0] + surprefix = surn.get_prefix().replace('/', '?') suffix = name.get_suffix() title = name.get_title() nick = name.get_nick_name() diff --git a/gramps/plugins/lib/libgedcom.py b/gramps/plugins/lib/libgedcom.py index f1ed7b1ea..f25fd9513 100644 --- a/gramps/plugins/lib/libgedcom.py +++ b/gramps/plugins/lib/libgedcom.py @@ -4318,11 +4318,12 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ + spfx = line.data.strip().split(", ")[0] if state.name.get_surname_list(): - state.name.get_surname_list()[0].set_prefix(line.data.strip()) + state.name.get_surname_list()[0].set_prefix(spfx) else: surn = Surname() - surn.set_prefix(line.data.strip()) + surn.set_prefix(spfx) surn.set_primary() state.name.set_surname_list([surn]) self.__skip_subordinate_levels(state.level + 1, state) @@ -4334,13 +4335,17 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - if state.name.get_surname_list(): - state.name.get_surname_list()[0].set_surname(line.data.strip()) - else: - surn = Surname() - surn.set_surname(line.data.strip()) - surn.set_primary() - state.name.set_surname_list([surn]) + names = line.data.strip().split(", ") + overwrite = bool(state.name.get_surname_list()) + for name in names: + if overwrite: + state.name.get_surname_list()[0].set_surname(name) + overwrite = False + else: + surn = Surname() + surn.set_surname(name) + surn.set_primary(primary=not state.name.get_surname_list()) + state.name.get_surname_list().append(surn) self.__skip_subordinate_levels(state.level + 1, state) def __name_marnm(self, line, state):