make 'frappy listcfg' bhave like nicos 'frappy_list()'

This commit is contained in:
l_samenv 2022-07-06 08:45:26 +02:00
parent 0904390dc3
commit e67fa0bc35

View File

@ -49,15 +49,17 @@ class FrappyManager(ServiceManager):
cfgpaths = [] cfgpaths = []
cfgparser = ConfigParser() cfgparser = ConfigParser()
cfgparser.optionxform = str cfgparser.optionxform = str
cfgfile = self.env[ins]['FRAPPY_CONFIG_FILE'].replace('<SERV>', service) cfgfile = self.env[ins].get('FRAPPY_CONFIG_FILE')
cfgparser.read(cfgfile) confdir = self.env[ins]['FRAPPY_CONFDIR']
try: if cfgfile is not None:
section = cfgparser['FRAPPY'] cfgfile = self.env[ins]['FRAPPY_CONFIG_FILE'].replace('<SERV>', service)
except KeyError: cfgparser.read(cfgfile)
if exists(cfgfile): try:
raise KeyError('%s has no FRAPPY section' % cfgfile) from None section = cfgparser['FRAPPY']
raise FileNotFoundError('%s not found' % cfgfile) from None except KeyError:
for cfgpath in section['confdir'].split(os.pathsep): raise ValueError('%s does not exist or has no FRAPPY section' % cfgfile)
confdir = section.get('confdir', confdir)
for cfgpath in confdir.split(os.pathsep):
if cfgpath.endswith('<SERV>'): if cfgpath.endswith('<SERV>'):
cfgpaths.append(cfgpath[:-6] + service) cfgpaths.append(cfgpath[:-6] + service)
else: else:
@ -146,17 +148,14 @@ class FrappyManager(ServiceManager):
return result if by_dir else all_cfg return result if by_dir else all_cfg
def do_listcfg(self, ins='', service=''): def do_listcfg(self, ins='', service=''):
omit = 'develop'
if service: if service:
all_cfg = self.all_cfg(ins, service, by_dir=True) all_cfg = self.all_cfg(ins, service, by_dir=True)
if service == 'develop':
omit = 'NONE'
else: else:
all_cfg = {} all_cfg = {}
for service in self.services: for service in self.services:
all_cfg.update(self.all_cfg(ins, service, by_dir=True)) all_cfg.update(self.all_cfg(ins, service, by_dir=True))
for cfgdir, cfgs in all_cfg.items(): for cfgdir, cfgs in all_cfg.items():
if cfgs and not cfgdir.endswith(omit): if cfgs:
print('\n--- %s:\n' % cfgdir) print('\n--- %s:\n' % cfgdir)
keylen = max(len(k) for k in cfgs) keylen = max(len(k) for k in cfgs)
for cfg, desc in cfgs.items(): for cfg, desc in cfgs.items():