diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-01-27 23:04:12 +0100 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-01-27 23:17:41 +0100 |
commit | c33694ac035fe2915c3aa4d39f430ad7d0de753b (patch) | |
tree | a3004a0eef0acff456d6b8a402a79adbb62386ce /command.py | |
parent | abfb91d87a57970315504508dd094b9f5cdba489 (diff) | |
download | clufter-c33694ac035fe2915c3aa4d39f430ad7d0de753b.tar.gz clufter-c33694ac035fe2915c3aa4d39f430ad7d0de753b.tar.xz clufter-c33694ac035fe2915c3aa4d39f430ad7d0de753b.zip |
command: implement "shapes" match for filter/format chain
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'command.py')
-rw-r--r-- | command.py | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -10,8 +10,12 @@ from optparse import make_option, SUPPRESS_HELP from .error import ClufterError, \ EC +from .filter import Filter from .plugin_registry import PluginRegistry -from .utils import func_defaults_varnames, \ +from .utils import apply_aggregation_preserving_depth, \ + apply_intercalate, \ + apply_strict_zip_preserving_depth, \ + func_defaults_varnames, \ head_tail, \ hybridproperty @@ -113,9 +117,32 @@ class Command(object): ##print apply_aggregation_preserving_passing_depth( ## lambda x, d: ('\n' + d * ' ') + (' ').join(x) ##)(format_chain) + # validate format_chain vs chain + # 1. "shapes" match + check_input, check_output = head_tail( + *apply_strict_zip_preserving_depth(self.filter_chain, format_chain) + ) + checked_input = apply_aggregation_preserving_depth( + lambda i: + head_tail(*i[1])[0] not in i[0].in_format._protocols + and head_tail(*i[1])[0] or None + if len(i) == 2 and isinstance(i[0], Filter) + else i if any(i) else None + )(check_input) + checked_output = apply_aggregation_preserving_depth( + lambda i: + head_tail(*i[1])[0] not in i[0].out_format._protocols + and head_tail(*i[1])[0] or None + if len(i) == 2 and isinstance(i[0], Filter) + else i if any(i) else None + )(check_output) + for passno, checked in enumerate((checked_input, checked_output)): + for order, cmd in filter(lambda (i, x): x, + enumerate(apply_intercalate((checked,)))): + raise CommandError(self, "filter resolution at #{0} of {1}:" + " `{2}' protocol not recognized", order + 1, + ('input', 'output')[passno], cmd) # TODO - # - validate format_chain vs chain - # 1. "shapes" match # 2. I/O formats path(s) through the graph exist(s) # 3. some per-filter validations? # - could some initial steps be done earlier? |