From 2f85845d32c6d6051cfef22da0a78fa6bd66cf70 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 23 Aug 2007 03:51:05 +0000 Subject: [PATCH] 2007-08-22 Don Allingham * src/GrampsDbUtils/_GedcomParse.py: use FACT for custom attributes, handle custom event descriptions as notes * src/GrampsDbUtils/_WriteGedcom.py: use FACT for custom attributes, handle custom event descriptions as notes * src/GrampsDbUtils/_GedTokens.py: add TOKEN_FACT svn: r8855 --- ChangeLog | 7 +++++ src/GrampsDbUtils/_GedcomParse.py | 45 +++++++++++++++++++++++++++++- src/GrampsDbUtils/_GedcomTokens.py | 2 ++ src/GrampsDbUtils/_WriteGedcom.py | 16 +++++++---- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e9d983312..068246a5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-08-22 Don Allingham + * src/GrampsDbUtils/_GedcomParse.py: use FACT for custom attributes, handle + custom event descriptions as notes + * src/GrampsDbUtils/_WriteGedcom.py: use FACT for custom attributes, handle + custom event descriptions as notes + * src/GrampsDbUtils/_GedTokens.py: add TOKEN_FACT + 2007-08-21 Don Allingham * src/GrampsDbUtils/_GedcomParse.py: code cleanup * src/GrampsDbUtils/_GedcomLex.py: code cleanup diff --git a/src/GrampsDbUtils/_GedcomParse.py b/src/GrampsDbUtils/_GedcomParse.py index 27af84939..a5bec1e84 100644 --- a/src/GrampsDbUtils/_GedcomParse.py +++ b/src/GrampsDbUtils/_GedcomParse.py @@ -421,6 +421,7 @@ class GedcomParser(UpdateCallback): # +1 <> {0:M} # +1 AFN {0:1} TOKEN_ATTR : self.__person_std_attr, + TOKEN_FACT : self.__person_fact, #+1 <> {0:M} TOKEN_BAPL : self.__person_bapl, TOKEN_CONL : self.__person_conl, @@ -519,7 +520,7 @@ class GedcomParser(UpdateCallback): # n <> {0:M} p.*,* TOKEN_OBJE : self.__event_object, # n <> {0:M} p. - TOKEN_NOTE : self.__event_note, + TOKEN_NOTE : self.__event_inline_note, TOKEN_RNOTE : self.__event_note, # Other TOKEN__PRIV : self.__event_privacy, @@ -601,6 +602,10 @@ class GedcomParser(UpdateCallback): TOKEN_TYPE : self.__ignore, } + self.person_fact_parse_tbl = { + TOKEN_TYPE : self.__person_fact_type, + } + self.person_attr_parse_tbl = { TOKEN_TYPE : self.__person_attr_type, TOKEN_CAUS : self.__ignore, @@ -2059,6 +2064,28 @@ class GedcomParser(UpdateCallback): self.__parse_level(sub_state, self.person_attr_parse_tbl, self.__ignore) + def __person_fact(self, line, state): + """ + Parses an TOKEN that GRAMPS recognizes as an Attribute + + @param line: The current line in GedLine format + @type line: GedLine + @param state: The current state + @type state: CurrentState + """ + sub_state = GedcomUtils.CurrentState() + sub_state.person = state.person + sub_state.attr = RelLib.Attribute() + sub_state.attr.set_value(line.data) + sub_state.level = state.level+1 + state.person.add_attribute(sub_state.attr) + self.__parse_level(sub_state, self.person_fact_parse_tbl, + self.__ignore) + + def __person_fact_type(self, line, state): + state.attr.set_type(line.data) + self.__skip_subordinate_levels(state.level) + def __person_bapl(self, line, state): """ Parses an BAPL TOKEN, producing a GRAMPS LdsOrd instance @@ -3133,6 +3160,22 @@ class GedcomParser(UpdateCallback): @type state: CurrentState """ self.__parse_note(line, state.event, state.level+1) + + def __event_inline_note(self, line, state): + """ + @param line: The current line in GedLine format + @type line: GedLine + @param state: The current state + @type state: CurrentState + """ + if line.data[0:13] == "Description: ": + state.event.set_description(line.data[13:]) + else: + new_note = RelLib.Note(line.data) + new_note.set_handle(Utils.create_id()) + self.dbase.add_note(new_note, self.trans) + self.__skip_subordinate_levels(level+2) + obj.add_note(new_note.get_handle()) def __event_source(self, line, state): """ diff --git a/src/GrampsDbUtils/_GedcomTokens.py b/src/GrampsDbUtils/_GedcomTokens.py index ffb05e59d..522a7fa16 100644 --- a/src/GrampsDbUtils/_GedcomTokens.py +++ b/src/GrampsDbUtils/_GedcomTokens.py @@ -138,6 +138,7 @@ TOKEN_ATTR = 119 TOKEN_MAP = 120 TOKEN_LATI = 121 TOKEN_LONG = 122 +TOKEN_FACT = 123 tokens = { "HEAD" : TOKEN_HEAD, "MEDI" : TOKEN_MEDI, @@ -238,4 +239,5 @@ tokens = { "MAP" : TOKEN_MAP, "LATI" : TOKEN_LATI, "LONG" : TOKEN_LONG, "_ITALIC" : TOKEN_IGNORE, "_PAREN" : TOKEN_IGNORE,"_PLACE" : TOKEN_IGNORE, + "FACT" : TOKEN_FACT, } diff --git a/src/GrampsDbUtils/_WriteGedcom.py b/src/GrampsDbUtils/_WriteGedcom.py index bbca7ec3f..9837f24d3 100644 --- a/src/GrampsDbUtils/_WriteGedcom.py +++ b/src/GrampsDbUtils/_WriteGedcom.py @@ -680,6 +680,9 @@ class GedcomWriter(UpdateCallback): self.__writeln(2, 'TYPE', val) else: self.__writeln(2, 'TYPE', str(event.get_type())) + descr = event.get_description() + if descr: + self.__writeln(2, 'NOTE', "Description: " + descr) self.dump_event_stats(event, event_ref) @@ -732,13 +735,11 @@ class GedcomWriter(UpdateCallback): if name and name.strip(): self.__writeln(1, name, value) + elif value: + self.__writeln(1, 'FACT', value) + self.__writeln(2, 'TYPE', key) else: - self.__writeln(1, 'EVEN') - if value: - self.__writeln(2, 'TYPE', "%s %s" % (key , value)) - else: - self.__writeln(2, 'TYPE', key) - + continue self.__write_note_references(attr.get_note_list(), 2) self.__write_source_references(attr.get_source_references(), 2) @@ -885,6 +886,9 @@ class GedcomWriter(UpdateCallback): the_type = str(event.get_type()) if the_type: self.__writeln(2, 'TYPE', the_type) + descr = event.get_description() + if descr: + self.__writeln(2, 'NOTE', "Description: " + descr) self.dump_event_stats(event, event_ref)