rpirena/rpirena-auto.py
stephan 10b3d0c493 rpirena-auto: try: block, module auto_run
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/cospi/host@9335 bc5caf13-1734-44f8-af43-603852e9ee25
2025-03-27 15:26:53 +00:00

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