예제 #1
0
    def callHook(self, name, *args, **kwargs):
	"""Call all hook functions for a given soho hook name."""
	from IFDapi import ray_comment

	hooks = self.hooks.get(name, ())

	for hook in hooks:
	    try:
		result = hook(*args, **kwargs)

	    except Exception as e:
		ray_comment(
		    "Hook Error[{0}]: {1}".format(name, str(e))
		)

		ray_comment(
		    "Traceback:\n# {0}\n".format(
			    "\n#".join(traceback.format_exc().split('\n'))
		    )
		)

	    else:
		if result:
		    return True

	return False
예제 #2
0
    def callHook(self, name, *args, **kwargs):
        """Call all hook functions for a given soho hook name."""
        from IFDapi import ray_comment

        hooks = self.hooks.get(name, ())

        for hook in hooks:
            try:
                result = hook(*args, **kwargs)

            except Exception as e:
                ray_comment(
                    "Hook Error[{}]: {}".format(name, str(e))
                )

                ray_comment(
                    "Traceback:\n# {}\n".format(
                            "\n#".join(traceback.format_exc().split('\n'))
                    )
                )

            else:
                if result:
                    return True

        return False
예제 #3
0
    def call_hook(self, name, *args, **kwargs):
        """Call all hook functions for a given soho hook name.

        :param name: The name of the hook to call.
        :type name: str
        :return: Whether or not the hooks succeeded.
        :rtypeL bool

        """
        from IFDapi import ray_comment

        # Get a list of hooks to call.
        hooks = self.hooks.get(name, ())

        return_value = False

        for hook in hooks:
            try:
                result = hook(*args, **kwargs)

            # Catch any exceptions and 'log' them to the ifd via comments.
            except Exception as inst:  # pylint: disable=broad-except
                ray_comment("Hook Error[{}]: {}".format(name, inst))

                ray_comment("Traceback:\n# {}\n".format("\n#".join(
                    traceback.format_exc().split('\n'))))

            else:
                if result:
                    return_value = True

        return return_value
예제 #4
0
def call(hookName="", *args, **kwargs):
    """Hook callback function.

    Args:
        hookName="" : (str)
            SOHO hook function name.

        args : (list)
            Arguments passed to the hook function call.

        kwargs : (dict)
            Keyword arguments passed to the hook function call.

    Raises:
        N/A

    Returns:
        bool
            The result of the hook call.

    """
    # Try to get methods to call for this hook.
    methods = _HOOK_FUNCTIONS.get(hookName, ())

    result = False

    for method in methods:
        # Try to call the function.
        try:
            result = method(*args, **kwargs)

        # Catch any exceptions.
        except Exception as e:
            # Write error information into the ifd.
            ray_comment("Hook Error[{0}]: {1} {2}".format(
                hookName, __file__, str(e)))

            ray_comment("Traceback:\n# {0}\n".format("\n#".join(
                traceback.format_exc().split('\n'))))

        if result:
            return True

    return False
예제 #5
0
def call(hookName="", *args, **kwargs):
    """Hook callback function.

    Args:
        hookName="" : (str)
            SOHO hook function name.

        args : (list)
            Arguments passed to the hook function call.

        kwargs : (dict)
            Keyword arguments passed to the hook function call.

    Raises:
        N/A

    Returns:
        bool
            The result of the hook call.

    """
    # Try to get methods to call for this hook.
    methods = _HOOK_FUNCTIONS.get(hookName, ())

    result = False

    for method in methods:
        # Try to call the function.
        try:
            result = method(*args, **kwargs)

        # Catch any exceptions.
        except Exception as e:
            # Write error information into the ifd.
            ray_comment("Hook Error[{0}]: {1} {2}".format(hookName, __file__, str(e)))

            ray_comment("Traceback:\n# {0}\n".format("\n#".join(traceback.format_exc().split("\n"))))

        if result:
            return True

    return False