diff --git a/frappyman.py b/frappyman.py index 39cf200..a580159 100644 --- a/frappyman.py +++ b/frappyman.py @@ -70,12 +70,12 @@ def summarize_server_state(givencfgs, ourcfgs, sealist, sea_info, strict=False): :param givencfgs: dict of given configuration (from nicos cache) :param outcfgs: dict of running configuration (frappy) - :param sealist: list of running sea configuration - :param sea_info: dict of with info about sea configs + :param sealist: list of running sea configuration [, , , ...] + :param sea_info: dict of :param strict: when True return empty cfg result on error :return: tuple (, , (, ), where: : proposed config not sure - : dict of proposed cfg + : dict of proposed cfg (cfg is True: no restart needed) : dict of items runnning in frappy servers (addons are separated) : dict of items running on the sea server : 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