/examples/dirwatch.py
https://bitbucket.org/prologic/circuits/ · Python · 37 lines · 13 code · 13 blank · 11 comment · 0 complexity · d70d9e1c385aa0578a11cff3dc70e838 MD5 · raw file
- #!/usr/bin/env python
- """Directory Watch Example
- This example demonstrates the inotify I/O Component ``Notify`` which can
- be used for real-time monitoring of file system events. The example simply
- takes a path to watch as the first Command Line Argument and prints to
- stdour every file system event it sees.
- """
- import sys
- from circuits import Component
- from circuits.io import Notify
- class FileWatcher(Component):
- channel = "notify"
- def opened(self, filename, path, fullpath, isdir):
- print("File {0:s} opened".format(filename))
- def closed(self, filename, path, fullpath, isdir):
- print("File {0:s} closed".format(filename))
- # Configure the system
- app = Notify()
- FileWatcher().register(app)
- # Add the path to watch
- app.add_path(sys.argv[1])
- # Run the system
- app.run()