/examples/dirwatch.py

https://bitbucket.org/prologic/circuits/ · Python · 37 lines · 13 code · 13 blank · 11 comment · 0 complexity · d70d9e1c385aa0578a11cff3dc70e838 MD5 · raw file

  1. #!/usr/bin/env python
  2. """Directory Watch Example
  3. This example demonstrates the inotify I/O Component ``Notify`` which can
  4. be used for real-time monitoring of file system events. The example simply
  5. takes a path to watch as the first Command Line Argument and prints to
  6. stdour every file system event it sees.
  7. """
  8. import sys
  9. from circuits import Component
  10. from circuits.io import Notify
  11. class FileWatcher(Component):
  12. channel = "notify"
  13. def opened(self, filename, path, fullpath, isdir):
  14. print("File {0:s} opened".format(filename))
  15. def closed(self, filename, path, fullpath, isdir):
  16. print("File {0:s} closed".format(filename))
  17. # Configure the system
  18. app = Notify()
  19. FileWatcher().register(app)
  20. # Add the path to watch
  21. app.add_path(sys.argv[1])
  22. # Run the system
  23. app.run()