#NEWLINE# def create_file_watcher( pl , watcher_type = 'auto' , expire_time = 10 ) : #NEWLINE# #INDENT# 'Create an object that can watch for changes to specified files\n\n\tUse ``.__call__()`` method of the returned object to start watching the file \n\tor check whether file has changed since last call.\n\n\tUse ``.unwatch()`` method of the returned object to stop watching the file.\n\n\tUses inotify if available, then pyuv, otherwise tracks mtimes. expire_time \n\tis the number of minutes after the last query for a given path for the \n\tinotify watch for that path to be automatically removed. This conserves \n\tkernel resources.\n\n\t:param PowerlineLogger pl:\n\t\tLogger.\n\t:param str watcher_type\n\t\tOne of ``inotify`` (linux only), ``uv``, ``stat``, ``auto``. Determines \n\t\twhat watcher will be used. ``auto`` will use ``inotify`` if available, \n\t\tthen ``libuv`` and then fall back to ``stat``.\n\t:param int expire_time:\n\t\tNumber of minutes since last ``.__call__()`` before inotify watcher will \n\t\tstop watching given file.\n\t' #NEWLINE# if ( watcher_type == 'stat' ) : #NEWLINE# #INDENT# pl . debug ( 'Using requested stat-based watcher' , prefix = 'watcher' ) #NEWLINE# return StatFileWatcher ( ) #NEWLINE# #UNINDENT# if ( watcher_type == 'inotify' ) : #NEWLINE# #INDENT# pl . debug ( 'Using requested inotify watcher' , prefix = 'watcher' ) #NEWLINE# return INotifyFileWatcher ( expire_time = expire_time ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( watcher_type == 'uv' ) : #NEWLINE# #INDENT# pl . debug ( 'Using requested uv watcher' , prefix = 'watcher' ) #NEWLINE# return UvFileWatcher ( ) #NEWLINE# #UNINDENT# #UNINDENT# if sys . platform . startswith ( 'linux' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# pl . debug ( 'Trying to use inotify watcher' , prefix = 'watcher' ) #NEWLINE# return INotifyFileWatcher ( expire_time = expire_time ) #NEWLINE# #UNINDENT# except INotifyError : #NEWLINE# #INDENT# pl . info ( 'Failed to create inotify watcher' , prefix = 'watcher' ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# pl . debug ( 'Using libuv-based watcher' ) #NEWLINE# return UvFileWatcher ( ) #NEWLINE# #UNINDENT# except UvNotFound : #NEWLINE# #INDENT# pl . debug ( 'Failed to import pyuv' ) #NEWLINE# #UNINDENT# pl . debug ( 'Using stat-based watcher' ) #NEWLINE# return StatFileWatcher ( )