From 9900af0e3f719c17aa308de79c6c06296ed12ada Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Fri, 9 Apr 2021 09:20:10 +0200 Subject: [PATCH] main ins no longer needed in command - MAIN is automatically replaced by the basename of the home directory - when %(ins) is omitted in *_command, it is also replaced by this + add help subcommand --- __init__.py | 3 +++ base.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 6ee90f5..b7d2074 100644 --- a/__init__.py +++ b/__init__.py @@ -58,6 +58,9 @@ def run(group, arglist): managers = {cls.group: cls() for cls in all if cls.group + '_command' in defaults} serv = managers[group] arglist = arglist + [''] # add dummy argument + if arglist[0].endswith('help'): + serv.usage() + return action = arglist.pop(0) if hasattr(serv, 'do_' + arglist[0]) else 'gui' instance = arglist.pop(0) if arglist[0] and arglist[0] not in serv.services else None if instance is None and len(serv.info) == 1: diff --git a/base.py b/base.py index f466ffe..00f023a 100644 --- a/base.py +++ b/base.py @@ -83,6 +83,7 @@ class ServiceManager: pkg = '' revcmd = {} USAGE = None + main_instrument = basename(expanduser('~')) def __init__(self): self.env = {} @@ -136,7 +137,7 @@ class ServiceManager: for ins in parser.sections(): section = dict(parser[ins]) if ins == 'MAIN': - ins = basename(expanduser('~')) + ins = self.main_instrument command = section.get('%s_command' % self.group) self.revcmd[command] = self.group nr = section.get(self.group) @@ -192,7 +193,7 @@ class ServiceManager: match = cmdpat.match(cmd) if match: gdict = match.groupdict() - ins = gdict['ins'] + ins = gdict.get('ins', self.main_instrument) serv = gdict.get('serv', '') if cfginfo is not None and 'cfg' in gdict: cfginfo[ins, serv] = gdict['cfg']