#1851 discard empty notes (and warn), also warn of skipped subordinates (see want_parse_warnings), update test util per warnings change

svn: r10147
This commit is contained in:
James G Sack
2008-03-01 06:58:17 +00:00
parent 825b301f7f
commit 8e3e98d571
4 changed files with 65 additions and 21 deletions

View File

@ -1,3 +1,12 @@
2008-02-28 Jim Sack <jgsack@san.rr.com>
* src/test/gedread_util.py: add some comments
* src/test/test/gedread_util_test.py: update per changes to
_GedcomParse warning messages for skipped subordinates
* src/GrampsDbUtils/_GedcomParse.py: #1851 discard empty notes
and emit a warning message. Also add warnings for skipped
subordinates in the same spirit (warn about bad/lost data)
See self.want_parse_warnings for disabling those warnings.
2008-02-27 Brian Matherly <brian@gramps-project.org> 2008-02-27 Brian Matherly <brian@gramps-project.org>
* src/plugins/NarrativeWeb.py: * src/plugins/NarrativeWeb.py:
Cleanup. Cleanup.

View File

@ -282,6 +282,7 @@ class GedcomParser(UpdateCallback):
self.is_ftw = False self.is_ftw = False
self.is_ancestry_com = False self.is_ancestry_com = False
self.groups = None self.groups = None
self.want_parse_warnings = True
self.pid_map = GedcomUtils.IdMapper( self.pid_map = GedcomUtils.IdMapper(
self.dbase.id_trans, self.dbase.id_trans,
@ -818,7 +819,9 @@ class GedcomParser(UpdateCallback):
self.dbase.disable_signals() self.dbase.disable_signals()
self.__parse_header_head() self.__parse_header_head()
self.want_parse_warnings = False
self.__parse_header_source() self.__parse_header_source()
self.want_parse_warnings = True
self.__parse_submitter() self.__parse_submitter()
if self.use_def_src: if self.use_def_src:
self.dbase.add_source(self.def_src, self.trans) self.dbase.add_source(self.def_src, self.trans)
@ -1173,7 +1176,9 @@ class GedcomParser(UpdateCallback):
try: try:
line.data = line.data[5:] line.data = line.data[5:]
except: except:
pass # don't think this path is ever taken, but if it is..
# ensure a message is emitted & subordinates skipped
line.data = None
self.__parse_inline_note(line, 1) self.__parse_inline_note(line, 1)
else: else:
self.__not_recognized(line, 1) self.__not_recognized(line, 1)
@ -3048,11 +3053,19 @@ class GedcomParser(UpdateCallback):
if line.data[0:13] == "Description: ": if line.data[0:13] == "Description: ":
state.event.set_description(line.data[13:]) state.event.set_description(line.data[13:])
else: else:
new_note = gen.lib.Note(line.data) if not line.data:
new_note.set_handle(Utils.create_id()) # empty: discard, with warning and skip subs
self.dbase.add_note(new_note, self.trans) # Note: level+2
self.__skip_subordinate_levels(state.level+2) msg = _("Line %d: empty event note was ignored.")\
state.event.add_note(new_note.get_handle()) % line.line
self.__warn(msg)
self.__skip_subordinate_levels(state.level+2)
else:
new_note = gen.lib.Note(line.data)
new_note.set_handle(Utils.create_id())
self.dbase.add_note(new_note, self.trans)
self.__skip_subordinate_levels(state.level+2)
state.event.add_note(new_note.get_handle())
def __event_source(self, line, state): def __event_source(self, line, state):
""" """
@ -4171,26 +4184,36 @@ class GedcomParser(UpdateCallback):
############################################################################### ###############################################################################
def __parse_note(self, line, obj, level): def __parse_note(self, line, obj, level):
# reference to a named note defined elsewhere
if line.token == TOKEN_RNOTE: if line.token == TOKEN_RNOTE:
# reference to a named note defined elsewhere
gid = line.data.strip() gid = line.data.strip()
obj.add_note(self.__find_note_handle(self.nid_map[gid])) obj.add_note(self.__find_note_handle(self.nid_map[gid]))
else: else:
new_note = gen.lib.Note(line.data) if not line.data:
new_note.set_handle(Utils.create_id()) msg = _("Line %d: empty note was ignored.") % line.line
self.dbase.add_note(new_note, self.trans) self.__warn(msg)
self.__skip_subordinate_levels(level+1) self.__skip_subordinate_levels(level+1)
obj.add_note(new_note.get_handle()) else:
new_note = gen.lib.Note(line.data)
new_note.set_handle(Utils.create_id())
self.dbase.add_note(new_note, self.trans)
self.__skip_subordinate_levels(level+1)
obj.add_note(new_note.get_handle())
def __parse_inline_note(self, line, level): def __parse_inline_note(self, line, level):
new_note = gen.lib.Note(line.data) if not line.data:
gid = self.nid_map[line.token_text] msg = _("Line %d: empty note was ignored.") % line.line
handle = self.nid2id.get(gid) self.__warn(msg)
new_note.set_handle(handle) self.__skip_subordinate_levels(level)
new_note.set_gramps_id(gid) else:
self.dbase.add_note(new_note, self.trans) new_note = gen.lib.Note(line.data)
self.nid2id[new_note.gramps_id] = new_note.handle gid = self.nid_map[line.token_text]
self.__skip_subordinate_levels(level) handle = self.nid2id.get(gid)
new_note.set_handle(handle)
new_note.set_gramps_id(gid)
self.dbase.add_note(new_note, self.trans)
self.nid2id[new_note.gramps_id] = new_note.handle
self.__skip_subordinate_levels(level)
def __parse_source_reference(self, src_ref, level, handle): def __parse_source_reference(self, src_ref, level, handle):
""" """
@ -4213,10 +4236,16 @@ class GedcomParser(UpdateCallback):
""" """
Skip add lines of the specified level or lower. Skip add lines of the specified level or lower.
""" """
skips = 0;
while True: while True:
line = self.__get_next_line() line = self.__get_next_line()
if self.__level_is_finished(line, level): if self.__level_is_finished(line, level):
if skips and self.want_parse_warnings:
msg = _("skipped %d subordinate(s) at line %d")\
% (skips, line.line - skips)
self.__warn(msg)
return return
skips += 1
def handle_source(self, line, level): def handle_source(self, line, level):
""" """

View File

@ -44,6 +44,8 @@ _head ="""
# _tail is presently a single (SUBM) record plus the trailer # _tail is presently a single (SUBM) record plus the trailer
# to satisfy the "one or more records" in the spec # to satisfy the "one or more records" in the spec
# it also provides a target for the xref in the header # it also provides a target for the xref in the header
# it also gives a "skipping 1 subordinate.." message error
# which presumeably will be fixed someday
_tail = """ _tail = """
0 @SUBM1@ SUBM 0 @SUBM1@ SUBM
1 NAME test /gedread/ 1 NAME test /gedread/
@ -65,6 +67,8 @@ def make_gedcom_input(gfile, fragment):
# code patterned after contents of ReadGedcom.import2, # code patterned after contents of ReadGedcom.import2,
# but avoiding the occurrence of a popup DialogError. # but avoiding the occurrence of a popup DialogError.
# NOTE: may need rewrite to track mods in ReadGedcom
# test this code via src/test/test/gedread_util_test.py
# ------------------------------------------------------- # -------------------------------------------------------
def gread(db, fname): def gread(db, fname):
"""read gedcom file into a test db """read gedcom file into a test db

View File

@ -44,7 +44,9 @@ class Test(U.TestCase):
gr.gread(db, infil) gr.gread(db, infil)
logging.warn("nothing here") logging.warn("nothing here")
loglines = tl.logfile_getlines() loglines = tl.logfile_getlines()
self.assertEquals(len(loglines),1, #NB incorrect SUBM handling causes one extraneous warning
xWarns = 1
self.assertEquals(len(loglines),1 + xWarns,
"log has no unexpected content") "log has no unexpected content")
# verify one person in database # verify one person in database
np = db.get_number_of_people() np = db.get_number_of_people()