git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/cospi/host@9335 bc5caf13-1734-44f8-af43-603852e9ee25
45 lines
1.3 KiB
Python
Executable file
45 lines
1.3 KiB
Python
Executable file
#! /usr/bin/python3
|
|
from auto_run import rpirena, config
|
|
rpirena.boot(config)
|
|
from time import strftime, gmtime
|
|
import sys
|
|
|
|
import pyinotify
|
|
class AutoRun(object):
|
|
fn = 'auto-run'
|
|
def process_event(self, event):
|
|
with open(self.fn) as f:
|
|
mes = f.read().strip()
|
|
if mes:
|
|
open(self.fn, "w").close()
|
|
self.message = mes
|
|
def __init__(self):
|
|
self.wm = pyinotify.WatchManager()
|
|
self.notifier = pyinotify.Notifier(self.wm, self.process_event, timeout=0)
|
|
self.watch = self.wm.add_watch(self.fn, pyinotify.IN_CLOSE_WRITE)
|
|
self.message = None
|
|
def trigger(self):
|
|
self.notifier.check_events() and self.notifier.read_events()
|
|
self.notifier.process_events()
|
|
mes = self.message
|
|
self.message = None
|
|
return mes
|
|
|
|
try:
|
|
rpirena.notification = AutoRun()
|
|
except Exception as e:
|
|
sys.stderr.write("notification: %s\n" % repr(e))
|
|
|
|
while True:
|
|
try:
|
|
rpirena.boot(config)
|
|
fn=strftime("data/%Y-%m-%dT%H:%M:%SZ.EI", gmtime())
|
|
rpirena.stream_file(fn)
|
|
if rpirena.notification_messages[-1]=="stop":
|
|
rpirena.altera_reset()
|
|
if rpirena.notification_messages[-1]!="restart":
|
|
break
|
|
except KeyboardInterrupt:
|
|
break
|
|
except:
|
|
pass
|