Advertisement
DeaD_EyE

Inotify Python

Mar 21st, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. from pathlib import Path
  2. from inotify.adapters import Inotify
  3. from inotify.constants import IN_CLOSE_WRITE
  4.  
  5.  
  6. def watch(paths):
  7.     if isinstance(paths, (str, bytes, Path)):
  8.         paths = [paths]
  9.     notify = Inotify()
  10.     for path in paths:
  11.         notify.add_watch(path, mask=IN_CLOSE_WRITE)
  12.     events = notify.event_gen(yield_nones=False)
  13.     for _, event_types, path, file in events:
  14.         target = Path(path, file)
  15.         # print(target, event_types)
  16.         yield target
  17.  
  18.  
  19. notifier = watch('/home/andre')
  20. for file in notifier:
  21.     print(file.name, 'CONTENT:', file.read_text().strip())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement