diff --git a/base.py b/base.py index f9d54b2..5a75daf 100644 --- a/base.py +++ b/base.py @@ -310,15 +310,21 @@ class ServiceManager: ins_list = self.wildcard(ins) if ins_list is not None: return ins_list - if logger is None: - class logger: - @staticmethod + if not logger: + if logger is False: + def info(fmt, *args): + pass + else: def info(fmt, *args): print(fmt % args) - @staticmethod - def error(fmt, *args): - print(('ERROR: ' + fmt) % args) + def error(fmt, *args): + print(('ERROR: ' + fmt) % args) + + logger = type('Logger', (), {}) + + logger.info = info + logger.error = error if ins is None: logger.info('nothing to start') diff --git a/seaman.py b/seaman.py index abf4afd..aaebcea 100644 --- a/seaman.py +++ b/seaman.py @@ -26,7 +26,8 @@ import subprocess import psutil import os import re -from os.path import join, exists +import socket +from os.path import join, exists, expanduser from servicemanager.base import ServiceManager, ServiceDown, UsageError CFGLINE = re.compile(r'(?:device makeitem (name|stick_name|confirmed) "(.*)" ""' @@ -255,3 +256,20 @@ class SeaManager(ServiceManager): if service: result.append(service) 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()