Reputation: 290
As the title states i need to watch a directory for changes(mainly for file additions) using python
I stumble upon a few solutions here but none of them work properly
1.One solution was using "fcntl", I tried it on my system but it failed with an error "no attribute F_SETSIG".Googling it resulted in nothing useful
2.Python module Watchdog fails to install as i don't have xcode, which i don't want to download(too big to download and lots of unnecessary things for such small work)
The accepted solution was windows specific and none of others work on osx without big packages
So in the end I don't want any solutions involving XCODE, PyQT, polling, busy loop(i.e. checking DIR every few seconds)
Applescripts support this by default, so I think python should too without any big modules/packages
I am using OS X 10.7.2 and python 2.7.3 by the way
Thanks in advance
Upvotes: 0
Views: 2007
Reputation: 92657
I use watchdog right now on osx. It works great. Install xcode. Or just the command line tools for the compilers.
You can install the gcc compiler without xcode: https://github.com/kennethreitz/osx-gcc-installer
If you really want an applescript approach you can use the python bindings appscript: http://appscript.sourceforge.net/py-appscript/index.html
I use those too and they work great.
So in the end I don't want any solutions involving XCODE, PyQT, polling, busy loop(i.e. checking DIR every few seconds)
Basically you are saying you dont want anything at all. Any solution is going to use a form of polling. Whether its system triggered or app busy loop. You just need to take a second to install the compilers to use the solution of your choice.
Upvotes: 0
Reputation: 400672
The API you want to be using is the FSEvents API. Python doesn't ship with bindings to that API, so you'll need to either make your own bindings or use a library such as MacFSEvents or python-watchdog. However you really should just install Xcode -- these libraries require compiling the C bindings, and Xcode is the easiest way to get a C compiler.
If you really want to avoid Xcode, you could roll your own bindings using the ctypes module, but that's going to be a big pain in the neck.
Applescripts support this by default, so I think python should too without any big modules/packages
Tough luck. The various 3rd-party libraries which are available are not that big, they just need a C compiler to work.
Upvotes: 1