From 618112b51c5bee69ee51d6e2ceb9d44d6e8caaf0 Mon Sep 17 00:00:00 2001 From: prculley Date: Tue, 2 Aug 2016 09:06:06 -0500 Subject: [PATCH] Support for FTM and others Custom Gedcom Event Tags on import --- data/tests/imp_CustTags.ged | 82 +++++++++++++ data/tests/imp_CustTags.gramps | 197 ++++++++++++++++++++++++++++++++ gramps/plugins/lib/libgedcom.py | 75 ++++++++++-- 3 files changed, 347 insertions(+), 7 deletions(-) create mode 100644 data/tests/imp_CustTags.ged create mode 100644 data/tests/imp_CustTags.gramps diff --git a/data/tests/imp_CustTags.ged b/data/tests/imp_CustTags.ged new file mode 100644 index 000000000..c12b7e67c --- /dev/null +++ b/data/tests/imp_CustTags.ged @@ -0,0 +1,82 @@ +0 HEAD +1 SOUR FTM +2 VERS Family Tree Maker (22.0.0.1410) +2 NAME Family Tree Maker for Windows +2 CORP Ancestry.com +3 ADDR 360 W 4800 N +4 CONT Provo, UT 84604 +1 DEST GED55 +1 DATE 01 MAR 2016 +1 CHAR UTF-8 +1 FILE D:\Family Tree Maker\imp_FTM_LINK.ged +1 SUBM @SUBM@ +1 GEDC +2 VERS 5.5 +2 FORM LINEAGE-LINKED +0 @SUBM@ SUBM +1 NAME The Subm /Tester/ +1 ADDR 123 Main St., Winslow, PA, 12345 +2 ADR1 123 Main St. +2 CITY Winslow +2 STAE PA +2 POST 12345 +0 @I0@ INDI +1 NAME The /Tester/ +2 SOUR @S6@ +3 PAGE 777, record for The Tester +3 _JUST Because it’s good +1 BIRT +2 DATE 29 DEC 1954 +2 PLAC 123 High St, Cleveland, Cuyahoga, Ohio, USA, 44140 +3 FORM Street, City, County, State, Country, Zip code +1 _CIRC +2 DATE 11 JAN 1955 +2 PLAC 456 Main St, Cleveland, Cuyahoga, Ohio, USA, 44140 +3 FORM Street, City, County, State, Country, Zip code +1 _ELEC Mayor +2 TYPE Small town +2 DATE 1980 +2 PLAC Littetown, Smallcounty, Ohio, USA +1 FAMS @F4211@ +1 _XYZ He should keep his zipper closed +2 DATE 1979 +1 EVEN Celebration +2 TYPE Independence Day +2 DATE 4 JUL 1981 +0 @I1@ INDI +1 NAME Mrs /Tester/ +1 RESI +2 DATE 30 DEC 1954 +2 ADDR 123 Main St., Winslow, PA, 12345 +3 ADR1 123 Main St. +3 CITY Winslow +3 STAE PA +3 POST 12345 +2 NOTE Address as event is legal, with PHON,FAX,EMAIL,WWW +1 FAMS @F4211@ +0 @I2@ INDI +1 NAME Tom /Tester/ +1 FAMC @F4211@ +0 @F4211@ FAM +1 HUSB @I0@ +1 WIFE @I1@ +1 CHIL @I2@ +2 _FREL Natural +2 _MREL Natural +1 MARR +2 DATE 1970 +2 PLAC St Rafaels Church, Bay Village, Cuyahoga, Ohio, USA +1 _INFIDELITY +2 DATE 1979 +2 PLAC Of Ill Repute, Shaker Heights, Ohio, USA +1 _SEPR +2 DATE 1980 +2 PLAC Cuyahoga, OHIO, USA +0 @S6@ SOUR +1 TITL Ohio Births, 1958-2002 +1 REPO @R1@ +0 @R1@ REPO +1 NAME Testers Repository +1 ADDR 123 High St., OSF village, CA, USA +1 NOTE Testers Repository Record +0 TRLR diff --git a/data/tests/imp_CustTags.gramps b/data/tests/imp_CustTags.gramps new file mode 100644 index 000000000..8415cfdf8 --- /dev/null +++ b/data/tests/imp_CustTags.gramps @@ -0,0 +1,197 @@ + + + +
+ + + The Subm /Tester/ + 123 Main St. + Winslow + PA + 12345 + +
+ + + Birth + + + + + Circumcision + + + + + Elected + + + Small town + + + _XYZ + + He should keep his zipper closed + + + Independence Day + + Celebration + + + Residence + + + + + + Marriage + + + + + _INFIDELITY + + + + + Separation + + + + + + + U + + The + Tester + + + + + + + + + + + U + + Mrs + Tester + + + + + + U + + Tom + Tester + + + + + + + + + + + + + + + + + + 777, record for The Tester + 2 + + + + + + + Ohio Births, 1958-2002 + + + + + + 123 High St, Cleveland, Cuyahoga, Ohio, USA, 44140 + 44140 + + + + + 456 Main St, Cleveland, Cuyahoga, Ohio, USA, 44140 + 44140 + + + + + Littetown, Smallcounty, Ohio, USA + + + + 123 Main St., Winslow, PA, 12345 + + + + + St Rafaels Church, Bay Village, Cuyahoga, Ohio, USA + + + + Of Ill Repute, Shaker Heights, Ohio, USA + + + + Cuyahoga, OHIO, USA + + + + USA + + + + Ohio, USA + + + + + Cuyahoga, Ohio, USA + + + + + Cleveland, Cuyahoga, Ohio, USA + + + + + + + Testers Repository + Library +
+ 123 High St., OSF village, CA, USA +
+ +
+
+ + + Because it’s good + + + Address as event is legal, with PHON,FAX,EMAIL,WWW + + + Testers Repository Record + + +
diff --git a/gramps/plugins/lib/libgedcom.py b/gramps/plugins/lib/libgedcom.py index 157d5935c..b7d983eb3 100644 --- a/gramps/plugins/lib/libgedcom.py +++ b/gramps/plugins/lib/libgedcom.py @@ -270,6 +270,7 @@ TOKEN__FSFTID = 131 TOKEN__PHOTO = 132 TOKEN__LINK = 133 TOKEN__PRIM = 134 +TOKEN__JUST = 135 TOKENS = { "HEAD" : TOKEN_HEAD, "MEDI" : TOKEN_MEDI, @@ -377,6 +378,7 @@ TOKENS = { "_MAR" : TOKEN__MAR, "_MARN" : TOKEN__MARN, "_ADPN" : TOKEN__ADPN, "_FSFTID" : TOKEN__FSFTID, "_LINK" : TOKEN__LINK, "_PHOTO" : TOKEN__PHOTO, + "_JUST" : TOKEN__JUST, # FTM Citation Quality Justification } ADOPT_NONE = 0 @@ -511,7 +513,7 @@ PERSONALCONSTANTEVENTS = { EventType.DEGREE : "_DEG", EventType.DIV_FILING : "DIVF", EventType.EDUCATION : "EDUC", - EventType.ELECTED : "", + EventType.ELECTED : "_ELEC", # FTM custom tag EventType.EMIGRATION : "EMIG", EventType.FIRST_COMMUN : "FCOM", EventType.GRADUATION : "GRAD", @@ -563,7 +565,40 @@ LDS_STATUS = { "SUBMITTED": LdsOrd.STATUS_SUBMITTED, "UNCLEARED": LdsOrd.STATUS_UNCLEARED, } - +# ------------------------------------------------------------------------- +# +# Custom event friendly names. These are non-standard GEDCOM "NEW_TAG" +# tags that start with an '_' i.e. "_DNA". FTM has several of these, other +# programs may have more. If a tag with this format is encountered it is +# checked in this table for a "friendly" name translation and thereafter is +# displayed and exported as such. If the tag is NOT in this table and not +# otherwise handled by the code, the tag itself is used for display and +# export. For example "_XYZ" is not in the table and will be displayed as +# "_XYZ" and exported as an EVEN.TYPE=_XYZ +# As Custom entries, they do not appear in GRAMPS Events add choice unless +# already imported via GEDCOM. +# +# ------------------------------------------------------------------------- +CUSTOMEVENTTAGS = { + "_CIRC" : _("Circumcision"), + "_COML" : _("Common Law Marriage"), + "_DEST" : _("Destination"), + "_DNA" : _("DNA"), + "_DCAUSE" : _("Cause of Death"), + "_EMPLOY" : _("Employment"), + "_EXCM" : _("Excommunication"), + "_EYC" : _("Eye Color"), + "_FUN" : _("Funeral"), + "_HEIG" : _("Height"), + "_INIT" : _("Initiatory (LDS)"), + "_MILTID" : _("Military ID"), + "_MISN" : _("Mission (LDS)"), + "_NAMS" : _("Namesake"), + "_ORDI" : _("Ordinance"), + "_ORIG" : _("Origin"), + "_SEPR" : _("Separation"), # Applies to Families + "_WEIG" : _("Weight"), + } # table for skipping illegal control chars in GEDCOM import # Only 09, 0A, 0D are allowed. STRIP_DICT = dict.fromkeys(list(range(9))+list(range(11, 13))+list(range(14, 32))) @@ -2316,6 +2351,7 @@ class GedcomParser(UpdateCallback): TOKEN_RNOTE : self.__citation_note, TOKEN_TEXT : self.__citation_data_text, TOKEN__LINK : self.__citation_link, + TOKEN__JUST : self.__citation__just, } self.func_list.append(self.citation_parse_tbl) @@ -3692,10 +3728,12 @@ class GedcomParser(UpdateCallback): @type state: CurrentState """ # We can get here when a tag that is not valid in the indi_parse_tbl - # parse table is encountered. It is remotely possible that this is - # actally a DATE tag, in which case line.data will be a date object, so - # we need to convert it back to a string here. - event_ref = self.__build_event_pair(state, EventType.CUSTOM, + # parse table is encountered. The tag may be of the form "_XXX". We + # try to convert to a friendly name, if fails use the tag itself as + # the TYPE in a custom event + cust_tag = CUSTOMEVENTTAGS.get(line.token_text, line.token_text) + cust_type = EventType((EventType.CUSTOM, cust_tag)) + event_ref = self.__build_event_pair(state, cust_type, self.event_parse_tbl, str(line.data)) state.person.add_event_ref(event_ref) @@ -4104,6 +4142,7 @@ class GedcomParser(UpdateCallback): state.person.add_address(addr) self.__skip_subordinate_levels(state.level+1, state) + def __person_email(self, line, state): """ O INDI @@ -5015,11 +5054,20 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ + # We can get here when a tag that is not valid in the family_func + # parse table is encountered. The tag may be of the form "_XXX". We + # try to convert to a friendly name, if fails use the tag itself as + # the TYPE in a custom event + cust_tag = CUSTOMEVENTTAGS.get(line.token_text,line.token_text) + cust_type = EventType((EventType.CUSTOM, cust_tag)) event = Event() event_ref = EventRef() event_ref.set_role(EventRoleType.FAMILY) event.set_gramps_id(self.emapper.find_next()) - event.set_type(line.data) + event.set_type(cust_type) + # in case a description ever shows up + if line.data and line.data != 'Y': + event.set_description(line.data) self.dbase.add_event(event, self.trans) sub_state = CurrentState() @@ -6270,6 +6318,19 @@ class GedcomParser(UpdateCallback): self.dbase.add_note(note, self.trans) state.citation.add_note(note.get_handle()) + def __citation__just(self, line, state): + """ + Not legal GEDCOM - added to support FTM, converts the _JUST tag to a + note. This tag represents the Justification for a source. + """ + note = Note() + note.set(line.data) + gramps_id = self.dbase.find_next_note_gramps_id() + note.set_gramps_id(gramps_id) + note.set_type(_("Citation Justification")) + self.dbase.add_note(note, self.trans) + state.citation.add_note(note.get_handle()) + def __citation_data_note(self, line, state): self.__parse_note(line, state.citation, state.level, state)