|
@@ -17,8 +17,79 @@
|
|
|
# along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
|
|
|
#
|
|
|
|
|
|
-class Plugin(object):
|
|
|
+class Marker(object):
|
|
|
+ class T(object):
|
|
|
+ NONE = 0x00
|
|
|
+ COMMENT = 0x01
|
|
|
+ STRING = 0x02
|
|
|
+ PREPROCESSOR = 0x04
|
|
|
+ CODE = 0x08
|
|
|
+ ALL_EXCEPT_CODE = 0x07
|
|
|
+ ANY = 0xFF
|
|
|
+
|
|
|
+ def to_str(self, group):
|
|
|
+ if group == self.NONE:
|
|
|
+ return "none"
|
|
|
+ elif group == self.COMMENT:
|
|
|
+ return "comment"
|
|
|
+ elif group == self.STRING:
|
|
|
+ return "string"
|
|
|
+ elif group == self.PREPROCESSOR:
|
|
|
+ return "preprocessor"
|
|
|
+ elif group == self.CODE:
|
|
|
+ return "code"
|
|
|
+ else:
|
|
|
+ assert(False)
|
|
|
+
|
|
|
+ def __init__(self, offset_begin, offset_end, group):
|
|
|
+ self.begin = offset_begin
|
|
|
+ self.end = offset_end
|
|
|
+ self.group = group
|
|
|
+
|
|
|
+ def get_offset_begin(self):
|
|
|
+ return self.begin
|
|
|
+
|
|
|
+ def get_offset_end(self):
|
|
|
+ return self.end
|
|
|
+
|
|
|
+ def get_type(self):
|
|
|
+ return self.group
|
|
|
+
|
|
|
+
|
|
|
+class BasePlugin(object):
|
|
|
+
|
|
|
+ def initialize(self):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def terminate(self):
|
|
|
+ pass
|
|
|
|
|
|
+ def set_name(self, name):
|
|
|
+ self.name = name
|
|
|
+
|
|
|
+ def get_name(self):
|
|
|
+ if hasattr(self, 'name') == False:
|
|
|
+ return None
|
|
|
+ return self.name
|
|
|
+
|
|
|
+ def set_version(self, version):
|
|
|
+ self.version = version
|
|
|
+
|
|
|
+ def get_version(self):
|
|
|
+ if hasattr(self, 'version') == False:
|
|
|
+ return None
|
|
|
+ return self.version
|
|
|
+
|
|
|
+ def set_plugin_loader(self, loader):
|
|
|
+ self.plugin_loader = loader
|
|
|
+
|
|
|
+ def get_plugin_loader(self):
|
|
|
+ if hasattr(self, 'plugin_loader') == False:
|
|
|
+ return None
|
|
|
+ return self.plugin_loader
|
|
|
+
|
|
|
+class Plugin(BasePlugin):
|
|
|
+
|
|
|
class Field(object):
|
|
|
def __init__(self, name, ftype, non_zero=False):
|
|
|
self.name = name
|
|
@@ -31,8 +102,13 @@ class Plugin(object):
|
|
|
self.value = value
|
|
|
|
|
|
def initialize(self, namespace=None, support_regions=True, fields=[], properties=[]):
|
|
|
- self.is_updated = False
|
|
|
+ super(Plugin, self).initialize()
|
|
|
+
|
|
|
+ if hasattr(self, 'is_updated') == False:
|
|
|
+ self.is_updated = False # original initialization
|
|
|
+
|
|
|
db_loader = self.get_plugin_loader().get_database_loader()
|
|
|
+
|
|
|
if namespace == None:
|
|
|
namespace = self.get_name()
|
|
|
|
|
@@ -57,36 +133,54 @@ class Plugin(object):
|
|
|
# if field is created (not cloned from the previous db),
|
|
|
# mark the plug-in as updated in order to trigger full rescan
|
|
|
self.is_updated = self.is_updated or is_created
|
|
|
+
|
|
|
+class MetricPlugin(Plugin):
|
|
|
|
|
|
- def terminate(self):
|
|
|
- pass
|
|
|
+ def add_field(self, is_active, field,
|
|
|
+ pattern_to_search,
|
|
|
+ marker_type_mask=Marker.T.ANY,
|
|
|
+ exclude_subregions=True,
|
|
|
+ merge_markers=False):
|
|
|
+ if hasattr(self, '_fields') == False:
|
|
|
+ self._fields = {}
|
|
|
+ if is_active == True:
|
|
|
+ self._fields[field.name] = (field,
|
|
|
+ marker_type_mask,
|
|
|
+ exclude_subregions,
|
|
|
+ merge_markers,
|
|
|
+ pattern_to_search)
|
|
|
+
|
|
|
+ def is_active(self, field_name = None):
|
|
|
+ if field_name == None:
|
|
|
+ return (len(self._fields.keys()) > 0)
|
|
|
+ return (field_name in self._fields.keys())
|
|
|
|
|
|
- def set_name(self, name):
|
|
|
- self.name = name
|
|
|
-
|
|
|
- def get_name(self):
|
|
|
- if hasattr(self, 'name') == False:
|
|
|
- return None
|
|
|
- return self.name
|
|
|
-
|
|
|
- def set_version(self, version):
|
|
|
- self.version = version
|
|
|
-
|
|
|
- def get_version(self):
|
|
|
- if hasattr(self, 'version') == False:
|
|
|
- return None
|
|
|
- return self.version
|
|
|
-
|
|
|
- def set_plugin_loader(self, loader):
|
|
|
- self.plugin_loader = loader
|
|
|
-
|
|
|
- def get_plugin_loader(self):
|
|
|
- if hasattr(self, 'plugin_loader') == False:
|
|
|
- return None
|
|
|
- return self.plugin_loader
|
|
|
+ def get_fields(self):
|
|
|
+ result = []
|
|
|
+ for key in self._fields.keys():
|
|
|
+ result.append(self._fields[key][0])
|
|
|
+ return result
|
|
|
+
|
|
|
+ def count_if_active(self, field_name, data, namespace=None):
|
|
|
+ if self.is_active(field_name) == False:
|
|
|
+ return
|
|
|
+
|
|
|
+ if namespace == None:
|
|
|
+ namespace = self.get_name()
|
|
|
+
|
|
|
+ field_data = self._fields[field_name]
|
|
|
+ text = data.get_content()
|
|
|
+ for region in data.iterate_regions():
|
|
|
+ count = 0
|
|
|
+ for marker in data.iterate_markers(
|
|
|
+ filter_group = field_data[1],
|
|
|
+ region_id = region.get_id(),
|
|
|
+ exclude_children = field_data[2],
|
|
|
+ merge=field_data[3]):
|
|
|
+ count += len(field_data[4].findall(text, marker.get_offset_begin(), marker.get_offset_end()))
|
|
|
+ region.set_data(namespace, field_name, count)
|
|
|
|
|
|
class InterfaceNotImplemented(Exception):
|
|
|
-
|
|
|
def __init__(self, obj):
|
|
|
import sys
|
|
|
Exception.__init__(self, "Method '"
|
|
@@ -95,10 +189,8 @@ class InterfaceNotImplemented(Exception):
|
|
|
+ str(obj.__class__))
|
|
|
|
|
|
class IConfigurable(object):
|
|
|
-
|
|
|
def configure(self, options):
|
|
|
raise InterfaceNotImplemented(self)
|
|
|
-
|
|
|
def declare_configuration(self, optparser):
|
|
|
raise InterfaceNotImplemented(self)
|
|
|
|
|
@@ -110,6 +202,13 @@ class IParser(object):
|
|
|
def process(self, parent, data, is_updated):
|
|
|
raise InterfaceNotImplemented(self)
|
|
|
|
|
|
+class ICode(object):
|
|
|
+ pass
|
|
|
+
|
|
|
+class ITool(object):
|
|
|
+ def run(self, tool_args):
|
|
|
+ raise InterfaceNotImplemented(self)
|
|
|
+
|
|
|
class CallbackNotImplemented(Exception):
|
|
|
|
|
|
def __init__(self, obj, callback_name):
|
|
@@ -125,6 +224,15 @@ class Child(object):
|
|
|
raise CallbackNotImplemented(self, callback_name)
|
|
|
self.__getattribute__(callback_name)(parent, *args)
|
|
|
|
|
|
+ def subscribe_by_parents_name(self, parent_name, callback_name='callback'):
|
|
|
+ self.get_plugin_loader().get_plugin(parent_name).subscribe(self, callback_name)
|
|
|
+
|
|
|
+ def subscribe_by_parents_interface(self, interface, callback_name='callback'):
|
|
|
+ for plugin in self.get_plugin_loader().iterate_plugins():
|
|
|
+ if isinstance(plugin, interface):
|
|
|
+ plugin.subscribe(self, callback_name)
|
|
|
+
|
|
|
+
|
|
|
class Parent(object):
|
|
|
|
|
|
def init_Parent(self):
|
|
@@ -164,22 +272,6 @@ class ExitError(Exception):
|
|
|
+ reason)
|
|
|
|
|
|
|
|
|
-def subscribe_by_parents_name(parent_name, child, callback_name='callback'):
|
|
|
- child.get_plugin_loader().get_plugin(parent_name).subscribe(child, callback_name)
|
|
|
-
|
|
|
-
|
|
|
-# interfaces for subscription
|
|
|
-class ICode(object):
|
|
|
- pass
|
|
|
|
|
|
-def subscribe_by_parents_interface(interface, child, callback_name='callback'):
|
|
|
- for plugin in child.get_plugin_loader().iterate_plugins():
|
|
|
- if isinstance(plugin, interface):
|
|
|
- plugin.subscribe(child, callback_name)
|
|
|
|
|
|
|
|
|
-class ITool(object):
|
|
|
-
|
|
|
- def run(self, tool_args):
|
|
|
- raise InterfaceNotImplemented(self)
|
|
|
-
|