Skip to content

Instantly share code, notes, and snippets.

@FredrikWendt
Created May 4, 2017 10:02
Show Gist options
  • Save FredrikWendt/7045cdd20d6ec5bafe049250b6a000a2 to your computer and use it in GitHub Desktop.
Save FredrikWendt/7045cdd20d6ec5bafe049250b6a000a2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# Watches the dropfolder, and kicks off the dropfolder-scanner when a file is closed
#
import pyinotify, os, logging
logging.basicConfig(filename='/tmp/dropfolder.log')
logger = logging.getLogger('watcher')
logger.setLevel(logging.INFO)
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
logger.info("close: %s", event.pathname)
os.system("do magic stuff %s" % event.pathname)
wm = pyinotify.WatchManager()
mask = pyinotify.IN_CLOSE_WRITE
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch('/dump/samba/dropfolder', mask)
notifier.loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment