Package gofer :: Module pmon :: Class PathMonitor
[hide private]
[frames] | no frames]

Class PathMonitor

source code

Path monitor.

Instance Methods [hide private]
 
__init__(self) source code
 
add(self, path, cb)
Add a path to be monitored.
source code
 
delete(self, path)
Delete a path to be monitored.
source code
PathMonitor
start(self, precision=1)
Start the monitor thread.
source code
 
join(self)
Join the monitoring thread.
source code
 
check(self)
Check paths and notify.
source code
 
__sniff(self, path, stat)
Sniff and compare the stats of the file at the specified path.
source code
 
__notify(self, path, cb)
Safely invoke registered callback.
source code
 
__lock(self) source code
 
__unlock(self) source code
Instance Variables [hide private]
RLock __mutex
The mutex.
dict path:(mtime, digest, cb) __paths
A list of paths to monitor.
Thread __thread
The optional thread.
Method Details [hide private]

add(self, path, cb)

source code 

Add a path to be monitored.

Parameters:
  • path (str) - An absolute path to monitor.
  • cb (callable) - A listener.

delete(self, path)

source code 

Delete a path to be monitored.

Parameters:
  • path (str) - An absolute path to monitor.

start(self, precision=1)

source code 

Start the monitor thread.

Parameters:
  • precision (float) - The precision (how often to check).
Returns: PathMonitor
self

__sniff(self, path, stat)

source code 

Sniff and compare the stats of the file at the specified path. First, check the modification time, if different, then check the hash of the file content to see if it really changed. If changed, notify the registered listener.

Parameters:
  • path (str) - The path of the file to sniff.
  • stat (tuple) - The cached stat (mtime, digest, cb)

__notify(self, path, cb)

source code 

Safely invoke registered callback.

Parameters:
  • path (str) - The path of the changed file.
  • cb (callable) - A registered callback.

Instance Variable Details [hide private]

__thread

The optional thread. see: start().
Type:
Thread