summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2014-02-09 21:46:02 +0100
committerJan Pokorný <jpokorny@redhat.com>2014-02-09 21:56:18 +0100
commite4ca64a26cefadb0e159463aac55d3d4410c84c5 (patch)
tree9733f16be57e3b91466bd73b6dbdedae953f8c4b
parent68ddfa35b8cbd5a47efcfbf4870bdc7391bd093e (diff)
downloadclufter-e4ca64a26cefadb0e159463aac55d3d4410c84c5.tar.gz
clufter-e4ca64a26cefadb0e159463aac55d3d4410c84c5.tar.xz
clufter-e4ca64a26cefadb0e159463aac55d3d4410c84c5.zip
plugin_registry/format/filter: new way of "private plugin" marking
using MetaPlugin class in the inheritance hierarchy to mark this fact. Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--filter.py4
-rw-r--r--format.py21
-rw-r--r--formats/simpleconfig.py6
-rw-r--r--plugin_registry.py18
4 files changed, 29 insertions, 20 deletions
diff --git a/filter.py b/filter.py
index 17d8559..23f1598 100644
--- a/filter.py
+++ b/filter.py
@@ -13,7 +13,7 @@ from collections import OrderedDict, defaultdict
from lxml import etree
from .error import ClufterError
-from .plugin_registry import PluginRegistry
+from .plugin_registry import MetaPlugin, PluginRegistry
from .utils import head_tail, hybridproperty, filtervarspop
from .command_context import CommandContext
@@ -102,7 +102,7 @@ def tag_log(s, elem):
return s.format(elem.tag, ', '.join(':'.join(i) for i in elem.items()))
-class XMLFilter(Filter):
+class XMLFilter(Filter, MetaPlugin):
@staticmethod
def _traverse(in_fmt, walk, walk_default=None, et=None,
preprocess=lambda s, n, r: s, proceed=lambda *x: x,
diff --git a/format.py b/format.py
index 843b658..5249fb2 100644
--- a/format.py
+++ b/format.py
@@ -17,7 +17,7 @@ from sys import modules
from lxml import etree
from .error import ClufterError
-from .plugin_registry import PluginRegistry
+from .plugin_registry import MetaPlugin, PluginRegistry
from .utils import classproperty
log = logging.getLogger(__name__)
@@ -30,8 +30,6 @@ class FormatError(ClufterError):
class formats(PluginRegistry):
"""Format registry (to be used as a metaclass for formats)"""
- use_local = True
-
def __init__(cls, name, bases, attrs):
cls._protocols = {}
# protocols merge: top-down through inheritance
@@ -154,6 +152,11 @@ class Format(object):
####
+ native_protocol = 'to-be-defined-in-subclasses'
+
+
+class SimpleFormat(Format, MetaPlugin):
+ """This is what most of the format classes want to subclass"""
native_protocol = 'bytestring'
@producing('bytestring')
@@ -169,7 +172,7 @@ class Format(object):
return filename
-class CompositeFormat(Format):
+class CompositeFormat(Format, MetaPlugin):
"""Quasi-format to stand in place of multiple formats at once
It is intended to build on top of atomic formats (and only these,
@@ -180,7 +183,13 @@ class CompositeFormat(Format):
contained/designated format in isolation, whereas the aggregated
result is then returned.
- See also: Format
+ Note that the semantics implicitly require protocols prescribing
+ the `CompositeFormat` instantiation to also become "composite",
+ i.e., having form like ('composite', ('file', 'file')) instead
+ of mere scalar like 'file' (IOW, whole declaration remains
+ fully "typed").
+
+ See also: Format, SimpleFormat
"""
native_protocol = 'composite' # to be overridden by per-instance one
# XXX: hybridproperty?
@@ -220,7 +229,7 @@ class CompositeFormat(Format):
for f, p, a in zip(self._designed, protocol[1], args))
-class XML(Format):
+class XML(SimpleFormat):
""""Base for XML-based configuration formats"""
@classproperty
def root(self):
diff --git a/formats/simpleconfig.py b/formats/simpleconfig.py
index 436c8fa..72acd3f 100644
--- a/formats/simpleconfig.py
+++ b/formats/simpleconfig.py
@@ -1,14 +1,14 @@
# -*- coding: UTF-8 -*-
-# Copyright 2013 Red Hat, Inc.
+# Copyright 2014 Red Hat, Inc.
# Part of clufter project
# Licensed under GPLv2 (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
"""Structured configuration formats such as corosync.conf"""
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
-from ..format import Format, producing
+from ..format import SimpleFormat
-class simpleconfig(Format):
+class simpleconfig(SimpleFormat):
""""Structured configuration formats such as corosync.conf"""
# yacc-based parser in fence-virt
native_protocol = 'struct'
diff --git a/plugin_registry.py b/plugin_registry.py
index b7e43ab..59a0624 100644
--- a/plugin_registry.py
+++ b/plugin_registry.py
@@ -1,5 +1,5 @@
# -*- coding: UTF-8 -*-
-# Copyright 2013 Red Hat, Inc.
+# Copyright 2014 Red Hat, Inc.
# Part of clufter project
# Licensed under GPLv2 (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
"""Easy (at least for usage) plugin framework"""
@@ -17,6 +17,10 @@ from .utils import classproperty, hybridproperty
log = logging.getLogger(__name__)
+class MetaPlugin(object):
+ """For use in the internal meta-hierarchy as "do not register me" mark"""
+
+
class PluginRegistry(type):
"""Core of simple plugin framework
@@ -40,8 +44,7 @@ class PluginRegistry(type):
# non-API
def __new__(registry, name, bases, attrs):
- if '__metaclass__' not in attrs and (registry.use_local
- or not registry.__module__.startswith(attrs['__module__'])):
+ if '__metaclass__' not in attrs and MetaPlugin not in bases:
# alleged end-use plugin
ret = registry.probe(name, bases, attrs)
else:
@@ -143,8 +146,6 @@ class PluginRegistry(type):
# API
- use_local = False
-
@classmethod
def setup(registry, reset=False):
"""Implicit setup upon first registry involvement or external reset"""
@@ -186,10 +187,9 @@ class PluginRegistry(type):
# filled as a side-effect of meta-magic, see `__new__`
ret.update((n, registry._plugins[n]) for n in path_plugins)
- if registry.use_local:
- # add "built-in" ones
- ret.update((n, p) for n, p in registry._plugins.iteritems()
- if p.__module__ == registry.__module__)
+ # add "built-in" ones
+ ret.update((n, p) for n, p in registry._plugins.iteritems()
+ if MetaPlugin not in p.__bases__)
return ret