diff --git a/seaman.py b/seaman.py index 2e100e3..abf4afd 100644 --- a/seaman.py +++ b/seaman.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # ***************************************************************************** # # This program is free software; you can redistribute it and/or modify it under @@ -34,6 +33,16 @@ CFGLINE = re.compile(r'(?:device makeitem (name|stick_name|confirmed) "(.*)" ""' r'|addon_list makeitem (.*) (?:"permanent"|"volatile"))') +INIFILE_CONTENT = """ +set instrument {ins_i} +set serverport {port} +set logbase {insdir} +{extraline}cd {seadir}tcl +exe echo 1 +exe {service}init.tcl +""" + + def run_command(cmd, wait=False): if wait: old = termios.tcgetattr(sys.stdin) @@ -68,6 +77,48 @@ class SeaManager(ServiceManager): %(legend)s """ + def do_create(self, ins, *args): + if ins == 'check': + ins_list = self.wildcard(None) + else: + ins_list = self.wildcard(ins) + if ins_list is None: + ins_list = [ins] + self.get_info() + for ins_i in ins_list: + seadir = f"{expanduser('~')}/sea/" + if not exists(seadir): + print(f'get {seadir} from git first') + return + insdir = seadir if ins_i == self.main_ins else f'{seadir}{ins_i}/' + if ins != 'check': + os.makedirs(f'{insdir}/logger', exist_ok=True) + os.makedirs(f'{insdir}/log', exist_ok=True) + os.makedirs(f'{insdir}/status', exist_ok=True) + extraline = 'set connect_sea_to_sics 0\n' + for service in 'sea', 'graph': + port = self.info[ins_i][service] + if not port: + continue + sea_init = INIFILE_CONTENT.format(**locals()).strip() + extraline = '' + filename = f'{seadir}{service}_{ins_i}.tcl' + try: + with open(filename) as f: + content = f.read().strip() + except FileNotFoundError: + content = '' + if sea_init != content: + if ins == 'check': + if content: + print(filename, 'does not match') + else: + print(filename, 'does not exist') + else: + with open(filename, 'w') as f: + f.write(sea_init) + f.write('\n') + def do_cli(self, ins, service=None): if self.wildcard(ins): raise UsageError('wildcards not allowed in sea cli')