diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-01-20 09:58:48 +0100 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-01-20 10:03:40 +0100 |
commit | dc1842974a40b1a537a3fc812c473a1b9c447602 (patch) | |
tree | e366b3a3a42710f625adbc35f4cdf36fb35db434 /command_manager.py | |
parent | 318c60a2bba180a9af0e86484f14ea50f8266d94 (diff) | |
download | clufter-dc1842974a40b1a537a3fc812c473a1b9c447602.tar.gz clufter-dc1842974a40b1a537a3fc812c473a1b9c447602.tar.xz clufter-dc1842974a40b1a537a3fc812c473a1b9c447602.zip |
command_manager: initial plugins registration (ala filter_manager)
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'command_manager.py')
-rw-r--r-- | command_manager.py | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/command_manager.py b/command_manager.py index f17b18d..9229598 100644 --- a/command_manager.py +++ b/command_manager.py @@ -9,6 +9,9 @@ import logging from .command import commands from .plugin_registry import PluginManager +from .utils import apply_preserving_depth, \ + apply_aggregation_preserving_depth, \ + apply_intercalate log = logging.getLogger(__name__) @@ -17,13 +20,41 @@ class CommandManager(PluginManager): """Class responsible for commands routing to filters or other actions""" _default_registry = commands - def _handle_plugins(self, commands): - self._commands = commands + def _handle_plugins(self, commands, flt_mgr): + log.debug("Commands before resolving: {0}" + .format(commands)) + self._commands = self._resolve(flt_mgr.filters, commands) + + @staticmethod + def _resolve(filters, commands): + for cmd_name, cmd_cls in commands.items(): + res_input = cmd_cls.filter_chain + res_output = apply_preserving_depth(filters.get)(res_input) + if apply_aggregation_preserving_depth(all)(res_output): + log.debug("resolve at `{0}' command: `{1}' -> {2}" + .format(cmd_name, repr(res_input), repr(res_output))) + commands[cmd_name] = cmd_cls(*res_output) + continue + # drop the command if cannot resolve any of the filters + res_input = apply_intercalate(res_input) + log.debug("cmd_name {0}".format(res_input)) + map(lambda (i, x): log.warning("Resolve at `{0}' command:" + " `{1}' (#{2}) filter fail" + .format(cmd_name, res_input[i], i)), + filter(lambda (i, x): not(x), + enumerate(apply_intercalate(res_output)))) + commands.pop(cmd_name) + return commands @property def commands(self): return self._commands.copy() def __call__(self, args): - pass - # self.filter_manager(string) + # 1. figure out commands + inject artificial ones (help) + #print self.commands + raise NotImplementedError + # commands = + # 2. check if command matches define ones (or none = default?) + # 2a. success -> pass further (TODO) + # 2b. failure -> print help/diagnostics |