Package flumotion :: Package component :: Package base :: Module watcher :: Class BaseWatcher
[hide private]

Class BaseWatcher

source code

extern.log.log.Loggable --+
                          |
                         BaseWatcher
Known Subclasses:

I watch for file changes.

I am a base class for a file watcher. I can be specialized to watch any set of files.

Instance Methods [hide private]
 
__init__(self, timeout)
Make a file watcher object.
source code
 
_reset(self) source code
 
_subscribe(self, **events)
Subscribe to events.
source code
 
subscribe(self, fileChanged=None, fileDeleted=None)
Subscribe to events.
source code
 
unsubscribe(self, id)
Unsubscribe from file change notifications.
source code
 
event(self, event, *args, **kwargs)
Fire an event.
source code
 
start(self)
Start checking for file changes.
source code
 
stop(self)
Stop checking for file changes.
source code
 
getFileData(self)
Returns: a dict, {filename => DATA} DATA can be anything.
source code
bool
isNewFileStable(self, fName, fData)
Check if the file is already stable when being added to the set of watched files.
source code
 
getFilesToStat(self)
Returns: sequence of filename
source code

Inherited from extern.log.log.Loggable: __providedBy__, debug, doLog, error, info, log, logFunction, logObjectName, warning, warningFailure, writeMarker

Class Variables [hide private]

Inherited from extern.log.log.Loggable: __implemented__, __provides__, logCategory

Method Details [hide private]

__init__(self, timeout)
(Constructor)

source code 

Make a file watcher object.

Parameters:
  • timeout (int) - timeout between checks, in seconds

_subscribe(self, **events)

source code 

Subscribe to events.

Parameters:
  • events - The events to subscribe to. Subclasses are expected to formalize this dict, specifying which events they support via declaring their kwargs explicitly.
Returns:
A subscription ID that can later be passed to unsubscribe().

subscribe(self, fileChanged=None, fileDeleted=None)

source code 

Subscribe to events.

Parameters:
  • fileChanged (filename -> None) - A function to call when a file changes. This function will only be called if the file's details (size, mtime) do not change during the timeout period.
  • fileDeleted (filename -> None) - A function to call when a file is deleted.
Returns:
A subscription ID that can later be passed to unsubscribe().

unsubscribe(self, id)

source code 

Unsubscribe from file change notifications.

Parameters:
  • id - Subscription ID received from subscribe()

event(self, event, *args, **kwargs)

source code 

Fire an event.

This method is intended for use by object implementations.

start(self)

source code 

Start checking for file changes.

Subscribers will be notified asynchronously of changes to the watched files.

getFileData(self)

source code 
Returns:
a dict, {filename => DATA} DATA can be anything. In the default implementation it is a pair of (mtime, size).

isNewFileStable(self, fName, fData)

source code 

Check if the file is already stable when being added to the set of watched files.

Parameters:
  • fName (str) - filename
  • fData - DATA, as returned by getFileData method. In the default implementation it is a pair of (mtime, size).
Returns: bool

getFilesToStat(self)

source code 
Returns:
sequence of filename