Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
update for more precise error offset interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Nov 29, 2016
1 parent 19b6b36 commit 7017fb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
34 changes: 32 additions & 2 deletions src/FlightCrew-plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
"2200" : "Warning OPF resource in manifest not reachable",
"2201" : "Warning non ascii filename",
}

def generate_line_offsets(s):
offlst = [0]
i = s.find('\n', 0)
while i >= 0:
offlst.append(i)
i = s.find('\n', i + 1)
return offlst

def charoffset(line, col, offlst):
coffset = offlst[line-1] + 1 + (col - 1)
return coffset

def run(bk):

Expand Down Expand Up @@ -117,7 +129,8 @@ def run(bk):

found_problem = False
content = None

lastfilepath = None

for text, tprefix, tname, ttype, tattr in qp.parse_iter():
if text is not None:
content = text
Expand All @@ -130,6 +143,7 @@ def run(bk):
resid = None
msg = None
filepath = None
coffset = None
continue

if tname == "type" and ttype == 'end':
Expand Down Expand Up @@ -157,11 +171,27 @@ def run(bk):
continue

if tname == "problem" and ttype == 'end':
# generate file offsets once per file
if bk.launcher_version() >= 20160802 and filepath != lastfilepath:
text = None
with open(os.path.join(ebook_root, filepath), 'rb') as f:
text = f.read()
text = text.decode('utf-8', errors='replace')
offlst = generate_line_offsets(text)
lastfilepath = filepath

# generate column offset
if bk.launcher_version() >= 20160802 and lineno and colno:
coffset = charoffset(int(lineno), int(colno), offlst)

msg = resid + ' : ' + msg + " near column " + colno
# since will be passed as attribute make sure to handle any embedded quotes
# all other entity replacements have already been done
msg = msg.replace("\"",""")
bk.add_result(ptype, filepath, lineno, msg)
if coffset:
bk.add_extended_result(ptype, filepath, lineno, coffset, msg)
else:
bk.add_result(ptype, filepath, lineno, msg)
found_problem = True
continue

Expand Down
2 changes: 1 addition & 1 deletion src/FlightCrew-plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>Use FlightCrew to Validate epub2 ebooks</description>
<engine>python2.7</engine>
<engine>python3.4</engine>
<version>0.9.1</version>
<version>0.9.2</version>
<autostart>true</autostart>
<autoclose>true</autoclose>
<oslist>osx</oslist>
Expand Down

0 comments on commit 7017fb6

Please sign in to comment.