Add in basic plugin/config and renderer support.

This commit is contained in:
Mike Auty
2014-03-31 00:36:11 +01:00
parent 89e7e6e7ff
commit fa789fb174
6 changed files with 242 additions and 69 deletions
-69
View File
@@ -1,69 +0,0 @@
from framework import validity
import collections
__author__ = 'mike'
class TreeRow(validity.ValidityRoutines):
"""Class providing the interface for an individual Row of the TreeGrid"""
def __init__(self, treegrid, values):
self._treegrid = treegrid
if not isinstance(treegrid, TreeGrid):
raise TypeError("TreeRow requires treegrid to be a TreeGrid")
self._values = values
if not isinstance(self, TreeGrid):
if not isinstance(values, list):
raise TypeError("Values must be a list of values of the type specified by treegrid.")
treegrid.validate_values(self._values)
else:
self._values = None
self._children = []
def add_child(self, child):
"""Appends a child to the current Row"""
raise NotImplementedError("Abstract method add_child not implemented.")
def insert_child(self, child, position):
"""Adds a child at the specified position"""
raise NotImplementedError("Abstract method insert_child not implemented")
def clear(self):
"""Removes all children from this row"""
self._children = []
@property
def children(self):
"""Returns an iterator of the children of the current row"""
for child in self._children:
yield child
class TreeGrid(TreeRow):
"""Class providing the interface for"""
simple_types = {int, str, float}
def __init__(self, columns):
"""Constructs a TreeGrid object using a specific set of columns
The TreeGrid itself is a root element, that can have children but no values
:param columns: An ordered dictionary of column name to column types.
"""
if not isinstance(columns, collections.OrderedDict):
raise TypeError("Columns must be an OrderedDict of column names to column types")
self._columns = columns
for k in columns:
is_simple_type = False
for t in self.simple_types:
is_simple_type = is_simple_type or issubclass(columns[k], t)
if not is_simple_type:
raise TypeError("One of the column types is not a simple type")
# We can use the special type None because we're the top level node without values
TreeRow.__init__(self, self, None)
def validate_values(self, values):
"""Takes a list of values and verified them against the column types"""
for i in range(len(self._columns)):
if not isinstance(values[i], self._columns[i]):
raise TypeError("Column type " + str(i) + " is incorrect.")
@@ -0,0 +1,38 @@
"""
Created on 6 May 2013
@author: mike
"""
from volatility.framework import validity
from volatility.framework.interfaces import context as context_module
class PluginInterface(validity.ValidityRoutines):
"""Class that defines the interface all Plugins must maintain"""
def __init__(self, context):
self._context = self.type_check(context, context_module.ContextInterface)
@property
def context(self):
return self._context
def establish_context(self):
"""Alters the context to ensure the plugin can run"""
raise NotImplementedError("Abstract method establish_context must be overridden by plugins.")
def plugin_options(self, config_group = None):
"""Modifies the passed in ConfigGroup object to contain the required options"""
raise NotImplementedError("Abstract method plugin_options must be overridden by plugins")
def __call__(self):
"""Executes the functionality of the code
Returns an OutputUI object
"""
# Needs to say what it can/can't handle (validate context)
# Needs to offer available options'
# Figure out how to handle global config options
@@ -0,0 +1,81 @@
from volatility.framework import validity
import collections
__author__ = 'mike'
class TreeRow(validity.ValidityRoutines):
"""Class providing the interface for an individual Row of the TreeGrid"""
def __init__(self, treegrid, values):
self.type_check(treegrid, TreeGrid)
if not isinstance(self, TreeGrid):
self.type_check(values, list)
treegrid.validate_values(values)
def add_child(self, child):
"""Appends a child to the current Row"""
raise NotImplementedError("Abstract method add_child not implemented.")
def insert_child(self, child, position):
"""Adds a child at the specified position"""
raise NotImplementedError("Abstract method insert_child not implemented.")
def clear(self):
"""Removes all children from this row
:rtype : None
"""
raise NotImplementedError("Abstract method clear not implemented.")
@property
def children(self):
"""Returns an iterator of the children of the current row
:rtype : iterator of TreeRows
"""
raise NotImplementedError("Abstract property children not implemented.")
class TreeGrid(TreeRow):
"""Class providing the interface for a TreeGrid (which contains TreeRows)"""
simple_types = {int, str, float, bytes}
def __init__(self, columns):
"""Constructs a TreeGrid object using a specific set of columns
The TreeGrid itself is a root element, that can have children but no values
:param columns: An ordered dictionary of column name to (column types).
"""
self.type_check(columns, collections.OrderedDict)
for k, column in columns.items():
is_simple_type = False
for t in self.simple_types:
try:
self.class_check(column, t)
is_simple_type = True
except TypeError:
pass
if not is_simple_type:
raise TypeError("Column " + k + "'s type " + column.__class__.__name__ + " is not a simple type")
# We can use the special type None because we're the top level node without values
TreeRow.__init__(self, self, None)
def validate_values(self, values):
"""Takes a list of values and verifies them against the column types"""
raise NotImplementedError("Abstract method validate_values not implemented.")
class Renderer(validity.ValidityRoutines):
def __init__(self, options):
"""Accepts an options object to configure the renderers"""
#FIXME: Once the config option objects are in place, put the type_check in place
@staticmethod
def get_render_options():
"""Returns a list of rendering options"""
raise NotImplementedError("Abstract method get_render_options not implemented.")
def render(self, grid):
"""Takes a grid object and renders it based on the object's preferences"""
raise NotImplementedError("Abstract method render not implemented.")