PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

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