2021-07-30 17:11:19 +00:00
|
|
|
#! /usr/bin/python3
|
2025-03-27 15:26:53 +00:00
|
|
|
from auto_run import rpirena, config
|
|
|
|
|
rpirena.boot(config)
|
2014-01-08 22:20:38 +00:00
|
|
|
from time import strftime, gmtime
|
2020-02-22 20:23:50 +00:00
|
|
|
import sys
|
|
|
|
|
|
2021-09-17 08:34:11 +00:00
|
|
|
import pyinotify
|
2020-02-22 20:23:50 +00:00
|
|
|
class AutoRun(object):
|
|
|
|
|
fn = 'auto-run'
|
2021-09-17 08:34:11 +00:00
|
|
|
def process_event(self, event):
|
|
|
|
|
with open(self.fn) as f:
|
|
|
|
|
mes = f.read().strip()
|
2020-02-22 20:23:50 +00:00
|
|
|
if mes:
|
|
|
|
|
open(self.fn, "w").close()
|
2021-09-17 08:34:11 +00:00
|
|
|
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
|
2020-02-22 20:23:50 +00:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
rpirena.notification = AutoRun()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
sys.stderr.write("notification: %s\n" % repr(e))
|
|
|
|
|
|
|
|
|
|
while True:
|
2025-03-27 15:26:53 +00:00
|
|
|
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:
|
2020-02-22 20:23:50 +00:00
|
|
|
break
|
2025-03-27 15:26:53 +00:00
|
|
|
except:
|
|
|
|
|
pass
|