udevedu: udev Event Dispatcher for Unprivileged user
udevedu is a little tool that allows you to call a Python function on udev events.
To install, run:
sudo pip install . A script named
udevedu will be put in
/usr/bin. (You can also do
pip install --user ., which will put the script
~/.local/bin, and you need to take care to add that to your
Put hooks in
~/.config/udevedu/hooks, which will be created the first time
udevedu is invoked. Some sample hooks (read: hooks used by me, xiaq) are
contained in the
hook/ directory of the repository.
Anatomy of hook scripts
Three functions are looked for in hook scripts:
They are all optional.
init function is called after udevedu has started and collected all hook
react is called when a udev event is received. If
doesn't exist or returns a true value,
react is called. Both are passed two
device which come from
checkis actually not necessary, but it would save you one level of indentation.
reactare called off the main thread, so that they may block.
Because udevedu runs as an unprivileged user in arbitrary environment - e.g.
from your WM script so that it can call
Other small bonuses:
- You don't need to learn yet another arcane configuration language - the information of the event is available as easy-to-use pyudev objects
- Hook functions are executed in separate threads, so that one blocking hook doesn't affect other hooks
- It's also much easier to experiment and debug - just put
from pdb import set_trace; set_trace()anywhere in the
Automatic reload of hook scripts
pyudev.Monitor.receive_deviceis deprecated, should use new interface; maybe also use the asynchronous