variant with config as mixin
This commit is contained in:
@@ -31,6 +31,7 @@ frappy_ports = 15000-15009
|
||||
MARCHESRC = ['/home/software/marche', '/home/l_samenv/marche']
|
||||
CFGDIRS = ['/home/linse/config', '/home/l_samenv/linse_config']
|
||||
|
||||
|
||||
def read_config(filename):
|
||||
parser = ConfigParser()
|
||||
parser.optxform = str
|
||||
@@ -94,12 +95,15 @@ class ArgError(ValueError):
|
||||
|
||||
|
||||
class Config:
|
||||
"""merge info from linsetools.cfg and instrument.cfg"""
|
||||
this = None
|
||||
single_instrument = None
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, instrument=None):
|
||||
configfile = Path('/sq_sw/linse/etc/linsetools.cfg')
|
||||
self.sections = read_config(configfile)
|
||||
if Path('/home/l_samenv').is_dir():
|
||||
# TODO: make it more elegant (this is a hack)
|
||||
for section_name, section in self.sections.items():
|
||||
for key, value in section.items():
|
||||
if value.startswith('/home/linse'):
|
||||
@@ -118,10 +122,23 @@ class Config:
|
||||
write_config(instconfig, self.instruments)
|
||||
except PermissionError:
|
||||
pass
|
||||
if len(self.instruments) == 1:
|
||||
self.single_instrument = list(self.instruments)[0]
|
||||
this = self.instruments.pop('this', None)
|
||||
if this:
|
||||
self.this = this['instrument']
|
||||
self.instruments[self.this] = this
|
||||
if not self.this:
|
||||
self.this = self.single_instrument
|
||||
|
||||
if instrument:
|
||||
self.instance = instrument or 'this'
|
||||
self.instrument = self.this if self.instance == 'this' else self.instance
|
||||
self.ins_config = self.instruments[self.instrument]
|
||||
self.init()
|
||||
|
||||
def init(self):
|
||||
pass
|
||||
|
||||
def parse_args(self, argmap, args, other=None):
|
||||
result = {}
|
||||
@@ -198,17 +215,14 @@ def wait_status(cl, service):
|
||||
return True
|
||||
|
||||
|
||||
class MarcheControl:
|
||||
class MarcheControl(Config):
|
||||
port = 8124
|
||||
otherarg = None
|
||||
argmap = {k: 'action' for k in ('start', 'restart', 'stop', 'gui', 'run', 'cli', 'list', 'listcfg')}
|
||||
argmap = {k: 'action' for k in ('start', 'restart', 'stop', 'gui', 'run', 'cli', 'list', 'listcfg', 'running')}
|
||||
|
||||
def __init__(self, instrument=None, host='localhost', port=None, user=None, config=None):
|
||||
self.config = config or Config()
|
||||
def __init__(self, instrument=None, host='localhost', port=None, user=None):
|
||||
super().__init__(instrument)
|
||||
self.host = host
|
||||
self.instance = instrument or 'this'
|
||||
self.instrument = self.config.this if self.instance == 'this' else self.instance
|
||||
self.ins_config = self.config.instruments[self.instrument]
|
||||
self.user = user or self.instrument # SINQ instruments
|
||||
if not (Path('/home') / self.user).is_dir():
|
||||
self.user = 'l_samenv'
|
||||
@@ -291,6 +305,5 @@ class MarcheControl:
|
||||
else:
|
||||
instruments = [instrument]
|
||||
for ins in instruments:
|
||||
print('---', ins)
|
||||
control = cls(ins, config=config)
|
||||
control.do(**argdict)
|
||||
|
||||
Reference in New Issue
Block a user