From 6620ab381834018a65c66bf3dd9ab4b6d4527487 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sun, 19 Aug 2012 00:38:04 +0100 Subject: Pre/Posthooks are no longer Command.__init__ parms but are directly set to cmd.pre/posthook by commandfactory. This still means that these hooks are looked up and stored *in* the cmd obj in the factory: so whenever FooCommand is instanciated from within some other commands apply, the hooks are None. --- alot/commands/__init__.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'alot/commands/__init__.py') diff --git a/alot/commands/__init__.py b/alot/commands/__init__.py index d3a052d0..2fd61b84 100644 --- a/alot/commands/__init__.py +++ b/alot/commands/__init__.py @@ -14,17 +14,9 @@ from alot.helper import split_commandstring class Command(object): """base class for commands""" - def __init__(self, prehook=None, posthook=None): - """ - :param prehook: name of the hook to call directly before - applying this command - :type prehook: str - :param posthook: name of the hook to call directly after - applying this command - :type posthook: str - """ - self.prehook = prehook - self.posthook = posthook + def __init__(self): + self.prehook = None + self.posthook = None self.undoable = False self.help = self.__doc__ @@ -191,17 +183,20 @@ def commandfactory(cmdline, mode='global'): parms = vars(parser.parse_args(args)) parms.update(forcedparms) - logging.debug('PARMS: %s' % parms) + + logging.debug('cmd parms %s' % parms) + + # create Command + cmd = cmdclass(**parms) # set pre and post command hooks get_hook = settings.get_hook - parms['prehook'] = get_hook('pre_%s_%s' % (mode, cmdname)) or \ + cmd.prehook = get_hook('pre_%s_%s' % (mode, cmdname)) or \ get_hook('pre_global_%s' % cmdname) - parms['posthook'] = get_hook('post_%s_%s' % (mode, cmdname)) or \ + cmd.posthook = get_hook('post_%s_%s' % (mode, cmdname)) or \ get_hook('post_global_%s' % cmdname) - logging.debug('cmd parms %s' % parms) - return cmdclass(**parms) + return cmd pyfiles = glob.glob1(os.path.dirname(__file__), '*.py') -- cgit v1.2.3