Commit 24f94fd1 authored by Clément Schreiner's avatar Clément Schreiner
Browse files

Trivial changes.

Comments and cosmetics. Add ``Base`` in debexpo.model.meta.__all__.
parent 6fa2dd2e
......@@ -238,20 +238,28 @@ class Plugins(object):
entity_list.append(result)
#
# magic methods from accessing the ``plugins`` attribute
#
# FIXME: do this properly with collections.abc? (not sure)
def __getitem__(self, key):
"""
Returns a plugin instance for the given plugin name.
plugins['native'] -> NativePlugin instance
"""
return self.plugins.get(key, None)
def iteritems(self):
"""
Iter the items in the ``plugins`` dictionary attribute.
"""
"""Iter the items in the ``plugins`` dictionary attribute."""
return self.plugins.iteritems()
def __len__(self):
"""Number of plugins that have been loaded."""
return len(self.plugins)
def __iter__(self):
""" Iter over plugin instances """
for plugin in self.plugins.values():
yield plugin
......@@ -39,7 +39,7 @@ from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base
__all__ = ['engine', 'metadata', 'session']
__all__ = ['engine', 'metadata', 'session', 'Base']
# SQLAlchemy database engine. Updated by model.init_model().
engine = None
......@@ -52,3 +52,4 @@ session = None
metadata = MetaData()
Base = declarative_base(metadata=metadata)
......@@ -45,6 +45,10 @@ class PluginResult(meta.Base):
# plugin that created the result: to be defined in subclasses
plugin = None
#
# Table columns
#
id = sa.Column(sa.types.Integer, primary_key=True)
entity = sa.Column(sa.types.String(200))
package_version_id = sa.Column(sa.types.Integer,
......@@ -52,15 +56,25 @@ class PluginResult(meta.Base):
nullable=False)
package_version = orm.relationship(PackageVersion, backref='plugin_results')
_data = association_proxy('_result_data', 'value',
creator = lambda k, v: PluginResultData(key = k,
value = v),
)
_data = association_proxy(
'_result_data', 'value',
creator = lambda k, v: PluginResultData(key = k, value = v))
__mapper_args__ = {'polymorphic_on': entity}
#
# Polymorphism configuration
#
# FIXME: inherit MutableMapping or something to provide a complete
#
# Quacking like a dict (but not really)
#
# FIXME: inherit MutableMapping or something and provide a complete
# dictionary-like interface
def __getitem__(self, key):
return self._data[key]
......@@ -73,6 +87,10 @@ class PluginResult(meta.Base):
def __delitem__(self, key):
del self._data[key]
#
# Direct access to some attributes (for templates)
#
@property
def severity(self):
return int(self.get('severity', 0))
......
......@@ -166,9 +166,10 @@ class QAPlugin(BasePlugin):
QA plugins have a the concept of a test that can be passed or
failed.
Also, their templates look alike and can be abstracted. 'tests
results' can be considered the main result, with other results
giving complementary information.
Also, their templates look alike and could be abstracted
(i.e. having a standard 'simple test template' that work sith any
SimpleTestPlugin's results. 'tests results' can be considered the
main result, with other results giving complementary information.
The ``test_entity`` class attribute must be set the
PluginResult-class which represents this test result.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment