Skip to content
Snippets Groups Projects
Commit c20cee22 authored by Henning Glawe's avatar Henning Glawe
Browse files

make annotate output field widths configurable in constructor

with this, field widths and format string are attributes of annotator
instances.
As a side effect, this accelerates runs with --annotate.
parent 797813bd
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,8 @@ LOGGER = logging.getLogger(__name__)
class Annotator(object):
def __init__(self, annotateFilename=None, coverageIgnore=None):
def __init__(self, annotateFilename=None, coverageIgnore=None,
formatNameWidth=15, formatSourceWidth=20):
self.matchHighlighter = MatchHighlighter()
self.coverageIgnore = coverageIgnore
if annotateFilename is None:
......@@ -14,7 +15,15 @@ class Annotator(object):
else:
LOGGER.info("writing annotated input to " + annotateFilename)
self.annotateFile = open(annotateFilename, 'w')
self.annotateFile.write("# this file contains ANSI colors; use 'less -R' to view it\n")
self.annotateFile.write(
"# this file contains ANSI colors; use 'less -R' to view it\n")
self._formatNameWidth = formatNameWidth
self._formatSourceWidth = formatSourceWidth
self._update_annotate_format()
def _update_annotate_format(self):
self._annotate_format = '%%%ds:%%04d %%%ds %%7s|%%s' % (
self._formatSourceWidth, self._formatNameWidth)
def annotate(self,match,line,matcher,targetStartEnd):
if not self.annotateFile:
......@@ -38,11 +47,11 @@ class Annotator(object):
matchlabel = 'no'
if matcher.name:
name=matcher.name[-15:]
name=matcher.name[-self._formatNameWidth:]
else:
name='UNNAMED'
defFile=matcher.defFile[-20:]
self.annotateFile.write("%20s:%04d %15s %7s|%s" % (
defFile=matcher.defFile[-self._formatSourceWidth:]
self.annotateFile.write(self._annotate_format % (
defFile, matcher.defLine, name,
matchlabel, highlightedLine,
))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment