View Single Post
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#18
Mmmh, I am now playing around with python-pyinotify to poll the file but it did not what I expected...

I get only a response for "process_IN_OPEN", "process_IN_ACCESS" and "process_IN_CLOSE_NOWRITE" but nothing for "process_IN_MODIFY"...

Any other ideas how to poll the file? Or should I build in a "only trigger event if value change caompared to last time"?

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import os, time, pyinotify
import pyinotify

ambient_sensor = '/sys/class/i2c-adapter/i2c-2/2-0029/lux'

wm = pyinotify.WatchManager()  # Watch Manager
mask = pyinotify.ALL_EVENTS

def action(self, the_event):
    value = open(the_event.pathname, 'r').read().strip()
    return value

class EventHandler(pyinotify.ProcessEvent):
    def process_IN_ACCESS(self, event):
	print "ACCESS event:", action(self, event)

    def process_IN_ATTRIB(self, event):
	print "ATTRIB event:", action(self, event)

    def process_IN_CLOSE_NOWRITE(self, event):
	print "CLOSE_NOWRITE event:", action(self, event)

    def process_IN_CLOSE_WRITE(self, event):
	print "CLOSE_WRITE event:", action(self, event)

    def process_IN_CREATE(self, event):
	print "CREATE event:", action(self, event)

    def process_IN_DELETE(self, event):
	print "DELETE event:", action(self, event)

    def process_IN_MODIFY(self, event):
	print "MODIFY event:", action(self, event)

    def process_IN_OPEN(self, event):
	print "OPEN event:", action(self, event)
	

#log.setLevel(10)
notifier = pyinotify.ThreadedNotifier(wm, EventHandler())
notifier.start()

wdd = wm.add_watch(ambient_sensor, mask)
wdd
#wm.rm_watch(wdd.values())

time.sleep(5)
notifier.stop()
Cheers
Bjoern