diff --git a/base.py b/base.py index 0d0fbca..ad85336 100644 --- a/base.py +++ b/base.py @@ -99,9 +99,16 @@ class Config: def __init__(self): configfile = Path('/sq_sw/linse/etc/linsetools.cfg') self.sections = read_config(configfile) + if Path('/home/l_samenv').is_dir(): + for section_name, section in self.sections.items(): + for key, value in section.items(): + if value.startswith('/home/linse'): + section[key] = value.replace('/home/linse', '/home/l_samenv') instconfig = Path('/home/linse/.config/instrument.cfg') if not instconfig.is_file(): - instconfig = Path('/home/l_samenv/.config/instrument.cfg') + cfg = Path('/home/l_samenv/.config/instrument.cfg') + if cfg.is_file(): + instconfig = cfg if instconfig.is_file(): self.instruments = read_config(instconfig) else: @@ -147,7 +154,6 @@ class Logger: method = log.show for lev in log.levels: setattr(log, lev, method) - print(lev, level) if lev == level: method = log.hide return log @@ -213,8 +219,7 @@ class MarcheControl: def connect(self): if self._client is None: if self.user == 'l_samenv': - x = 1 - arg = f'{2**4+x}lns{x}' + arg = '' else: arg = self.user.upper() + 'LNS' self._client = Client(self.host, self.port, self.user, arg) @@ -277,10 +282,15 @@ class MarcheControl: config = Config() argdict = config.parse_args(cls.argmap, args, cls.otherarg) instrument = argdict.pop('instrument', None) - if instrument is None and argdict.get('action') == 'list': # TODO: make more generic if needed + if instrument is None: instruments = list(config.instruments) + if len(instruments) != 1: + if argdict.get('action') != 'list': # TODO: make more generic if needed + raise ValueError('missing instrument') + instruments[1:] = [] else: instruments = [instrument] for ins in instruments: + print('---', ins) control = cls(ins, config=config) control.do(**argdict) diff --git a/frappy.py b/frappy.py index e344929..ee2ab0b 100644 --- a/frappy.py +++ b/frappy.py @@ -11,7 +11,7 @@ overrideNode(interface=interface) WRAPPER_PAT = re.compile(r"interface\s=\s*'(\d*)'\s*\n") -class Config: +class FrappyConfig: log = None process_file = None @@ -37,9 +37,9 @@ class FrappyControl(MarcheControl): superconfig = self.config.sections['superfrappy'] self.instance = instance - self.wrapperdir = superconfig.pop('wrapperdir') - self.cfgdirs = superconfig.pop('cfgdirs') - frappy_ports = self.ins_config.get('frappy_ports') + self.wrapperdir = superconfig.get('wrapperdir') + self.cfgdirs = superconfig.get('cfgdirs') + frappy_ports = self.ins_config.get('frappy_ports', '0') ports = frappy_ports.split('-') self.frappy_ports = list(range(int(ports[0]), int(ports[-1]))) self.frappy_servers = [f'{host}:{p}' for p in self.frappy_ports] @@ -52,7 +52,8 @@ class FrappyControl(MarcheControl): return f'frappy.{instance}' if self.instance == 'this' else f'frappy.{self.instrument}-{instance}' def wrapper_file(self, cfg): - return Path(self.wrapperdir) / f'{cfg}_cfg.py' + prefix = "" if self.instrument == 'this' else f'{self.instrument}-' + return Path(self.wrapperdir) / f'{prefix}{cfg}_cfg.py' def cfg_file(self, cfgdirs, service, cfg): if '/' in cfg: @@ -110,7 +111,7 @@ class FrappyControl(MarcheControl): if log is None: log = Logger('info') log.info('add %r port=%r', cfg, port) - service, cfgfile = self.cfg_file(self.cfgdirs, service, cfg) + servicedir, cfgfile = self.cfg_file(self.cfgdirs, service, cfg) if not port: if not service: raise ArgError('service is not given and can not be determined from cfg file location') @@ -187,7 +188,7 @@ class FrappyControl(MarcheControl): @staticmethod def get_cfg_details(cfgfile): - mods = Config.get(cfgfile) + mods = FrappyConfig.get(cfgfile) node = mods.pop('node') or {} sea_cfg = None for mod, config in mods.items():