Exemplo n.º 1
0
class MHubApp(object):
    """
    Core application container responsible for managing and running of configured plugins.

    :param cfg: Application configuration dictionary
    :type cfg: dict.
    """
    def __init__(self, cfg=None):
        """
        Constructor
        """

        self.cfg = cfg or dict()
        self.logger = logging.getLogger("app")

        self.reactor = reactor
        self.root_service = MultiService()
        self.service = MHubService(self.cfg, self.reactor, self)
        self.application = Application("mhub")
        self.root_service.setServiceParent(self.application)

    def get_application(self):
        """
        Get the Twisted application object.

        :returns: Application
        """

        return self.application
Exemplo n.º 2
0
    def setServiceParent(self, app):
        MultiService.setServiceParent(self, app)

        if config.ErrorLogEnabled:
            errorLogFile = LogFile.fromFullPath(
                config.ErrorLogFile,
                rotateLength=config.ErrorLogRotateMB * 1024 * 1024,
                maxRotatedFiles=config.ErrorLogMaxRotatedFiles
            )
            errorLogObserver = FileLogObserver(errorLogFile).emit

            # Registering ILogObserver with the Application object
            # gets our observer picked up within AppLogger.start( )
            app.setComponent(ILogObserver, errorLogObserver)
Exemplo n.º 3
0
    def setServiceParent(self, parent):
        MultiService.setServiceParent(self, parent)

        self.pb = PbService(self.config.socket)
        self.pb.setServiceParent(self)

        self.resolver = Resolver(self.config.resolver_cache)
        self.resolver.setServiceParent(self)

        self.proxyservices = []
        for service in self.config.services:
            p = ProxyService(service)
            p.setServiceParent(self)
            self.proxyservices.append(p)
Exemplo n.º 4
0
    def add(self, name, services):
        log.msg(
            'bit.core.services: Services.add %s, %s' % (name, services))
        if not isinstance(services, dict):
            services.setName(name)
            services.setServiceParent(self.collect)
            self._services.append(name)
            return

        add = True
        if name in self._multi:
            plug_services = self.collect.getServiceNamed(name)
            add = False
        else:
            plug_services = MultiService()
            plug_services.setName(name)
            self._multi.append(name)
        for sid, s in services.items():
            s.setName(sid)
            s.setServiceParent(plug_services)
        if add:
            plug_services.setServiceParent(self.collect)
Exemplo n.º 5
0
class MHubApp(object):

    """
    Core application container responsible for managing and running of configured plugins.

    :param cfg: Application configuration dictionary
    :type cfg: dict.
    """



    def __init__(self, cfg=None):

        """
        Constructor
        """

        self.cfg = cfg or dict()
        self.logger = logging.getLogger("app")

        self.reactor = reactor
        self.root_service = MultiService()
        self.service = MHubService(self.cfg, self.reactor, self)
        self.application = Application("mhub")
        self.root_service.setServiceParent(self.application)


    def get_application(self):

        """
        Get the Twisted application object.

        :returns: Application
        """

        return self.application
Exemplo n.º 6
0
 def setServiceParent(self, parent):
     MultiService.setServiceParent(self, parent)
     if isinstance(parent, Componentized):
         parent.setComponent(ILogObserver, carbonLogObserver)
Exemplo n.º 7
0
 def setServiceParent(self, parent):
   MultiService.setServiceParent(self, parent)
   if isinstance(parent, Componentized):
     parent.setComponent(ILogObserver, carbonLogObserver)
Exemplo n.º 8
0
from twisted.application.internet import TCPClient, TCPServer
from twisted.application.service import Application, MultiService

from bravo.amp import ConsoleRPCFactory
from bravo.config import configuration
from bravo.factory import BetaFactory
from bravo.irc import BravoIRC

service = MultiService()

worlds = []
for section in configuration.sections():
    if section.startswith("world "):
        factory = BetaFactory(section[6:])
        TCPServer(factory.port, factory).setServiceParent(service)
        worlds.append(factory)
    elif section.startswith("irc "):
        factory = BravoIRC(worlds, section[4:])
        TCPClient(factory.host, factory.port,
            factory).setServiceParent(service)

# Start up our AMP.
TCPServer(25600, ConsoleRPCFactory(worlds)).setServiceParent(service)

application = Application("Bravo")
service.setServiceParent(application)
Exemplo n.º 9
0
verbose = True

config = dict(hello="mum", goodbye="friend")
callbacks = {
    "player_play": lambda player: "Callback for Player '%s'" % (player)
}

top_service = MultiService()

reader = None

if ncurses_enabled:
    std_screen = curses.initscr()
    reader = Screen(std_screen)
    std_screen.refresh()
    reactor.addReader(reader)

sbs_service = SqueezeboxServerService(reader=reader, 
                                      config=config, 
                                      callbacks=callbacks,
                                      verbose=verbose)
sbs_service.setServiceParent(top_service)

factory = SqueezeboxServerFactory(sbs_service)
tcp_service = TCPClient(host, port, factory)
tcp_service.setServiceParent(top_service)

application = Application("pysqueezeboxserver")
top_service.setServiceParent(application)

Exemplo n.º 10
0
def load_role_config():
    config = StationConfig(blocked_roles=static_config["blocked_roles"])
    if isfile(static_config["dynamic_config"]):
        config.roles = load_json(static_config["dynamic_config"])
    return config


def save_role_config(roles):
    save_json(roles, static_config["dynamic_config"])

static_config = load_json("station.json")

role_config = load_role_config()

service_wrapper = MultiService()

configuration_manager_service = ConfigurationManagerService(role_config, update_callback=save_role_config)
configuration_manager_service.setServiceParent(service_wrapper)

transmit_service.setServiceParent(service_wrapper)

client = internet.TCPClient(static_config["manager_address"], static_config["manager_port"], StationClientFactory())
client.setServiceParent(service_wrapper)

application = Application("EventStreamr Station")
service_wrapper.setServiceParent(application)

if __name__ == "__main__":
    print "Please run this file using the following command - It makes life easier."
    print "\ttwistd --pidfile station.pid --nodaemon --python station.py"