Travis Griggs Travis Griggs - 1 year ago 93
Python Question

python dbus method for watching a directory change?

I have successfully used the python bindings to

in my dbus mainloop to react to changes in a known single file. But I have a case now, where I'm running a dbus mainloop, and need to do work when a directory changes.

I've played around with the command line tool
inotifywait -m directory
, as well as played with some of the examples provided with pyinotify. What's unclear is how I put the two together. Or if I even should. I could just launch a thread that uses a pipe to run
directly, and then write to a ram file in
which I had established an
to. I'm relatively new to glib/dbus/mainloop, so it's still kind of magic to me.
seems kind of heavy for my purposes, but I'm working from no experience here.

I'm running on Debian Jessie, using python3. I am not looking for anything cross platform.

Answer Source

PyInotify can easily watch a directory:

notifier = pyinotify.Notifier(wm, handler)
wm.add_watch('/tmp', pyinotify.IN_CREATE)

The full tutorial is here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download