renamed to 'servicemanager'

the PYTHONPATH should be set to the directory above servicemanager
This commit is contained in:
2021-02-26 14:48:15 +01:00
parent 632beda430
commit 51abcab182
9 changed files with 158 additions and 134 deletions

View File

@ -27,7 +27,65 @@ this code is currently used:
- from a script allowing to start/stop/list (and more) multiple frappy and nicos servers
"""
from servman.base import ServiceManager, ServiceDown, run, UsageError
from servman.frappyman import FrappyManager
from servman.nicosman import NicosManager
from servman.seaman import SeaManager
from servicemanager.base import ServiceManager, ServiceDown, UsageError, get_config
from servicemanager.nicosman import NicosManager
from servicemanager.seaman import SeaManager
class FrappyManager(ServiceManager):
group = 'frappy'
services = ('main', 'stick', 'addons')
USAGE = """
Usage:
frappy list [<instance>]
frappy start <instance> <service> <cfgfiles>
frappy restart <instance> [<service>] [<cfgfiles>]
frappy stop <instance> [<service>]
<service> is one of main, stick, addons
<instance> is one of %s
"""
class SewebManager(ServiceManager):
group = 'seweb'
services = ('',)
USAGE = """
Usage:
seaweb list [<instance>]
seaweb start <instance>
seaweb restart <instance>
seaweb stop <instance>
<instance> is one of %s
"""
all = NicosManager, FrappyManager, SeaManager, SewebManager
def run(group, arglist):
try:
parser = get_config()
defaults = parser['DEFAULT']
managers = {cls.group: cls() for cls in all if cls.group + '_command' in defaults}
serv = managers[group]
arglist = arglist + [''] # add dummy argument
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:
instance = list(serv.info)[0]
if instance is not None:
arglist.insert(0, instance)
arglist.pop() # remove dummy argument
try:
serv.action(action, *arglist)
except AttributeError:
raise UsageError("do not know '%s'" % ' '.join([serv.group, action] + arglist))
except UsageError as e:
print(repr(e))
print(serv.usage())