Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiaq/udevedu
udevedu: udev Event Dispatcher for Unprivileged user
https://github.com/xiaq/udevedu
Last synced: 2 months ago
JSON representation
udevedu: udev Event Dispatcher for Unprivileged user
- Host: GitHub
- URL: https://github.com/xiaq/udevedu
- Owner: xiaq
- Created: 2013-11-26T09:56:38.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-03-25T16:04:26.000Z (almost 9 years ago)
- Last Synced: 2023-03-24T19:03:05.790Z (almost 2 years ago)
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 21
- Watchers: 5
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# udevedu: udev Event Dispatcher for Unprivileged user
udevedu is a little tool that allows you to call a Python function on udev
events.## Usage
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 `$PATH`.)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: `init`, `check` and `react`.
They are all optional.`init` function is called after udevedu has started and collected all hook
scripts.`check` and `react` is called when a udev event is received. If `check`
doesn't exist or returns a true value, `react` is called. Both are passed two
positional arguments, `action` and `device` which come from
[pyudev.Monitor.receive_device](http://pyudev.readthedocs.org/en/latest/api/pyudev.html#pyudev.Monitor.receive_device).Notes:
* `check` is actually not necessary, but it would save you one level of
indentation.
* `check` and `react` are called off the main thread, so that they may block.## Why not just write [udev rules](http://www.freedesktop.org/software/systemd/man/udev.html)?
Because udevedu runs as an unprivileged user in arbitrary environment - e.g.
from your WM script so that it can call `xset`, `notify-send` etc.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](http://pyudev.readthedocs.org/) 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 `check` or `react`
function.## TODO
* Automatic reload of hook scripts
* `pyudev.Monitor.receive_device` is deprecated, should use new interface;
maybe also use the asynchronous `pyudev.MonitorObserver`?