add seaman.sea_recorder
+ do_start argument logger=False disables info messages
This commit is contained in:
18
base.py
18
base.py
@ -310,15 +310,21 @@ class ServiceManager:
|
|||||||
ins_list = self.wildcard(ins)
|
ins_list = self.wildcard(ins)
|
||||||
if ins_list is not None:
|
if ins_list is not None:
|
||||||
return ins_list
|
return ins_list
|
||||||
if logger is None:
|
if not logger:
|
||||||
class logger:
|
if logger is False:
|
||||||
@staticmethod
|
def info(fmt, *args):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
def info(fmt, *args):
|
def info(fmt, *args):
|
||||||
print(fmt % args)
|
print(fmt % args)
|
||||||
|
|
||||||
@staticmethod
|
def error(fmt, *args):
|
||||||
def error(fmt, *args):
|
print(('ERROR: ' + fmt) % args)
|
||||||
print(('ERROR: ' + fmt) % args)
|
|
||||||
|
logger = type('Logger', (), {})
|
||||||
|
|
||||||
|
logger.info = info
|
||||||
|
logger.error = error
|
||||||
|
|
||||||
if ins is None:
|
if ins is None:
|
||||||
logger.info('nothing to start')
|
logger.info('nothing to start')
|
||||||
|
20
seaman.py
20
seaman.py
@ -26,7 +26,8 @@ import subprocess
|
|||||||
import psutil
|
import psutil
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from os.path import join, exists
|
import socket
|
||||||
|
from os.path import join, exists, expanduser
|
||||||
from servicemanager.base import ServiceManager, ServiceDown, UsageError
|
from servicemanager.base import ServiceManager, ServiceDown, UsageError
|
||||||
|
|
||||||
CFGLINE = re.compile(r'(?:device makeitem (name|stick_name|confirmed) "(.*)" ""'
|
CFGLINE = re.compile(r'(?:device makeitem (name|stick_name|confirmed) "(.*)" ""'
|
||||||
@ -255,3 +256,20 @@ class SeaManager(ServiceManager):
|
|||||||
if service:
|
if service:
|
||||||
result.append(service)
|
result.append(service)
|
||||||
return result + extra
|
return result + extra
|
||||||
|
|
||||||
|
def sea_recorder(self, ins, uris):
|
||||||
|
self.do_start(ins, None, logger=False)
|
||||||
|
port = self.info[ins]['sea']
|
||||||
|
try:
|
||||||
|
conn = socket.create_connection(('localhost', port))
|
||||||
|
uris = ' '.join(uris)
|
||||||
|
conn.send(f'seauser seaser\nconfig listen 1\nsea_recorder {uris}\n'.encode())
|
||||||
|
conn.settimeout(2)
|
||||||
|
prev = b''
|
||||||
|
while True:
|
||||||
|
lines = (prev + conn.recv(999)).split(b'\n')
|
||||||
|
prev = lines.pop()
|
||||||
|
if b'ACTIVE' in lines:
|
||||||
|
break
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
Reference in New Issue
Block a user