本文整理汇总了Python中pyinotify.WatchManager方法的典型用法代码示例。如果您正苦于以下问题:Python pyinotify.WatchManager方法的具体用法?Python pyinotify.WatchManager怎么用?Python pyinotify.WatchManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyinotify
的用法示例。
在下文中一共展示了pyinotify.WatchManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: watch
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def watch(watch_file):
'''
Watch the given file for changes
'''
wm = WatchManager()
with TailHandler(watch_file) as th:
notifier = Notifier(wm, th)
wdd = wm.add_watch(watch_file, TailHandler.MASK)
notifier.loop()
# flush queue before exiting
th.publish_queue.publish()
print 'Exiting'
示例2: run
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def run(self):
self.running = True
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm)
def inotify_callback(event):
if event.mask == pyinotify.IN_CLOSE_WRITE:
self._parse_desktop_file(event.pathname)
elif event.mask == pyinotify.IN_DELETE:
with self.lock:
for cmd, data in self.apps.items():
if data[2] == event.pathname:
del self.apps[cmd]
break
for p in DESKTOP_PATHS:
if os.path.exists(p):
wm.add_watch(p,
pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE,
inotify_callback)
notifier.loop()
示例3: setup
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def setup(self):
""" Set up inotify manager.
See https://github.com/seb-m/pyinotify/.
"""
if not pyinotify.WatchManager:
raise error.UserError("You need to install 'pyinotify' to use %s (%s)!" % (
self.__class__.__name__, pyinotify._import_error)) # pylint: disable=E1101, W0212
self.manager = pyinotify.WatchManager()
self.handler = TreeWatchHandler(job=self)
self.notifier = pyinotify.AsyncNotifier(self.manager, self.handler)
if self.LOG.isEnabledFor(logging.DEBUG):
mask = pyinotify.ALL_EVENTS
else:
mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO # bogus pylint: disable=E1101
# Add all configured base dirs
for path in self.config.path:
self.manager.add_watch(path.strip(), mask, rec=True, auto_add=True)
示例4: _loop_linux
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def _loop_linux(self, loop_callback):
"""loop implementation for linux platform"""
import pyinotify
handler = self._handle
class EventHandler(pyinotify.ProcessEvent):
def process_default(self, event):
handler(event)
watch_manager = pyinotify.WatchManager()
event_handler = EventHandler()
notifier = pyinotify.Notifier(watch_manager, event_handler)
mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO
for watch_this in self.watch_dirs:
watch_manager.add_watch(watch_this, mask)
notifier.loop(loop_callback)
示例5: file_monitor
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def file_monitor(path='.', client=None):
wm = WatchManager()
mask = IN_DELETE | IN_CREATE | IN_MODIFY
notifier = AsyncNotifier(wm, EventHandler(client))
wm.add_watch(path, mask, auto_add=True, rec=True)
if not os.path.isfile(path):
logger.debug("File %s does not exist." % path)
sys.exit(3)
else:
logger.debug("Now starting monitor file %s." % path)
global f
f = open(path, 'r')
st_size = os.stat(path)[6]
f.seek(st_size)
while True:
try:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
except KeyboardInterrupt:
print "keyboard Interrupt."
notifier.stop()
break
示例6: __init__
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(self, config, corpusManager):
self.wm = pyinotify.WatchManager()
self.mask = pyinotify.IN_CREATE
self.handler = FileWatcherEventHandler(corpusManager)
self.wdd = None
self.config = config
示例7: linux_event_handler
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def linux_event_handler(logger, dir_watch_data, cond, tasks):
watch_manager = pyinotify.WatchManager()
mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO | pyinotify.IN_MODIFY | pyinotify.IN_CREATE
for dir_watch in dir_watch_data:
logger.info(_(u'Watching directory %s' % dir_watch['path']))
watch_manager.add_watch(path=dir_watch['path'], mask=mask, rec=False, auto_add=True, do_glob=True)
handler = LinuxEventHandler(logger=logger, dir_watch_data=dir_watch_data, cond=cond, tasks=tasks)
notifier = pyinotify.Notifier(watch_manager, handler)
notifier.loop()
# end of linux-specific ##################################################################################
示例8: main
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def main():
(options, args) = parser.parse_args()
if None in [options.watch_dir, options.backup_dir]:
parser.print_help()
return
# 删除最后的 /
options.watch_dir = options.watch_dir.rstrip('/')
options.backup_dir = options.backup_dir.rstrip('/')
global watch_dir_name
global back_dir_name
watch_dir_name = options.watch_dir
back_dir_name = options.backup_dir
logger.info('watch dir %s' % options.watch_dir)
logger.info('back dir %s' % options.backup_dir)
if not options.disable_backup:
backup_monitor_dir(options.watch_dir, options.backup_dir)
# watch manager
wm = pyinotify.WatchManager()
wm.add_watch(options.watch_dir, pyinotify.ALL_EVENTS, rec=True)
wm.add_watch(options.backup_dir, pyinotify.ALL_EVENTS, rec=True)
# event handler
eh = FileEventHandler()
# notifier
notifier = pyinotify.Notifier(wm, eh)
notifier.loop()
示例9: __init__
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(self, file_created_captured, file_modified_captured):
self.WATCHDIR = u'/tmp'
self.file_created_captured = file_created_captured
self.file_modified_captured = file_modified_captured
self.wm = pyinotify.WatchManager() # Watch Manager
self.mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY # watched events
self.notifier = pyinotify.Notifier(self.wm, self)
self.wdd = self.wm.add_watch(self.WATCHDIR, self.mask, rec = True)
示例10: __init__
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(self, file_paths, watch_mask=FILE_CHANGE_MASK):
self.inotify_watch_manager = pyinotify.WatchManager()
self._file_paths = file_paths
self._event_handler = ModifiedFileEventHandler(callback=self._reload_modified_file)
self._inotify_notifier = pyinotify.Notifier(self.inotify_watch_manager, default_proc_fun=self._event_handler)
self._loop_thread = threading.Thread(target=self._inotify_notifier.loop, daemon=True)
for file_path in self._file_paths:
self.inotify_watch_manager.add_watch(file_path, watch_mask)
self._loop_thread.start()
atexit.register(self._shutdown)
示例11: __init__
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(
self,
instances_to_bounce: DelayDeadlineQueueProtocol,
cluster: str,
config: SystemPaastaConfig,
**kwargs: Any,
) -> None:
super().__init__(instances_to_bounce, cluster, config)
self.wm = pyinotify.WatchManager()
self.wm.add_watch(DEFAULT_SOA_DIR, self.mask, rec=True)
self.notifier = pyinotify.Notifier(
watch_manager=self.wm,
default_proc_fun=YelpSoaEventHandler(filewatcher=self),
)
示例12: start_config_watch
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def start_config_watch(self):
wm = pyinotify.WatchManager()
wm.add_watch('./config/mitmf.conf', pyinotify.IN_MODIFY)
notifier = pyinotify.Notifier(wm, self)
t = threading.Thread(name='ConfigWatcher', target=notifier.loop)
t.setDaemon(True)
t.start()
示例13: _watch_file
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def _watch_file(self):
mask = pyinotify.IN_MOVED_FROM | pyinotify.IN_DELETE
watch_manager = pyinotify.WatchManager()
handler = _FileKeeper(watched_handler=self,
watched_file=self._log_file)
notifier = _EventletThreadedNotifier(
watch_manager,
default_proc_fun=handler,
read_freq=FastWatchedFileHandler.READ_FREQ,
timeout=FastWatchedFileHandler.TIMEOUT)
notifier.daemon = True
watch_manager.add_watch(self._log_dir, mask)
notifier.start()
示例14: watch_folder
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def watch_folder(module, params):
log.debug('Watching folder %s for screenshots ...' % params['in'])
screen_wm = pyinotify.WatchManager()
screen_mask = pyinotify.IN_CLOSE_WRITE
screen_notifier = pyinotify.AsyncNotifier(screen_wm, ScreenshotHandler())
screen_wdd = screen_wm.add_watch(params['in'], screen_mask, rec = True)
asyncore.loop()
示例15: watch_folder
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def watch_folder(properties):
log.debug('Function "folder" launched with params %s: ' % properties)
# inotify kernel watchdog stuff
wm = pyinotify.WatchManager()
mask = pyinotify.IN_CLOSE_WRITE
notifier = pyinotify.AsyncNotifier(wm, EventHandler())
wdd = wm.add_watch(properties['in'], mask, rec = True)
log.debug('watching :: %s' % properties['in'])
asyncore.loop()