0

Trying to find out if there any good modules which allow constant monitoring of a directory and as soon as a new file is in there, a number of functions are intiated?

Also actions should not be done on partly transfered files which are coming in via FTP.

ismail
  • 3,652
  • 5
  • 32
  • 47

4 Answers4

1

I'm implementing a cross-platform library called watchdog which may be what you are looking for. It's available at http://github.com/gorakhargosh/watchdog

HTH. =)

GoraKhargosh
  • 1,117
  • 1
  • 7
  • 5
0

You are looking for file system events modules.

Which OS are you running?

(disclaimer: I'm maintaining those two modules)

For other alternatives, you can have a look at pyinotify or gamin, but I have never tried those modules.

Nicolas Dumazet
  • 6,980
  • 23
  • 36
  • Operating system is Linux/Unix , however it should be able to work with unix – ismail Aug 26 '09 at 11:08
  • Generic "unix" does not have such functionality; specific Unix versions often do, but you have to specify which versions (Solaris, HPUX, ?BSD, AIX, ...) and with some you may be out of luck. – Alex Martelli Aug 26 '09 at 14:53
0

In addition to NicDumZ's excellent modules, you may want to consider pyinotify for a rich (and richly documented) alternative. I think Nic's is simpler (at least for basical functionality), but I haven't studied it in detail -- I'm more familiar with pyinotify. BTW, interestingly, the latter is in pure Python (with ctypes of course;-).

Since you did mention "should be able to work with unix", you should specify exactly which unix versions you need to support and study whether they offer similar functionality (and if so through what interface). For example, this man page for inotify says:

The inotify API is Linux specific. Some other systems provide similar mechanisms, e.g., FreeBSD has kqueue, and Solaris has /dev/poll.

and Nic already mentioned FSEvents on MacOSX. Once you determine the C way to do it on a given system of interest, worst case, if there's no pre-made Python version, you can probably use ctypes similarly to the way pyinotify does for inotify. BTW, for completeness: on Windows you might use ReadDirectoryChangesW (typically you'd do that via either ctypes or the win32file file of the Win32 Extensions).

Alex Martelli
  • 762,786
  • 156
  • 1,160
  • 1,345
0

High-level libraries often implement different solutions for each platform they work on. With luck, you only have to use one method -- the high-level library.

See this non-python Question about file monitoring

Specifically, if you can use QT's QFileSystemwatcher with python bindings, or GLib's GFileMonitor (which I use in my application, although it's just for Linux), you might save work.

Community
  • 1
  • 1
u0b34a0f6ae
  • 42,509
  • 13
  • 86
  • 97
  • I'm digging into glib's file system code (called "gio", also as python module "gio" when part of pygobject), and it has implementations in place for inotify and win32, and "fam" which is a polling fallback http://git.gnome.org/cgit/glib/tree/gio – u0b34a0f6ae Aug 26 '09 at 20:01