Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from inotify.adapters import Inotify
- import os
- import time
- WATCH = "/media/eri"
- # Events that actually indicate a change
- INTERESTING = {
- "IN_CREATE",
- "IN_DELETE",
- "IN_MOVED_TO",
- "IN_MOVED_FROM",
- "IN_CLOSE_WRITE",
- "IN_ATTRIB",
- }
- ino = Inotify()
- ino.add_watch(WATCH)
- print(f"Watching {WATCH} (changes only)")
- print("Ctrl+C to stop\n")
- try:
- for event in ino.event_gen(yield_nones=False):
- (_, type_names, path, filename) = event
- # Keep only meaningful changes
- changes = [e for e in type_names if e in INTERESTING]
- if not changes:
- continue
- full = os.path.join(path, filename) if filename else path
- print(time.strftime("%H:%M:%S"), full)
- print(" changes:", changes)
- print()
- except KeyboardInterrupt:
- print("\nStopped.")
Advertisement
Add Comment
Please, Sign In to add comment