#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>
* src/plugins/NarrativeWeb.py:
Cleanup.

View File

@ -282,6 +282,7 @@ class GedcomParser(UpdateCallback):
self.is_ftw = False
self.is_ancestry_com = False
self.groups = None
self.want_parse_warnings = True
self.pid_map = GedcomUtils.IdMapper(
self.dbase.id_trans,
@ -818,7 +819,9 @@ class GedcomParser(UpdateCallback):
self.dbase.disable_signals()
self.__parse_header_head()
self.want_parse_warnings = False
self.__parse_header_source()
self.want_parse_warnings = True
self.__parse_submitter()
if self.use_def_src:
self.dbase.add_source(self.def_src, self.trans)
@ -1173,7 +1176,9 @@ class GedcomParser(UpdateCallback):
try:
line.data = line.data[5:]
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)
else:
self.__not_recognized(line, 1)
@ -3047,6 +3052,14 @@ class GedcomParser(UpdateCallback):
"""
if line.data[0:13] == "Description: ":
state.event.set_description(line.data[13:])
else:
if not line.data:
# empty: discard, with warning and skip subs
# Note: level+2
msg = _("Line %d: empty event note was ignored.")\
% 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())
@ -4171,10 +4184,15 @@ class GedcomParser(UpdateCallback):
###############################################################################
def __parse_note(self, line, obj, level):
# reference to a named note defined elsewhere
if line.token == TOKEN_RNOTE:
# reference to a named note defined elsewhere
gid = line.data.strip()
obj.add_note(self.__find_note_handle(self.nid_map[gid]))
else:
if not line.data:
msg = _("Line %d: empty note was ignored.") % line.line
self.__warn(msg)
self.__skip_subordinate_levels(level+1)
else:
new_note = gen.lib.Note(line.data)
new_note.set_handle(Utils.create_id())
@ -4183,6 +4201,11 @@ class GedcomParser(UpdateCallback):
obj.add_note(new_note.get_handle())
def __parse_inline_note(self, line, level):
if not line.data:
msg = _("Line %d: empty note was ignored.") % line.line
self.__warn(msg)
self.__skip_subordinate_levels(level)
else:
new_note = gen.lib.Note(line.data)
gid = self.nid_map[line.token_text]
handle = self.nid2id.get(gid)
@ -4213,10 +4236,16 @@ class GedcomParser(UpdateCallback):
"""
Skip add lines of the specified level or lower.
"""
skips = 0;
while True:
line = self.__get_next_line()
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
skips += 1
def handle_source(self, line, level):
"""

View File

@ -44,6 +44,8 @@ _head ="""
# _tail is presently a single (SUBM) record plus the trailer
# to satisfy the "one or more records" in the spec
# 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 = """
0 @SUBM1@ SUBM
1 NAME test /gedread/
@ -65,6 +67,8 @@ def make_gedcom_input(gfile, fragment):
# code patterned after contents of ReadGedcom.import2,
# 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):
"""read gedcom file into a test db

View File

@ -44,7 +44,9 @@ class Test(U.TestCase):
gr.gread(db, infil)
logging.warn("nothing here")
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")
# verify one person in database
np = db.get_number_of_people()