Add in FormatSpecification object, and bulk up the TextRenderer.

This commit is contained in:
Mike Auty
2014-04-14 02:22:05 +01:00
parent 3da8bdf28a
commit 2e5656ade4
2 changed files with 260 additions and 23 deletions
+34 -13
View File
@@ -1,32 +1,53 @@
from framework.renderers import FormatSpecification
__author__ = 'mike'
from volatility.framework.interfaces import renderers as interface
from volatility.framework import renderers
import sys
class TextRenderer(interface.Renderer):
def get_render_options(self):
# FIXME: Fill in the docstring and provide render_options
pass
def __init__(self, options):
interface.Renderer.__init__(self, options)
self._options = options
self._headers = []
self._column_widths = []
def render(self, grid):
"""Renders a text grid based on the contents of each element"""
# Render headers and calculate column widths
self.type_check(grid, renderers.TreeGrid)
grid.iterator()
def _determine_headers(self, grid):
self.type_check(grid, renderers.TreeGrid)
self._headers = []
# FIXME: Separator should come from options
sep = " | "
max_level = -1
column_maximum_widths = [max(len(column.name), column.format.width) for column in grid.columns]
for (level, row) in grid.iterator():
max_level = max(max_level, level)
column_maximum_widths = [max(column_maximum_widths[column.index], len(
("{0:" + column.format.to_string() + "}").format(row.values[column.index]))) for column in grid.columns]
for column in grid.columns:
self._headers.append((column.name, len(column.name)))
column.format.width = column_maximum_widths[column.index]
column.format.fill = ' '
# column.format.align = '<'
# Run through the values and determine their maximum lengths, perhaps build up a two dimensional array
# Then print out the headers and the values at their appropriate spacings
# Potentially warn if the output is likely to be longer than the display area.
def render_row(self, row, level):
pass
headers = [("{0:" + FormatSpecification(width = column_maximum_widths[column.index], fill = ' ',
align = '^').to_string() + "}").format(column.name) for column in
grid.columns]
print(sep.join(headers))
def _subrender(self, subgrid, level):
for child in subgrid:
self.render_row(child, level + 1)
self._subrender(child, level + 1)
for (level, row) in grid.iterator():
row_text = []
for column in grid.columns:
row_text.append(("{:" + column.format.to_string() + "}").format(row.values[column.index]))
line = sep.join(row_text)
sys.stdout.write(line + "\n")