Adds a function to be called for hook of a given name.

        The function gets entire workspace as input and
        does not return anything.

        Example:
        def hook_fcn(workspace):
            pass
512472
def add_hook(self, name, function):
        
        if not callable(function):
            return ValueError('Hook function should be callable')
        if name not in self.hooks:
            self.hooks[name] = []
        self.hooks[name].append(function)
        return self
151481
def get_function(self, name: str) -> AbiFunction or None:
        
        for func in self.functions:
            if func['name'] == name:
                return AbiFunction(func['name'], func['parameters'], func.get('returntype', ''))
        return None
1235556
def callHook(self, hookname, *args, **kwargs):
        ''
        r = []
        for f in self.hooks[hookname]:
            try:
                r.append(f(*args, **kwargs))
            except Exception as e:
                exceptionCaught(e)
        return r
1268774
def call_hook(self, hook, *args, **kwargs):
        
        for function in self.hooks[hook]:
            function.__call__(*args, **kwargs)
226030
def add_plugin(self, f):
        
        if f.endswith('.py'):

            # Just the basename without extension
            plugin_name = os.path.splitext(os.path.basename(f))[0]

            # It's possible the plugin has been modified and needs to be reloaded
            if plugin_name in sys.modules:
                try:
                    handler = reload(sys.modules[plugin_name])
                    print'\t- %s %sRELOAD%s' % (plugin_name, color.Yellow, color.Normal)
                except ImportError, error:
                    print 'Failed to import plugin: %s (%s)' % (plugin_name, error)
                    return
            else:
                # Not already loaded so try to import it
                try:
                    handler = __import__(plugin_name, globals(), locals(), [], -1)
                except ImportError, error:
                    print 'Failed to import plugin: %s (%s)' % (plugin_name, error)
                    return

            # Run the handler through plugin validation
            plugin = self.validate(handler)
            print '\t- %s %sOK%s' % (plugin_name, color.Green, color.Normal)
            if plugin:

                # Okay must be successfully loaded so capture the plugin meta-data,
                # modification time and register the plugin through the callback
                plugin['name'] = plugin_name
                plugin['dependencies'] = plugin['class'].dependencies
                plugin['docstring'] = plugin['class'].__doc__
                plugin['mod_time'] = datetime.utcfromtimestamp(os.path.getmtime(f))

                # Plugin may accept sample_sets as input
                try:
                    plugin['sample_set_input'] = getattr(plugin['class'], 'sample_set_input')
                except AttributeError:
                    plugin['sample_set_input'] = False

                # Now pass the plugin back to workbench
                self.plugin_callback(plugin)
506233
def _get_function(self, name: str):
        
        f = mapped.get(name)

        if f is None:
            raise MissingPipelineFunctionError('{} is not registered as a pipeline function'.format(name))

        if name in universe_map and name in in_place_map:
            return self._wrap_in_place(self._wrap_universe(f))

        if name in universe_map:
            return self._wrap_universe(f)

        if name in in_place_map:
            return self._wrap_in_place(f)

        return f
532033
def add_hook(hook, &block)
      fail ArgumentError, "Invalid hook `#{hook}'" unless\
        HOOKS.keys.include? hook
      fail ArgumentError, 'Block require' unless block_given?
      options[hook] = block
    end
997166
def pass_context(f):
    
    def new_func(*args, **kwargs):
        return f(get_current_context(), *args, **kwargs)
    return update_wrapper(new_func, f)
993937
def function(self, rule, args, **kwargs):
        
        fname = rule.function
        try:
            return self.functions[fname](args)
        except KeyError:
            raise FilteringRuleException("Invalid function name '{}'".format(fname))
971104
def post_run_hook(self, func, prefix=None):
        
        cf = self.capture(func, prefix=prefix)
        self.post_run_hooks.append(cf)
        return cf
1041807
def add(self, fn, name=None):
        
        if not name:
            name = fn.__name__
        self.functions[name] = fn
304084
def register_hook(self, hook_name, fn):
        """"""
        if hook_name not in self._hooks:
            self._hooks[hook_name] = fn
        else:
            raise Exception('%s hook already registered' % hook_name)
389403
def add_hook(self, hook):
        
        h = hook.hash
        self.hooks[h] = hook
476644
def register_function_hooks(self, func):
        """"""
        for hook_kind, hooks in func.xworkflows_hook.items():
            for field_name, hook in hooks:
                if field_name and field_name != self.state_field:
                    continue
                for transition in self.workflow.transitions:
                    if hook.applies_to(transition):
                        implem = self.implementations[transition.name]
                        implem.add_hook(hook)
12082
def function(fname):
    
    def _f(func):
        class WrapFunction(Function):
            name = fname

            def __call__(self, *args, **kwargs):
                return func(*args, **kwargs)

        return WrapFunction

    return _f
538642
def add_function(self,
                     fun=None,
                     name=None,
                     fun_type=FUN_TYPE):
        """"""
        if not name:
            if six.PY2:
                name = fun.func_name
            else:
                name = fun.__name__

        self.say('adding fun(%s)' % name, verbosity=50)
        self.say('adding fun_type:%s' % fun_type, verbosity=50)

        if self.function_exists(name):
            self.cry('overwriting :fun(%s)' % name, verbosity=10)

        self.say('added :' + name, verbosity=10)
        self._rule_functions[name] = RuleFunction(name, fun, fun_type)
        return True
1082339
def get_hook(self, name):
        
        assert isinstance(name, (str, unicode)), name
        headers, attributes = self.__requester.requestJsonAndCheck(
            "GET",
            "/hooks/" + name
        )
        return HookDescription.HookDescription(self.__requester, headers, attributes, completed=True)