from ajenti.api import *
from ajenti.util import cache_value
@plugin
@persistent
[docs]class ServiceMultiplexor (object):
"""
Merges together output of all available ServiceManagers.
"""
[docs] def init(self):
self.managers = ServiceManager.get_all()
@cache_value(1)
def get_all(self):
"""
Returns all :class:`Service` s.
"""
r = []
for mgr in self.managers:
r += mgr.get_all()
return r
[docs] def get_one(self, name):
"""
Returns a :class:`Service` by name.
"""
for mgr in self.managers:
s = mgr.get_one(name)
if s:
return s
return None
@interface
@persistent
[docs]class ServiceManager (object):
def get_all(self):
return []
[docs] def get_one(self, name):
"""
Returns a :class:`Service` by name.
"""
for s in self.get_all():
if s.name == name:
return s
return None
[docs]class Service (object):
source = 'unknown'
""" Marks which ServiceManager owns this object """
def __init__(self):
self.name = None
self.running = False
@property
def icon(self):
return 'play' if self.running else None
[docs] def restart(self):
pass
[docs] def command(self, cmd):
pass