Package: hooker
Arcane HookerI'm a hooker from Silvermoon City. Let me show you the Arcane way to PythonHooker is a hooking library that tries to simplify event firing and catching.
It gives the ability to plugin creators to create plugins for many different
parts, without having to break the logic in separate destinations, if it's not
needed. The main features include:Event declaration with help message supportWaterfallevents that pass their output as arguments to next hookSimple CLI tool to view all defined events of a project and its help messagesFunctions decorators to hook on eventsDependency requirement for hooks (ahook has to be run beforeb)HOOKER_SCRIPTSenvironmental variable allows to load additional scripts (aka plugins)Wildcard hooks that are fired on all eventsWhen a hook accepts the__retvals__argument, the returned values of the previous
hooks (and the whole hook functions) will be passed into it as anOrderedDictPython 2 compatibility - I'll try to keep that for as long as I canTerminology:Project: A project that uses HookerPlugin: A piece of code that adds functionality to aProjectusinghooksEvent: A name for something thatPluginscan hook on. It is called on specific times
(that theProjectauthor has programmed) so thatPluginscan add functionalityHook: A function that thePlugincreator wrote and is declared as hook using
the@hooker.hookdecorator. Contains at least oneEventname (or none if its a wildcard
hook) and optionallyDependenciesDependency: AHookcan declare to be called after a plugin has run.Dependencycan
include the name(s) of the python module(s) (NOTthe function name) that include hooks
that need to be run before theHookFor documentation check thewikiInstallationpip install -U hookerUsageTo find defined hooks in a project usepython -m hooker <python file/module directory>Example:$ py -m hooker example/crypter/crypter.pypre_open_in: Input file will open. Arguments: path<str>. Return: path<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:6
pre_open_out: Output file will open. Arguments: path<str>. Return: path<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:7
encrypt: Encrypt data. Arguments: data<bytearray>. Return: data<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:8
decrypt: Decrypt data. Arguments: data<bytearray>. Return: data<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:9As a Project Author to use hooker you have to declare an event and then fire itExample:# project.pyimporthookerhooker.EVENTS.append("test","Fired after Hello World is printed")print("Hello World")hooker.EVENTS["test"]()As a Plugin Creator to extend a project using hooker, you have to create a function
using the@hooker.hookdecorator and define the event you want to hook on:Example:# my_plugin.pyimporthooker@hooker.hook("test")defhello():print("Goodbye World")Now to use the plugin, you either have toimportit in the project, or execute the
project using the environment variableHOOKER_SCRIPTSas follows:$ HOOKER_SCRIPTS=my_plugin python project.pyHello World
Goodbye WorldUsed inSatori- The reason this project existswormnest- A Web Server to hide stuffWhile the code is not a mess, I'm using a fair bit of python magic.
The target is to provide the simplest and most convenient API for
both project and plugin authors.If you have a better way to do something, at least open an issue to
discuss it, I'm very interested!Happy Hacking! :)