45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import sys
|
|
import socket
|
|
from streams import EventStream
|
|
from nicoscache import NicosStream
|
|
from secop import ScanStream, ScanReply, TrySecopConnect, send_fake_udp
|
|
from seinflux import SEHistory
|
|
from servicemanager import FrappyManager
|
|
|
|
|
|
def main():
|
|
# egen = EventStream(ScanReply(), ScanStream(), n=NicosStream('localhost:14002'))
|
|
egen = EventStream(ScanReply(), ScanStream())
|
|
db = SEHistory(access='write')
|
|
db.enable_write_access()
|
|
|
|
fm = FrappyManager()
|
|
fm.get_info()
|
|
host = socket.gethostname().split('.')[0]
|
|
for ins, procs in fm.get_procs().items():
|
|
for service in procs:
|
|
if service in procs:
|
|
port = fm.info.get(ins, {}).get(service, {})
|
|
if port:
|
|
uri = f'{host}:{port}'
|
|
print('CREATE', uri)
|
|
TrySecopConnect(uri)
|
|
|
|
event_map = {'value': db.add_float, 'error': db.add_error, 'stream': db.add_stream}
|
|
|
|
try:
|
|
while 1:
|
|
for kind, *args in egen.get_events():
|
|
event_map[kind](*args)
|
|
db.flush()
|
|
finally:
|
|
for kind, *args in egen.finish():
|
|
event_map[kind](*args)
|
|
db.disconnect()
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
send_fake_udp(*sys.argv[1:])
|
|
else:
|
|
main()
|