summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.py54
-rw-r--r--filter.py14
-rw-r--r--format.py3
-rw-r--r--plugin_registry.py5
4 files changed, 48 insertions, 28 deletions
diff --git a/command.py b/command.py
index d4b244e..aef8598 100644
--- a/command.py
+++ b/command.py
@@ -133,11 +133,12 @@ class Command(object):
filter_backtrack = analysis_acc['filter_backtrack']
terminal_chain = analysis_acc['terminal_chain'][-1]
- assert tuplist(filter_chain)
+ assert tuplist(filter_chain) and filter_chain
# PASSDOWN or FILTERS
pass_through, filter_chain = head_tail(*filter_chain) \
- if isinstance(filter_chain, tuple) \
- and len(filter_chain) > 1 \
+ if len(filter_chain) > 1 \
+ and( not isinstance(filter_chain[0], tuple) \
+ or len(filter_chain[0]) < 2) \
else (None, filter_chain)
for i in filter_chain:
if not i:
@@ -155,22 +156,25 @@ class Command(object):
"filter `{0}' is feeded by `{1}' more than once",
i.__class__.__name__, pass_through.__class__.__name__
)
- common_protocols = sorted(
- reduce(
- set.intersection,
- map(set, (pass_through.out_format._protocols,
- i.in_format._protocols))
- ),
- key=lambda x:
- int(x == pass_through.out_format.native_protocol)
- + int(x == i.in_format.native_protocol)
- )
- if not common_protocols:
- raise CommandError(me,
- "filter `{0}' and its feeder `{1}' have no protocol"
- " in common",
- i.__class__.__name__, pass_through.__class__.__name__
+ common_protocols = None # for when CompositeFormat involved
+ if (hasattr(pass_through.out_format, '_protocols')
+ and hasattr(i.in_format, '_protocols')):
+ common_protocols = sorted(
+ reduce(
+ set.intersection,
+ map(set, (pass_through.out_format._protocols,
+ i.in_format._protocols))
+ ),
+ key=lambda x:
+ int(x == pass_through.out_format.native_protocol)
+ + int(x == i.in_format.native_protocol)
)
+ if not common_protocols:
+ raise CommandError(me,
+ "filter `{0}' and its feeder `{1}' have no protocol"
+ " in common",
+ i.__class__.__name__, pass_through.__class__.__name__
+ )
bt[pass_through] = common_protocols
if i_tail:
# PASSDOWN
@@ -350,6 +354,8 @@ class Command(object):
checked_flat = apply_intercalate((checked,))
for order, proto in filter(lambda (i, x): x,
enumerate(checked_flat)):
+ if proto is zip_empty:
+ continue
raise CommandError(me,
"filter resolution #{0} of {1}: {2}", order + 1,
('input', 'output')[passno],
@@ -387,11 +393,17 @@ class Command(object):
worklist = list(reversed(tailshake(terminal_chain,
partitioner=lambda x:
not (tuplist(x)) or protodecl(x))))
- maxl = sorted(worklist, key=lambda x: len(x[0].__class__.name))[-1][0]
- maxl, unused, tstmp = len(maxl.__class__.name), {}, hex(int(time()))[2:]
+ # if any "EMPTY" (zip_empty) value present, respective class name ~ str
+ maxl = len(sorted(worklist, key=lambda x: len(x[0].__class__.__name__)
+ )[-1][0].__class__.__name__)
+ unused, tstmp = {}, hex(int(time()))[2:]
cmd_ctxt['maxl'] = maxl
while worklist:
- flt, io_decl = worklist.pop()
+ workitem = worklist.pop()
+ if workitem == zip_empty:
+ log.debug("Worklist: EMPTY value observed, skipped")
+ continue
+ flt, io_decl = workitem
io_decl_use = protodictval(io_decl)
io_decl, passout = (io_decl_use, unused if io_decl_use is io_decl
else io_decl)
diff --git a/filter.py b/filter.py
index 4cb66e6..f993c26 100644
--- a/filter.py
+++ b/filter.py
@@ -23,7 +23,7 @@ from lxml import etree
from . import package_name
from .error import ClufterError, ClufterPlainError
-from .format import CompositeFormat, XML
+from .format import CompositeFormat, Format, XML
from .plugin_registry import MetaPlugin, PluginRegistry
from .utils import args2tuple, arg2wrapped, \
filterdict_keep, filterdict_pop, \
@@ -100,10 +100,16 @@ class Filter(object):
def _resolve_formats_composite(formats):
# XXX should rather be implemented by CompositeFormat itself?
composite_onthefly = \
- lambda protocol, *args: \
- CompositeFormat(protocol, formats=formats, *args)
+ lambda protocol, *args, **kwargs: \
+ CompositeFormat(protocol, *args,**dict(kwargs.iteritems(),
+ **{'formats': formats}))
# XXX currently instantiation only (no match for composite classes)
- composite_onthefly.as_instance = composite_onthefly
+ composite_onthefly.as_instance = \
+ lambda *decl_or_instance, **kwargs: \
+ composite_onthefly(('composite', ('native', ) * len(decl_or_instance)),
+ *(di('native') for di in decl_or_instance), **kwargs) \
+ if decl_or_instance and isinstance(decl_or_instance[0], Format)\
+ else composite_onthefly(*decl_or_instance, **kwargs)
composite_onthefly.context = CompositeFormat.context
return composite_onthefly
diff --git a/format.py b/format.py
index 2ecc95f..c1dab77 100644
--- a/format.py
+++ b/format.py
@@ -499,7 +499,8 @@ class CompositeFormat(Format, MetaPlugin):
assert tuplist(protocol[1]) and len(protocol[1]) > 1
assert tuplist(formats) and len(protocol[1]) == len(formats)
assert len(args) == len(formats)
- assert all(p in f._protocols for (f, p) in zip(formats, protocol[1]))
+ assert all(p in f._protocols or p == 'native'
+ for (f, p) in zip(formats, protocol[1]))
self._protocols[protocol] = lambda *_: args # just to pass the assert
self.native_protocol = (self.__class__.native_protocol,
tuple(f.native_protocol for f in formats))
diff --git a/plugin_registry.py b/plugin_registry.py
index 4f504b0..860855c 100644
--- a/plugin_registry.py
+++ b/plugin_registry.py
@@ -1,5 +1,5 @@
# -*- coding: UTF-8 -*-
-# Copyright 2014 Red Hat, Inc.
+# Copyright 2015 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"""
@@ -219,7 +219,7 @@ class PluginRegistry(type):
Returns `{plugin_name: plugin_cls}` mapping of plugins found.
"""
ret = {}
- fname_start_use = args2sgpl(fname_start or '[!_.]')
+ fname_start_use = apply_intercalate(args2sgpl(fname_start or '[!_.]'))
fp = re_compile('|'.join(
translate(fs + '*')
for fs in (pfx.split('-', 1)[0] for pfx in fname_start_use)
@@ -286,6 +286,7 @@ class PluginManager(object):
ret.update(filterdict_remove(to_discover,
fn=lambda x: native_plugins[x],
*native_plugins.keys()))
+ to_discover = apply_intercalate(tuple(to_discover))
if to_discover:
log.debug("Couldn't look up everything: {0}".format(', '.join(
to_discover)))