invert sea_info dict

This commit is contained in:
zolliker 2024-04-03 13:24:26 +02:00
parent 9fed0ead11
commit 0d026c91de

View File

@ -70,12 +70,12 @@ def summarize_server_state(givencfgs, ourcfgs, sealist, sea_info, strict=False):
:param givencfgs: dict <service> of given configuration (from nicos cache)
:param outcfgs: dict <service> of running configuration (frappy)
:param sealist: list of running sea configuration
:param sea_info: dict <frappycfg> of <seacfg> with info about sea configs
:param sealist: list of running sea configuration [<config>, <stick>, <addon1>, <addon2> ...]
:param sea_info: dict <seacfg> of <frappycfg>
:param strict: when True return empty cfg result on error
:return: tuple (<error>, <proposed>, (<frappyitems>, <seaitems>), <remarks> where:
<error>: proposed config not sure
<proposed>: dict <service> of proposed cfg
<proposed>: dict <service> of proposed cfg (cfg is True: no restart needed)
<frappyitems>: dict of items runnning in frappy servers (addons are separated)
<seaitems>: dict of items running on the sea server
<remarks>: dict of actions / remarks
@ -95,7 +95,6 @@ def summarize_server_state(givencfgs, ourcfgs, sealist, sea_info, strict=False):
seacfgfiles = [(c or '') + SEAEXT.get(s, '.addon')
for c, s in zip_longest(sealist, FrappyManager.services)]
seacfgset = set(seacfgfiles)
error = False
result = {}
addons = set()
@ -143,6 +142,10 @@ def summarize_server_state(givencfgs, ourcfgs, sealist, sea_info, strict=False):
remarks[pkey] = 'missing frappy config'
error = True
restart = set()
available = {s: set() for s in ('.config', '.stick', '.addon')}
for seacfg, cfg in sea_info.items():
ext = seacfg.rsplit('.', 1)[-1]
available[ext].add(cfg)
for key, running in frappycfgs.items():
if running:
if key in ('main', 'stick'):
@ -151,7 +154,7 @@ def summarize_server_state(givencfgs, ourcfgs, sealist, sea_info, strict=False):
service = 'addons'
addons.add(running)
if not seacfgs.get(key):
if sea_info.get(running):
if running in available[SEAEXT.get(key, '.addon')]:
restart.add(service)
remarks[key] = 'restart to start sea'
elif givencfgs.get(key) != running:
@ -334,7 +337,8 @@ class FrappyManager(ServiceManager):
desc = repr(e)
if cfg not in all_cfg:
if sea_cfg and sea_info is not None:
sea_info.setdefault(sea_cfg, set()).add(cfg)
# sea_info.setdefault(sea_cfg, set()).add(cfg)
sea_info[cfg] = sea_cfg
all_cfg.add(cfg)
if list_info is not None:
list_info.setdefault(cfgdir, {})[cfg] = desc.split('\n', 1)[0]
@ -351,35 +355,39 @@ class FrappyManager(ServiceManager):
for service in self.services:
self.all_cfg(ins, service, list_info, sea_info)
seacfgpat = re.compile(r'(.*)(\.config|\.stick|\.addon)')
inverted_sea_info = {}
for seacfg, cfgset in sea_info.items():
for cfg in cfgset:
inverted_sea_info[cfg] = seacfg
ambiguous = 0
# inverted_sea_info = {}
# for seacfg, cfgset in sea_info.items():
# for cfg in cfgset:
# inverted_sea_info[cfg] = seacfg
cfgset = set()
ambiguous = {}
for cfg, seacfg in sea_info.items():
if cfg in cfgset:
ambiguous[cfg] = ambiguous.get(cfg, 1) + 1
else:
cfgset.add(cfg)
keylen = max(max(len(k) for k in cfgs) for cfgs in list_info.values())
for cfgdir, cfgs in list_info.items():
if cfgs:
prt('')
prt('--- %s:' % cfgdir)
for cfg, desc in sorted(cfgs.items(), key=lambda v: (v[0].lower(), v)):
seacfg = inverted_sea_info.get(cfg)
seacfg = sea_info.get(cfg)
if seacfg:
name, ext = seacfgpat.match(seacfg).groups()
if name == cfg or name + 'stick' == cfg:
prefix = '* '
else:
prefix = f'* ({name}{ext}) '
n = len(sea_info[seacfg])
if n > 1:
if cfg in ambiguous:
prefix = '!' + prefix[1:]
ambiguous += 1.0 / n
desc = prefix + desc
prt('%s %s' % (cfg.ljust(keylen), desc))
prt(' ')
gap = ' ' * keylen
prt(f'{gap} * need sea')
if ambiguous:
print(f'{gap} ! {round(ambiguous)} ambiguous mappings sea -> frappy')
print(f'{gap} ! {len(ambiguous)} ambiguous mappings sea -> frappy')
def treat_args(self, argdict, unknown=(), extra=()):
cfg = None