diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-01-24 18:02:42 +0100 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-01-24 18:02:42 +0100 |
commit | ce201e6299a08fe29fe0e4af3d8b2a30f4f67b2c (patch) | |
tree | 414c8aa079b8d285c32ba00ea6ecd4c094b7c8ba | |
parent | fa0a0f7f7bc95ef869aec822cc55af76946bed97 (diff) | |
download | clufter-ce201e6299a08fe29fe0e4af3d8b2a30f4f67b2c.tar.gz clufter-ce201e6299a08fe29fe0e4af3d8b2a30f4f67b2c.tar.xz clufter-ce201e6299a08fe29fe0e4af3d8b2a30f4f67b2c.zip |
Finalize basic command manager's responsibilities
...pushing the generic processing to be implemented further to the
command itself.
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r-- | command.py | 25 | ||||
-rw-r--r-- | command_manager.py | 5 |
2 files changed, 29 insertions, 1 deletions
@@ -10,6 +10,7 @@ from optparse import make_option, SUPPRESS_HELP from .plugin_registry import PluginRegistry from .utils import ClufterError, \ + EC, \ func_defaults_varnames, \ head_tail, \ hybridproperty @@ -98,6 +99,30 @@ class Command(object): """Chain of filter identifiers/classes for the command""" return this._filter_chain + def __call__(self, opts, args=None): + """Proceed the command""" + ec = EC.EXIT_SUCCESS + fnc_defaults, fnc_varnames = self._figure_func_defaults_varnames() + kwargs = {} + for v in fnc_varnames: + if hasattr(opts, v): + kwargs[v] = getattr(opts, v) + format_chain = self._fnc(**kwargs) + ##print format_chain + ##from .utils import apply_aggregation_preserving_passing_depth + ##print apply_aggregation_preserving_passing_depth( + ## lambda x, d: ('\n' + d * ' ') + (' ').join(x) + ##)(format_chain) + # 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? + # - perform the chain + # - [advanced] threading for parallel branches? + return ec + @classmethod def deco(cls, *filter_chain): """Decorator as an easy factory of actual commands""" diff --git a/command_manager.py b/command_manager.py index dfd28f2..389c843 100644 --- a/command_manager.py +++ b/command_manager.py @@ -90,7 +90,10 @@ class CommandManager(PluginManager): )) print parser.format_customized_help(usage=usage) return ec - print opts, args # TODO + logging.getLogger().setLevel(opts.loglevel) + log.debug("Running command `{0}'; opts={1}, args={2}" + .format(cmd, opts.__dict__, args)) + ec = command(opts, args) except ClufterError as e: ec = EC.EXIT_FAILURE print e |