Skip to content
Snippets Groups Projects

Plugin management system for piped transformation functions for log files

Merged Stefan-Gabriel Chitic requested to merge log_update into prepare-for-new-jenkins
1 file
+ 14
7
Compare changes
  • Side-by-side
  • Inline
@@ -97,7 +97,8 @@ class XTerm2HTML(object):
def __init__(self, first_line=1, show_line_no=False,
for_bootstrap=False, line_prefix='',
is_escaped=False):
is_escaped=False,
plugins_function=[]):
'''
Initialize the conversion instance.
An optional first_line can be provided if the output of the processing
@@ -111,6 +112,7 @@ class XTerm2HTML(object):
self.for_bootstrap = for_bootstrap
self.line_prefix = line_prefix
self.is_escaped = is_escaped
self.plugins_function = plugins_function
def parse_code(self, code):
'''
@@ -214,6 +216,10 @@ class XTerm2HTML(object):
'''
Choose the correct function to process the data
'''
# Preprocess escape all the text
chunk = cgi.escape(chunk, quote=True)
for plugin_function in self.plugins_function:
chunk = plugin_function(chunk)
if self.for_bootstrap:
return self._bootstrap_process(chunk)
return self._normal_process(chunk)
@@ -259,7 +265,7 @@ class XTerm2HTML(object):
data.append('<span class="{}">'.format(new_class))
old_class = new_class
# flush text
data.append(cgi.escape(line[pos:start], quote=True))
data.append(line[pos:start])
if m:
# update current style
@@ -321,7 +327,7 @@ class XTerm2HTML(object):
data.append('<samp>%s'
'</samp>' % line[pos:start])
else:
data.append(cgi.escape(line[pos:start], quote=True))
data.append(line[pos:start])
if m:
# update current style
@@ -339,13 +345,14 @@ class XTerm2HTML(object):
def convertFile(src, dst, show_line_no=False, for_bootstrap=False,
line_prefix=''):
line_prefix='', plugins_function=[]):
'''
Small helper to convert a text (ANSI) file to HTML.
'''
from os.path import basename
conv = XTerm2HTML(show_line_no=show_line_no, for_bootstrap=for_bootstrap,
line_prefix=line_prefix)
line_prefix=line_prefix,
plugins_function=plugins_function)
with open(dst, 'w') as dst_file, open(src) as src_file:
dst_file.write(conv.head(title=basename(src)))
dst_file.write(conv.process(src_file.read()))
@@ -373,10 +380,10 @@ if __name__ == '__main__':
import sys
if '--convertFile' in sys.argv:
src = sys.argv[sys.argv.index('--convertFile') + 1]
plugin = []
dest = src + '.html'
convertFile(src, dest, show_line_no='--show-line-no' in sys.argv,
for_bootstrap='--boostrap' in sys.argv,
line_prefix='test')
for_bootstrap='--boostrap' in sys.argv)
else:
conv = XTerm2HTML(show_line_no='--show-line-no' in sys.argv,
for_bootstrap='--boostrap' in sys.argv)
Loading