twisted.application.service.MultiService

Here are the examples of the python api twisted.application.service.MultiService taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

48 Examples 7

Example 1

Project: txstatsd Source File: httpinfo.py
Function: make_service
def makeService(options, processor, statsd_service):

    if options["http-port"] is None:
        return service.MultiService()

    root = resource.Resource()
    root.putChild("status", Status(processor, statsd_service))
    root.putChild("metrics", Metrics(processor))
    root.putChild("list_metrics", ListMetrics(processor))
    site = server.Site(root)
    s = internet.TCPServer(int(options["http-port"]), site)
    return s

Example 2

Project: txstatsd Source File: test_router.py
Function: set_up
    def setUp(self):
        self.service = MultiService()
        self.received = []

        class Collect(DatagramProtocol):

            def datagramReceived(cself, data, host_port):
                self.got_data(data)

        self.port = reactor.listenUDP(0, Collect())

        self.processor = TestMessageProcessor()
        self.router = Router(self.processor,
            r"any => redirect_udp 127.0.0.1 %s" %
            (self.port.getHost().port,),
            service=self.service)
        self.service.startService()
        return self.router.ready

Example 3

Project: tahoe-lafs Source File: check_memory.py
    def __init__(self, basedir, mode):
        self.basedir = basedir = abspath_expanduser_unicode(unicode(basedir))
        if not (basedir + os.path.sep).startswith(abspath_expanduser_unicode(u".") + os.path.sep):
            raise AssertionError("safety issue: basedir must be a subdir")
        self.testdir = testdir = os.path.join(basedir, "test")
        if os.path.exists(testdir):
            shutil.rmtree(testdir)
        fileutil.make_dirs(testdir)
        self.sparent = service.MultiService()
        self.sparent.startService()
        self.proc = None
        self.tub = Tub()
        self.tub.setOption("expose-remote-exception-types", False)
        self.tub.setServiceParent(self.sparent)
        self.mode = mode
        self.failed = False
        self.keepalive_file = None

Example 4

Project: tahoe-lafs Source File: check_speed.py
    def __init__(self, test_client_dir):
        #self.real_stderr = sys.stderr
        log.startLogging(open("st.log", "a"), setStdout=False)
        f = open(os.path.join(test_client_dir, "private", "control.furl"), "r")
        self.control_furl = f.read().strip()
        f.close()
        self.base_service = service.MultiService()
        self.failed = None
        self.upload_times = {}
        self.download_times = {}

Example 5

Project: tahoe-lafs Source File: no_network.py
Function: add_server
    def add_server(self, i, ss):
        # to deal with the fact that all StorageServers are named 'storage',
        # we interpose a middleman
        middleman = service.MultiService()
        middleman.setServiceParent(self)
        ss.setServiceParent(middleman)
        serverid = ss.my_nodeid
        self.servers_by_number[i] = ss
        wrapper = wrap_storage_server(ss)
        self.wrappers_by_id[serverid] = wrapper
        self.proxies_by_id[serverid] = NoNetworkServer(serverid, wrapper)
        self.rebuild_serverlist()

Example 6

Project: magic-wormhole Source File: common.py
    def _setup_relay(self, error):
        self.sp = service.MultiService()
        self.sp.startService()
        self.relayport = allocate_tcp_port()
        self.transitport = allocate_tcp_port()
        # need to talk to twisted team about only using unicode in
        # endpoints.serverFromString
        s = RelayServer("tcp:%d:interface=127.0.0.1" % self.relayport,
                        "tcp:%s:interface=127.0.0.1" % self.transitport,
                        advertise_version=__version__,
                        signal_error=error)
        s.setServiceParent(self.sp)
        self._rendezvous = s._rendezvous
        self._transit_server = s._transit
        self.relayurl = u"ws://127.0.0.1:%d/v1" % self.relayport
        self.rdv_ws_port = self.relayport
        # ws://127.0.0.1:%d/wormhole-relay/ws
        self.transit = u"tcp:127.0.0.1:%d" % self.transitport

Example 7

Project: petmail Source File: common.py
    def setUp(self):
        self.sparent = service.MultiService()
        self.sparent.startService()
        d = allocate_port()
        def _allocated(port):
            p = "tcp:%d:interface=127.0.0.1" % port
            r = RelayServer(p, None, wormhole.__version__)
            r.setServiceParent(self.sparent)
            self.relay_url = "http://127.0.0.1:%d/wormhole-relay/" % port
        d.addCallback(_allocated)
        return d

Example 8

Project: Piped Source File: test_zeromq.py
Function: set_up
    def setUp(self):
        self.mocker = mocker.Mocker()
        self.runtime_environment = processing.RuntimeEnvironment()
        self.runtime_environment.application = service.MultiService()
        self.runtime_environment.configuration_manager.set('zmq', dict())

        self.dependency_manager = self.runtime_environment.dependency_manager
        self.dependency_manager.configure(self.runtime_environment)

Example 9

Project: Piped Source File: test_zeromq.py
Function: set_up
    def setUp(self):
        self.mocker = mocker.Mocker()
        self.runtime_environment = processing.RuntimeEnvironment()
        self.runtime_environment.application = service.MultiService()

        self.dependency_manager = self.runtime_environment.dependency_manager
        self.dependency_manager.configure(self.runtime_environment)

        self.resource_manager = self.runtime_environment.resource_manager

Example 10

Project: twisted-intro Source File: fastpoetry_plugin.py
Function: make_service
    def makeService(self, options):
        top_service = service.MultiService()

        poetry_service = PoetryService(options['poem'])
        poetry_service.setServiceParent(top_service)

        factory = PoetryFactory(poetry_service)
        tcp_service = internet.TCPServer(int(options['port']), factory,
                                         interface=options['iface'])
        tcp_service.setServiceParent(top_service)

        return top_service

Example 11

Project: mythbox Source File: test_application.py
    def testAddingIntoRunning(self):
        p = service.MultiService()
        p.startService()
        s = service.Service()
        self.assert_(not s.running)
        s.setServiceParent(p)
        self.assert_(s.running)
        s.disownServiceParent()
        self.assert_(not s.running)

Example 12

Project: mythbox Source File: test_application.py
    def testTCP(self):
        s = service.MultiService()
        s.startService()
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        t = internet.TCPServer(0, factory)
        t.setServiceParent(s)
        num = t._port.getHost().port
        factory = protocol.ClientFactory()
        factory.d = defer.Deferred()
        factory.protocol = Foo
        factory.line = None
        internet.TCPClient('127.0.0.1', num, factory).setServiceParent(s)
        factory.d.addCallback(self.assertEqual, 'lalala')
        factory.d.addCallback(lambda x : s.stopService())
        factory.d.addCallback(lambda x : TestEcho.d)
        return factory.d

Example 13

Project: ccs-calendarserver Source File: sim.py
    def attachServices(self, output):
        self.ms = MultiService()
        for svcclass in self.serviceClasses():
            svcclass(self, output).setServiceParent(self.ms)
        attachService(self.reactor, self, self.ms)
        self.startAmpHub()

Example 14

Project: worker Source File: server.py
def run():

    config.read()
    logs.api()

    top_service = service.MultiService()

    db = Db()
    datalib.db = db
    db.setServiceParent(top_service)

    http_service = internet.TCPServer(config.HTTP_PORT, Site(db), interface=config.HTTP_ADDR)
    http_service.setServiceParent(top_service)

    top_service.startService()

    reactor.addSystemEventTrigger('before', 'shutdown', top_service.stopService)

    reactor.run()

Example 15

Project: SubliminalCollaborator Source File: tap.py
def makeService(config):
    ca, cl = _buildResolvers(config)

    f = server.DNSServerFactory(config.zones, ca, cl, config['verbose'])
    p = dns.DNSDatagramProtocol(f)
    f.noisy = 0
    ret = service.MultiService()
    for (klass, arg) in [(internet.TCPServer, f), (internet.UDPServer, p)]:
        s = klass(config['port'], arg, interface=config['interface'])
        s.setServiceParent(ret)
    for svc in config.svcs:
        svc.setServiceParent(ret)
    return ret

Example 16

Project: restkin Source File: api.py
Function: make_service
def makeService(config):
    s = MultiService()

    push_tracer(
        ZipkinTracer(
            ScribeClient(
                clientFromString(reactor, config['scribe']))))

    root = RootResource()

    if config['rproxy']:
        root = RProxyWrapper(root)

    site = server.Site(root)
    site.displayTracebacks = False

    api_service = strports.service(config['port'], site)
    api_service.setServiceParent(s)

    return s

Example 17

Project: restkin Source File: scribe.py
Function: make_service
def makeService(config):
    s = MultiService()

    keystone_url = os.getenv(
        'KEYSTONE_URL',
        'https://identity.api.rackspacecloud.com/v2.0/tokens')

    keystone_user = os.getenv('KEYSTONE_USER')
    keystone_pass = os.getenv('KEYSTONE_PASS')

    agent = Agent(reactor, pool=HTTPConnectionPool(reactor, persistent=True))
    if keystone_user and keystone_pass:
        agent = KeystoneAgent(
            agent,
            keystone_url, (keystone_user, keystone_pass))

    handler = RESTKinHandler(agent, config['restkin-url'])

    scribe_service = ScribeServerService(
        serverFromString(reactor, config['port']),
        handler)
    scribe_service.setServiceParent(s)

    return s

Example 18

Project: idavoll Source File: tap.py
def makeService(config):
    s = service.MultiService()

    # Create backend service with storage

    if config['backend'] == 'pgsql':
        from twisted.enterprise import adbapi
        from idavoll.pgsql_storage import Storage
        from psycopg2.extras import NamedTupleConnection
        dbpool = adbapi.ConnectionPool('psycopg2',
                                       user=config['dbuser'],
                                       password=config['dbpass'],
                                       database=config['dbname'],
                                       host=config['dbhost'],
                                       port=config['dbport'],
                                       cp_reconnect=True,
                                       client_encoding='utf-8',
                                       connection_factory=NamedTupleConnection,
                                       )
        st = Storage(dbpool)
    elif config['backend'] == 'memory':
        from idavoll.memory_storage import Storage
        st = Storage()

    bs = BackendService(st)
    bs.setName('backend')
    bs.setServiceParent(s)

    # Set up XMPP server-side component with publish-subscribe capabilities

    cs = Component(config["rhost"], int(config["rport"]),
                   config["jid"].full(), config["secret"])
    cs.setName('component')
    cs.setServiceParent(s)

    cs.factory.maxDelay = 900

    if config["verbose"]:
        cs.logTraffic = True

    FallbackHandler().setHandlerParent(cs)
    VersionHandler('Idavoll', __version__).setHandlerParent(cs)
    DiscoHandler().setHandlerParent(cs)

    resource = IPubSubResource(bs)
    resource.hideNodes = config["hide-nodes"]
    resource.serviceJID = config["jid"]

    ps = PubSubService(resource)
    ps.setHandlerParent(cs)
    resource.pubsubService = ps

    return s

Example 19

Project: wokkel Source File: componentservertap.py
def makeService(config):
    s = service.MultiService()

    router = component.Router()

    # Set up the XMPP server service

    serverService = server.ServerService(router, secret=config['server-secret'])
    serverService.domains = config['domains']
    serverService.logTraffic = config['verbose']

    # Hook up XMPP server-to-server service
    s2sFactory = server.XMPPS2SServerFactory(serverService)
    s2sFactory.logTraffic = config['verbose']
    s2sService = strports.service(config['server-port'], s2sFactory)
    s2sService.setServiceParent(s)

    # Hook up XMPP external server-side component service
    cFactory = component.XMPPComponentServerFactory(router,
                                                    config['component-secret'])

    cFactory.logTraffic = config['verbose']
    cServer = strports.service(config['component-port'], cFactory)
    cServer.setServiceParent(s)

    return s

Example 20

Project: txstatsd Source File: service.py
def createService(options):
    """Create a txStatsD service."""
    from carbon.routers import ConsistentHashingRouter
    from carbon.client import CarbonClientManager
    from carbon.conf import settings

    settings.MAX_QUEUE_SIZE = options["max-queue-size"]
    settings.MAX_DATAPOINTS_PER_MESSAGE = options["max-datapoints-per-message"]

    root_service = MultiService()
    root_service.setName("statsd")

    prefix = options["prefix"]
    if prefix is None:
        prefix = "statsd"

    instance_name = options["instance-name"]
    if not instance_name:
        instance_name = platform.node()

    # initialize plugins
    plugin_metrics = []
    for plugin in getPlugins(IMetricFactory):
        plugin.configure(options)
        plugin_metrics.append(plugin)

    processor = None
    if options["dump-mode"]:
        # LoggingMessageProcessor supersedes
        #  any other processor class in "dump-mode"
        assert not hasattr(log, 'info')
        log.info = log.msg  # for compatibility with LMP logger interface
        processor = functools.partial(LoggingMessageProcessor, logger=log)

    if options["statsd-compliance"]:
        processor = (processor or MessageProcessor)(plugins=plugin_metrics)
        input_router = Router(processor, options['routing'], root_service)
        connection = InternalClient(input_router)
        metrics = Metrics(connection)
    else:
        processor = (processor or ConfigurableMessageProcessor)(
            message_prefix=prefix,
            internal_metrics_prefix=prefix + "." + instance_name + ".",
            plugins=plugin_metrics)
        input_router = Router(processor, options['routing'], root_service)
        connection = InternalClient(input_router)
        metrics = ExtendedMetrics(connection)

    if not options["carbon-cache-host"]:
        options["carbon-cache-host"].append("127.0.0.1")
    if not options["carbon-cache-port"]:
        options["carbon-cache-port"].append(2004)
    if not options["carbon-cache-name"]:
        options["carbon-cache-name"].append(None)

    reporting = ReportingService(instance_name)
    reporting.setServiceParent(root_service)

    reporting.schedule(report_client_manager_stats,
                       options["flush-interval"] / 1000,
                       metrics.gauge)

    if options["report"] is not None:
        from txstatsd import process
        from twisted.internet import reactor

        reporting.schedule(
            process.report_reactor_stats(reactor), 60, metrics.gauge)
        reports = [name.strip() for name in options["report"].split(",")]
        for report_name in reports:
            if report_name == "reactor":
                inspector = ReactorInspectorService(reactor, metrics,
                                                    loop_time=0.05)
                inspector.setServiceParent(root_service)

            for reporter in getattr(process, "%s_STATS" %
                                    report_name.upper(), ()):
                reporting.schedule(reporter, 60, metrics.gauge)

    # XXX Make this configurable.
    router = ConsistentHashingRouter()
    carbon_client = CarbonClientManager(router)
    carbon_client.setServiceParent(root_service)

    for host, port, name in zip(options["carbon-cache-host"],
                                options["carbon-cache-port"],
                                options["carbon-cache-name"]):
        carbon_client.startClient((host, port, name))

    statsd_service = StatsDService(carbon_client, input_router,
                                   options["flush-interval"])
    statsd_service.setServiceParent(root_service)

    statsd_server_protocol = StatsDServerProtocol(
        input_router,
        monitor_message=options["monitor-message"],
        monitor_response=options["monitor-response"])

    listener = UDPServer(options["listen-port"], statsd_server_protocol)
    listener.setServiceParent(root_service)

    if options["listen-tcp-port"] is not None:
        statsd_tcp_server_factory = StatsDTCPServerFactory(
            input_router,
            monitor_message=options["monitor-message"],
            monitor_response=options["monitor-response"])

        listener = TCPServer(options["listen-tcp-port"],
                             statsd_tcp_server_factory)
        listener.setServiceParent(root_service)

    httpinfo_service = httpinfo.makeService(options, processor, statsd_service)
    httpinfo_service.setServiceParent(root_service)

    return root_service

Example 21

Project: txstatsd Source File: test_router.py
Function: set_up
    def setUp(self):
        self.service = MultiService()
        self.received = []

        class Collect(LineReceiver):

            def lineReceived(cself, data):
                self.got_data(data)

        class CollectFactory(Factory):

            def buildProtocol(self, addr):
                return Collect()

        self.port = reactor.listenTCP(0, CollectFactory())

        self.processor = TestMessageProcessor()
        self.router = Router(self.processor,
            r"any => redirect_tcp 127.0.0.1 %s" %
            (self.port.getHost().port,),
            service=self.service)
        self.service.startService()
        return self.router.ready

Example 22

Project: fmspy Source File: fmspy_plugin.py
    def makeService(self, options):
        """
        Construct a TCPServer from a factory defined in myproject.
        """
        observer = log.FileLogObserver(sys.stderr)
        log.addObserver(observer.emit)

        from fmspy.config import config
        
        if options['rtmp-port'] != 1935:
            config.set('RTMP', 'port', options['rtmp-port'])
        if options['rtmp-interface'] != '':
            config.set('RTMP', 'interface', options['rtmp-interface'])

        from twisted.application import internet, service
        from fmspy.rtmp.protocol import RTMPServerFactory

        s = service.MultiService()

        h = internet.TCPServer(config.getint('RTMP', 'port'), RTMPServerFactory(), config.getint('RTMP', 'backlog'), config.get('RTMP', 'interface'))
        h.setServiceParent(s)

        log.msg('RTMP server at port %d.' % config.getint('RTMP', 'port'))

        from fmspy.application import app_factory

        def appsLoaded(_):
            log.msg("Applications loaded.")

        def appsError(fail):
            log.err(fail, "Applications failed to load.")

        app_factory.load_applications().addCallbacks(appsLoaded, appsError)

        if config.getboolean('HTTP', 'enabled'):
            from twisted.web import server, static, resource

            root = resource.Resource()

            if config.getboolean('HTTP', 'examples-enabled'):
                examples_path = 'examples/'

                try:
                    from pkg_resources import Requirement, resource_filename, DistributionNotFound

                    try:
                        examples_path = resource_filename(Requirement.parse("fmspy"), "share/examples")
                    except DistributionNotFound:
                        pass

                except ImportError:
                    pass 

                root.putChild('examples', static.File(examples_path))

                h = internet.TCPServer(config.getint('HTTP', 'port'), server.Site(root))
                h.setServiceParent(s)

                log.msg('HTTP server at port %d.' % config.getint('HTTP', 'port'))

        log.removeObserver(observer.emit)

        return s

Example 23

Project: txTelegramBot Source File: telegrambot_plugin.py
    def makeService(self, options):
        if options['config'] is None:
            print('Config file not specified')
            exit(1)
        config = ConfigParser()
        config.optionxform = str
        config.read([options['config']])

        token = config['telegrambot']['token']

        proxy = config['proxy'].get('address', None)
        if proxy:
            os.environ['http_proxy'] = 'http://%s' % proxy
            os.environ['https_proxy'] = 'https://%s' % proxy

        msg_plugins = [v for v in config['message_plugins'].values()]

        for key, value in config['env'].items():
            os.environ[key] = value

        multi = service.MultiService()

        bot = BotService(plugin_filespec=msg_plugins)
        bot.setServiceParent(multi)

        client = TwistedClient(token, bot.on_update, proxy=proxy)
        client.setServiceParent(multi)

        return multi

Example 24

Project: tahoe-lafs Source File: no_network.py
Function: set_up
    def setUp(self):
        self.s = service.MultiService()
        self.s.startService()

Example 25

Project: tahoe-lafs Source File: test_client.py
    def test_create_magic_folder_service(self):
        class MockMagicFolder(service.MultiService):
            name = 'magic-folder'

            def __init__(self, client, upload_dircap, collective_dircap, local_path_u, dbfile, umask, inotify=None,
                         uploader_delay=1.0, clock=None, downloader_delay=3):
                service.MultiService.__init__(self)
                self.client = client
                self._umask = umask
                self.upload_dircap = upload_dircap
                self.collective_dircap = collective_dircap
                self.local_dir = local_path_u
                self.dbfile = dbfile
                self.inotify = inotify

            def ready(self):
                pass

        self.patch(allmydata.frontends.magic_folder, 'MagicFolder', MockMagicFolder)

        upload_dircap = "URI:DIR2:blah"
        local_dir_u = self.unicode_or_fallback(u"loc\u0101l_dir", u"local_dir")
        local_dir_utf8 = local_dir_u.encode('utf-8')
        config = (BASECONFIG +
                  "[storage]\n" +
                  "enabled = false\n" +
                  "[magic_folder]\n" +
                  "enabled = true\n")

        basedir1 = "test_client.Basic.test_create_magic_folder_service1"
        os.mkdir(basedir1)

        fileutil.write(os.path.join(basedir1, "tahoe.cfg"),
                       config + "local.directory = " + local_dir_utf8 + "\n")
        self.failUnlessRaises(MissingConfigEntry, client.Client, basedir1)

        fileutil.write(os.path.join(basedir1, "tahoe.cfg"), config)
        fileutil.write(os.path.join(basedir1, "private", "magic_folder_dircap"), "URI:DIR2:blah")
        fileutil.write(os.path.join(basedir1, "private", "collective_dircap"), "URI:DIR2:meow")
        self.failUnlessRaises(MissingConfigEntry, client.Client, basedir1)

        fileutil.write(os.path.join(basedir1, "tahoe.cfg"),
                       config.replace("[magic_folder]\n", "[drop_upload]\n"))
        self.failUnlessRaises(OldConfigOptionError, client.Client, basedir1)

        fileutil.write(os.path.join(basedir1, "tahoe.cfg"),
                       config + "local.directory = " + local_dir_utf8 + "\n")
        c1 = client.Client(basedir1)
        magicfolder = c1.getServiceNamed('magic-folder')
        self.failUnless(isinstance(magicfolder, MockMagicFolder), magicfolder)
        self.failUnlessReallyEqual(magicfolder.client, c1)
        self.failUnlessReallyEqual(magicfolder.upload_dircap, upload_dircap)
        self.failUnlessReallyEqual(os.path.basename(magicfolder.local_dir), local_dir_u)
        self.failUnless(magicfolder.inotify is None, magicfolder.inotify)
        self.failUnless(magicfolder.running)

        class Boom(Exception):
            pass
        def BoomMagicFolder(client, upload_dircap, collective_dircap, local_path_u, dbfile,
                            umask, inotify=None, uploader_delay=1.0, clock=None, downloader_delay=3):
            raise Boom()
        self.patch(allmydata.frontends.magic_folder, 'MagicFolder', BoomMagicFolder)

        basedir2 = "test_client.Basic.test_create_magic_folder_service2"
        os.mkdir(basedir2)
        os.mkdir(os.path.join(basedir2, "private"))
        fileutil.write(os.path.join(basedir2, "tahoe.cfg"),
                       BASECONFIG +
                       "[magic_folder]\n" +
                       "enabled = true\n" +
                       "local.directory = " + local_dir_utf8 + "\n")
        fileutil.write(os.path.join(basedir2, "private", "magic_folder_dircap"), "URI:DIR2:blah")
        fileutil.write(os.path.join(basedir2, "private", "collective_dircap"), "URI:DIR2:meow")
        self.failUnlessRaises(Boom, client.Client, basedir2)

Example 26

Project: tahoe-lafs Source File: test_client.py
Function: set_up
    def setUp(self):
        self.sparent = service.MultiService()
        self.sparent.startService()

Example 27

Project: ooni-backend Source File: oonibackend.py
    def makeService(self, so):
        ooniBackendService = service.MultiService()

        if config.helpers['ssl'].port:
            print "Starting SSL helper on %s" % config.helpers['ssl'].port
            ssl_helper = internet.SSLServer(int(config.helpers['ssl'].port),
                                            http_helpers.HTTPReturnJSONHeadersHelper(),
                                            ssl_helpers.SSLContext(config))
            ooniBackendService.addService(ssl_helper)

        # Start the DNS Server related services
        if config.helpers['dns'].tcp_port:
            print "Starting TCP DNS Helper on %s" % config.helpers['dns'].tcp_port
            tcp_dns_helper = internet.TCPServer(int(config.helpers['dns'].tcp_port),
                                                dns_helpers.DNSTestHelper())
            ooniBackendService.addService(tcp_dns_helper)

        if config.helpers['dns'].udp_port:
            print "Starting UDP DNS Helper on %s" % config.helpers['dns'].udp_port
            udp_dns_factory = dns.DNSDatagramProtocol(dns_helpers.DNSTestHelper())
            udp_dns_helper = internet.UDPServer(int(config.helpers['dns'].udp_port),
                                                udp_dns_factory)
            ooniBackendService.addService(udp_dns_helper)

        if config.helpers['dns_discovery'].udp_port:
            print ("Starting UDP DNS Discovery Helper on %s" %
                   config.helpers['dns_discovery'].udp_port)
            udp_dns_discovery = internet.UDPServer(
                int(config.helpers['dns_discovery'].udp_port),
                dns.DNSDatagramProtocol(dns_helpers.DNSResolverDiscovery())
            )
            ooniBackendService.addService(udp_dns_discovery)

        if config.helpers['dns_discovery'].tcp_port:
            print ("Starting TCP DNS Discovery Helper on %s" %
                   config.helpers['dns_discovery'].tcp_port)
            tcp_dns_discovery = internet.TCPServer(
                int(config.helpers['dns_discovery'].tcp_port),
                dns_helpers.DNSResolverDiscovery()
            )
            ooniBackendService.addService(tcp_dns_discovery)

        # XXX this needs to be ported
        # Start the OONI daphn3 backend
        if config.helpers['daphn3'].port:
            print "Starting Daphn3 helper on %s" % config.helpers['daphn3'].port
            daphn3_helper = internet.TCPServer(int(config.helpers['daphn3'].port),
                                               tcp_helpers.Daphn3Server())
            ooniBackendService.addService(daphn3_helper)

        if config.helpers['tcp-echo'].port:
            print "Starting TCP echo helper on %s" % config.helpers['tcp-echo'].port
            tcp_echo_helper = internet.TCPServer(int(config.helpers['tcp-echo'].port),
                                                 tcp_helpers.TCPEchoHelper())
            ooniBackendService.addService(tcp_echo_helper)

        if config.helpers['http-return-json-headers'].port:
            print ("Starting HTTP return request helper on %s" %
                   config.helpers['http-return-json-headers'].port)
            http_return_request_helper = internet.TCPServer(
                int(config.helpers['http-return-json-headers'].port),
                http_helpers.HTTPReturnJSONHeadersHelper())
            ooniBackendService.addService(http_return_request_helper)

        # this is to ensure same behaviour with an old config file
        if config.main.tor_hidden_service and \
                config.main.bouncer_endpoints is None and \
                config.main.collector_endpoints is None:
            bouncer_hsdir   = os.path.join(config.main.tor_datadir, 'bouncer')
            collector_hsdir = os.path.join(config.main.tor_datadir, 'collector')
            config.main.bouncer_endpoints   = [ {'type': 'onion', 'hsdir':   bouncer_hsdir} ]
            config.main.collector_endpoints = [ {'type': 'onion', 'hsdir': collector_hsdir} ]

        for endpoint_config in config.main.get('bouncer_endpoints', []):
            if config.main.bouncer_file:
                print "Starting bouncer with config %s" % endpoint_config
                endpoint = getEndpoint(endpoint_config)
                bouncer_service = createService(endpoint, 'bouncer',
                                                endpoint_config)
                ooniBackendService.addService(bouncer_service)
            else:
                print "No bouncer configured"

        for endpoint_config in config.main.get('collector_endpoints', []):
            print "Starting collector with config %s" % endpoint_config
            endpoint = getEndpoint(endpoint_config)
            collector_service = createService(endpoint, 'collector',
                                              endpoint_config)
            ooniBackendService.addService(collector_service)

        for endpoint_config in config.helpers.web_connectivity.get('endpoints', []):
            print "Starting web_connectivity helper with config %s" % endpoint_config
            endpoint = getEndpoint(endpoint_config)
            web_connectivity_service = createService(endpoint,
                                                     'web_connectivity',
                                                     endpoint_config)
            ooniBackendService.addService(web_connectivity_service)


        return ooniBackendService

Example 28

Project: trigger Source File: trigger_xmlrpc.py
    def makeService(self, options):
        rpc = TriggerXMLRPCServer(allowNone=True, useDateTime=True)
        xmlrpc.addIntrospection(rpc)
        site_factory = server.Site(rpc)

        # Try to setup SSL
        if ssl is not None:
            ctx = ssl.DefaultOpenSSLContextFactory(options['ssl-keyfile'],
                                                   options['ssl-certfile'])
            xmlrpc_service = SSLServer(int(options['port']), site_factory, ctx)
        # Or fallback to clear-text =(
        else:
            xmlrpc_service = TCPServer(int(options['port']), site_factory)

        # SSH Manhole service
        console_service = makeConsoleService(
            {
                'sshPort': 'tcp:%s' % options['ssh-port'],
                'sshKeyDir': options['ssh-keydir'],
                'sshKeyName': options['ssh-keyname'],
                'sshKeySize': options['ssh-keysize'],
                'telnetPort': None,
                'passwd': options['ssh-users'],
                'namespace': {
                    'service': rpc,
                    'rebuild': rebuild,
                    'factory': site_factory,
                }
            }
        )

        svc = MultiService()
        xmlrpc_service.setServiceParent(svc)
        console_service.setServiceParent(svc)
        return svc

Example 29

Project: vertex Source File: test_q2q.py
    def setUp(self):
        self.fromAddress = q2q.Q2QAddress(self.fromDomain, self.fromResource)
        self.toAddress = q2q.Q2QAddress(self.toDomain, self.toResource)

        # A mapping of host names to port numbers Our connectTCP will always
        # connect to 127.0.0.1 and on a port which is a value in this
        # dictionary.
        fakeDNS = FakeConnectTCP(reactor.connectTCP)
        reactor.connectTCP = fakeDNS.connectTCP

        # ALSO WE MUST DO OTHER SIMILAR THINGS
        self._oldResolver = reactor.resolver
        reactor.installResolver(fakeDNS)

        # Set up a know-nothing service object for the client half of the
        # conversation.
        self.serverService2 = self._makeQ2QService(self.fromDomain, self.fromIP, noResources)

        # Do likewise for the server half of the conversation.  Also, allow
        # test methods to set up some trivial resources which we can attempt to
        # access from the client.
        self.resourceMap = {}
        self.serverService = self._makeQ2QService(self.toDomain, self.toIP,
                                                  self.protocolFactoryLookup)

        self.msvc = service.MultiService()
        self.serverService2.setServiceParent(self.msvc)
        self.serverService.setServiceParent(self.msvc)

        # Let the kernel allocate a random port for each of these service's listeners
        self.msvc.startService()

        fakeDNS.addHostPort(
            self.fromDomain, 8788,
            self.serverService2.q2qPort.getHost().port)

        fakeDNS.addHostPort(
            self.toDomain, 8788,
            self.serverService.q2qPort.getHost().port)

        self._addQ2QProtocol('pony', OneTrickPonyServerFactory())

        self.dataEater = DataEater()
        self._addQ2QProtocol('eat', self.dataEater)

        self._addQ2QProtocol('error', ErroneousServerFactory())

Example 30

Project: wiremaps Source File: service.py
def makeService(config):

    # Use psyco if available
    try:
        import psyco
        psyco.full()
    except ImportError:
        pass

    # configuration file
    configfile = yaml.load(file(config['config'], 'rb').read())
    # database
    dbpool = Database(configfile).pool
    application = service.MultiService()

    collector = CollectorService(configfile, dbpool)
    collector.setServiceParent(application)

    web = internet.TCPServer(int(config['port']),
                             appserver.NevowSite(MainPage(configfile,
                                                      dbpool,
                                                      collector)),
                             interface=config['interface'])
    web.setServiceParent(application)
    return application

Example 31

Project: foolscap Source File: test_call.py
Function: set_up
    def setUp(self):
        self.s = service.MultiService()
        self.target_tub, self.source_tub = self.makeTubs(2)
        self.target_tub.setServiceParent(self.s)
        self.source_tub.setServiceParent(self.s)

Example 32

Project: spinoff Source File: startnode.py
    def makeService(self, options):
        actor = options['actor']
        if not actor:
            fatal("error: no actor specified")
            sys.exit(1)

        try:
            module_path, actor_cls_name = actor.rsplit('.', 1)
        except ValueError:
            fatal("error: invalid path to actor %s" % actor)
            sys.exit(1)

        try:
            mod = __import__(module_path, globals(), locals(), [actor_cls_name], -1)
        except ImportError:
            fatal("error: could not import %s:\n%s" % (actor, traceback.format_exc()))
            sys.exit(1)

        try:
            actor_cls = getattr(mod, actor_cls_name)
        except AttributeError:
            fatal("error: no such actor %s" % actor)
            sys.exit(1)

        kwargs = {}

        if options['params'] is not _EMPTY:
            params = 'dict(%s)' % (options['params'],)
            try:
                params = eval(params)
            except:
                fatal("error: could not parse parameters")
                sys.exit(1)
            else:
                kwargs['init_params'] = params

        if options['message'] is not _EMPTY:
            initial_message = options['message']
            try:
                initial_message = eval(initial_message)
            except:
                fatal("error: could not parse initial message")
                sys.exit(1)
            else:
                kwargs['initial_message'] = initial_message

        if options['name']:
            name = options['name']
            if '/' in name:
                fatal("invalid name: names cannot contain slashes")
                sys.exit(1)
            else:
                kwargs['name'] = name

        if options['remoting']:
            nodeid = options['remoting']
            try:
                _validate_nodeid(nodeid)
            except TypeError:
                fatal("invalid node ID")
                sys.exit(1)
            else:
                kwargs['nodeid'] = nodeid

        kwargs['keep_running'] = options['keeprunning']

        m = MultiService()
        actor_runner = ActorRunner(actor_cls, **kwargs)
        actor_runner.setServiceParent(m)

        # manhole

        if options['remotedebugging']:
            port = options['remotedebuggingport']
            try:
                port = int(port)
            except ValueError:
                fatal("Invalid port specified: %r" % port)
                sys.exit(1)

            username = options['remotedebuggingusername']
            password = options['remotedebuggingpassword']

            manhole = self.make_manhole_server(port, username, password)
            manhole.setServiceParent(m)

        return m

Example 33

Project: Tickery Source File: tickery_service.py
    def makeService(self, options):
        if not options['noisy-logging']:
            protocol.Factory.noisy = False

        endpoint = twitterEndpoint(options['endpoint'])
        tickeryService = service.MultiService()
        cache = TickeryCache(
            options['cache-dir'], options['restore-add-queue'],
            int(options['queue-width']), endpoint)
        cache.setServiceParent(tickeryService)

        root = File('tickery/www/output')
        root.putChild('tickery', RegularService(cache, endpoint))
        root.putChild(defaults.TICKERY_CALLBACK_CHILD,
                      callback.Callback(cache))

        adminRoot = File('tickery/admin/output')
        adminRoot.putChild('tickery', AdminService(cache))
        root.putChild('admin', adminRoot)

        factory = server.Site(root)
        if options['promiscuous']:
            kw = {}
        else:
            kw = {'interface': 'localhost'}
        tickeryServer = internet.TCPServer(int(options['port']), factory, **kw)
        tickeryServer.setServiceParent(tickeryService)

        return tickeryService

Example 34

Project: Piped Source File: test_providers.py
Function: set_up
    def setUp(self):
        self.runtime_environment = processing.RuntimeEnvironment()
        self.runtime_environment.application = service.MultiService()
        self.runtime_environment.configure()

Example 35

Project: Piped Source File: test_providers.py
Function: set_up
    def setUp(self):
        self.service = service.MultiService()

Example 36

Project: Piped Source File: test_tick_processors.py
    def setUp(self):
        self.runtime_environment = processing.RuntimeEnvironment()
        self.runtime_environment.application = service.MultiService()
        self.runtime_environment.application.startService()
        
        self.runtime_environment.resource_manager.register('pipeline.test_pipeline', self)

        self.dependency_manager = self.runtime_environment.dependency_manager
        self.dependency_manager.configure(self.runtime_environment)

        self.provider = tick_provider.TickProvider()
        self.provider.setServiceParent(self.runtime_environment.application)

        self.intervals = dict()
        self.runtime_environment.configuration_manager.set('ticks.interval', self.intervals)

        self.start_processor = tick_processors.StartInterval('test_interval')
        self.stop_processor = tick_processors.StopInterval('test_interval')

        self.ticks = defer.DeferredQueue()

Example 37

Project: Piped Source File: test_smtp_provider.py
Function: set_up
    def setUp(self):
        self.runtime_environment = processing.RuntimeEnvironment()
        self.application = self.runtime_environment.application = service.MultiService()

Example 38

Project: Piped Source File: test_smtp_provider.py
Function: set_up
    def setUp(self):
        self.runtime_environment = processing.RuntimeEnvironment()
        self.cm = self.runtime_environment.configuration_manager
        self.application = self.runtime_environment.application = service.MultiService()

Example 39

Project: Piped Source File: test_spread_provider.py
Function: set_up
    def setUp(self):
        self.runtime_environment = processing.RuntimeEnvironment()
        self.application = self.runtime_environment.application = service.MultiService()

        self.runtime_environment.configure()

Example 40

Project: rproxy Source File: __init__.py
def makeService(config):

    ini = ConfigParser.RawConfigParser()
    ini.read(config['config'])

    configPath = FilePath(config['config']).parent()

    rproxyConf = dict(ini.items("rproxy"))
    hostsConf = dict(ini.items("hosts"))

    hosts = {}

    for k, v in hostsConf.items():

        k = k.lower()
        hostname, part = k.rsplit("_", 1)

        if hostname not in hosts:
            hosts[hostname] = {}

        hosts[hostname][part] = v

    if not hosts:
        raise ValueError("No hosts configured.")

    for i in hosts:

        if "port" not in hosts[i]:
            raise ValueError("All hosts need a port.")

        if "host" not in hosts[i]:
            print("%s does not have a host, making localhost" % (i,))
            hosts[i]["host"] = "localhost"

        if "onlysecure" not in hosts[i]:
            print("%s does not have an onlysecure setting, making False" % (i,))
            hosts[i]["onlysecure"] = False

        if "wwwtoo" not in hosts[i]:
            print("%s does not have an wwwtoo setting, making True" % (i,))
            hosts[i]["wwwtoo"] = "True"

        if "proxysecure" not in hosts[i]:
            print("%s does not have an proxysecure setting, making False" % (i,))
            hosts[i]["proxysecure"] = False

        if "sendhsts" not in hosts[i]:
            print("%s does not have an sendhsts setting, making the value of onlysecure" % (i,))
            hosts[i]["sendhsts"] = hosts[i]["onlysecure"]

        hosts[i]["onlysecure"] = True if hosts[i]["onlysecure"]=="True" else False
        hosts[i]["proxysecure"] = True if hosts[i]["proxysecure"]=="True" else False
        hosts[i]["sendhsts"] = True if hosts[i]["sendhsts"]=="True" else False
        hosts[i]["wwwtoo"] = True if hosts[i]["wwwtoo"]=="True" else False

        if hosts[i]["onlysecure"] and not hosts[i]["proxysecure"]:
            if not hosts[i].get("iamokwithalocalnetworkattackerpwningmyusers", "False") == "True":
                raise ValueError("%s has onlysecure==True, but proxysecure==False. This will mean TLS protected requests will not be TLS-protected between the proxy and the proxied server. If this is okay (e.g., if it's going over localhost), set %s_iamokwithalocalnetworkattackerpwningmyusers=True in your config." % (i, i))

        if hosts[i]["proxysecure"] and not hosts[i]["onlysecure"]:
            if not hosts[i].get("iamokwithlyingtomyproxiedserverthatheuserisoverhttps", "False") == "True":
                raise ValueError("%s has onlysecure==False, but proxysecure==True. This means that the connection may not be TLS protected between the user and this proxy, only the proxy and the proxied server. This can trick your proxied server into thinking the user is being served over HTTPS. If this is okay (I can't imagine why it is), set %s_iamokwithlyingtomyproxiedserverthatheuserisoverhttps=True in your config." % (i, i))

    from twisted.internet import reactor
    pool = HTTPConnectionPool(reactor)

    resource = RProxyResource(hosts, rproxyConf.get("clacks"), pool, reactor)

    site = server.Site(resource)
    multiService = service.MultiService()
    certificates = rproxyConf.get("certificates", None)

    if certificates:
        try:
            configPath.child(certificates).makedirs()
        except:
            pass

        certificates = configPath.child(certificates).path
        for i in rproxyConf.get("https_ports").split(","):
            print("Starting HTTPS on port " + i)
            multiService.addService(strports.service('le:' + certificates + ':tcp:' + i, site))

        for host in hosts.keys():
            with open(FilePath(certificates).child(host + ".pem").path, 'w'):
                # Open it so that txacme can find it
                pass
            if hosts[host]["wwwtoo"]:
                with open(FilePath(certificates).child("www." + host + ".pem").path, 'w'):
                    # Open it so that txacme can find it
                    pass

    for i in rproxyConf.get("http_ports", "").split(","):
        print("Starting HTTP on port " + i)
        multiService.addService(strports.service('tcp:' + i, site))

    return multiService

Example 41

Project: ibid Source File: ibid_plugin.py
    def makeService(self, options):
        service = MultiService()
        ibid.setup(options, service)
        return service

Example 42

Project: mythbox Source File: manhole_tap.py
def makeService(options):
    """Create a manhole server service.

    @type options: C{dict}
    @param options: A mapping describing the configuration of
    the desired service.  Recognized key/value pairs are::

        "telnetPort": strports description of the address on which
                      to listen for telnet connections.  If None,
                      no telnet service will be started.

        "sshPort": strports description of the address on which to
                   listen for ssh connections.  If None, no ssh
                   service will be started.

        "namespace": dictionary containing desired initial locals
                     for manhole connections.  If None, an empty
                     dictionary will be used.

        "passwd": Name of a passwd(5)-format username/password file.

    @rtype: L{twisted.application.service.IService}
    @return: A manhole service.
    """

    svc = service.MultiService()

    namespace = options['namespace']
    if namespace is None:
        namespace = {}

    checker = checkers.FilePasswordDB(options['passwd'])

    if options['telnetPort']:
        telnetRealm = _StupidRealm(telnet.TelnetBootstrapProtocol,
                                   insults.ServerProtocol,
                                   manhole.ColoredManhole,
                                   namespace)

        telnetPortal = portal.Portal(telnetRealm, [checker])

        telnetFactory = protocol.ServerFactory()
        telnetFactory.protocol = makeTelnetProtocol(telnetPortal)
        telnetService = strports.service(options['telnetPort'],
                                         telnetFactory)
        telnetService.setServiceParent(svc)

    if options['sshPort']:
        sshRealm = manhole_ssh.TerminalRealm()
        sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace)

        sshPortal = portal.Portal(sshRealm, [checker])
        sshFactory = manhole_ssh.ConchFactory(sshPortal)
        sshService = strports.service(options['sshPort'],
                                      sshFactory)
        sshService.setServiceParent(svc)

    return svc

Example 43

Project: mythbox Source File: test_application.py
    def testMultiService(self):
        self.assert_(service.IService.providedBy(service.MultiService()))
        self.assert_(service.IServiceCollection.providedBy(service.MultiService()))

Example 44

Project: mythbox Source File: test_application.py
    def testUNIX(self):
        # FIXME: This test is far too dense.  It needs comments.
        #  -- spiv, 2004-11-07
        if not interfaces.IReactorUNIX(reactor, None):
            raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
        s = service.MultiService()
        s.startService()
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        t = internet.UNIXServer('echo.skt', factory)
        t.setServiceParent(s)
        factory = protocol.ClientFactory()
        factory.protocol = Foo
        factory.d = defer.Deferred()
        factory.line = None
        internet.UNIXClient('echo.skt', factory).setServiceParent(s)
        factory.d.addCallback(self.assertEqual, 'lalala')
        factory.d.addCallback(lambda x : s.stopService())
        factory.d.addCallback(lambda x : TestEcho.d)
        factory.d.addCallback(self._cbTestUnix, factory, s)
        return factory.d

Example 45

Project: Comet Source File: broker.py
def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_factory.noisy = False
        broadcaster_whitelisting_factory = WhitelistingFactory(
            broadcaster_factory, config['subscriber-whitelist'], "subscription"
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_whitelisting_factory.noisy = False
        broadcaster_service = TCPServer(
            config['broadcast-port'],
            broadcaster_whitelisting_factory
        )
        broadcaster_service.setName("Broadcaster")
        broadcaster_service.setServiceParent(broker_service)

        # If we're running a broadcast, we will rebroadcast any events we
        # receive to it.
        config['handlers'].append(EventRelay(broadcaster_factory))

    if config['receive']:
        receiver_factory = VOEventReceiverFactory(
            local_ivo=config['local-ivo'],
            validators=[
                CheckPreviouslySeen(event_db),
                CheckSchema(
                    os.path.join(comet.__path__[0], "schema/VOEvent-v2.0.xsd")
                ),
                CheckIVORN()
            ],
            handlers=config['handlers']
        )
        if log.LEVEL >= log.Levels.INFO: receiver_factory.noisy = False
        author_whitelisting_factory = WhitelistingFactory(
            receiver_factory, config['author-whitelist'], "submission"
        )
        if log.LEVEL >= log.Levels.INFO: author_whitelisting_factory.noisy = False
        receiver_service = TCPServer(config['receive-port'], author_whitelisting_factory)
        receiver_service.setName("Receiver")
        receiver_service.setServiceParent(broker_service)

    for host, port in config["remotes"]:
        subscriber_factory = VOEventSubscriberFactory(
            local_ivo=config["local-ivo"],
            validators=[CheckPreviouslySeen(event_db)],
            handlers=config['handlers'],
            filters=config['filters']
        )
        if log.LEVEL >= log.Levels.INFO: subscriber_factory.noisy = False
        remote_service = TCPClient(host, port, subscriber_factory)
        remote_service.setName("Remote %s:%d" % (host, port))
        remote_service.setServiceParent(broker_service)

    if not broker_service.services:
        reactor.callWhenRunning(log.warn, "No services requested; stopping.")
        reactor.callWhenRunning(reactor.stop)
    return broker_service

Example 46

Project: shinysdr Source File: main.py
@defer.inlineCallbacks
def _main_async(reactor, argv=None, _abort_for_test=False):
    if argv is None:
        argv = sys.argv
    
    if not _abort_for_test:
        # Configure logging. Some log messages would be discarded if we did not set up things early
        # TODO: Consult best practices for Python and Twisted logging.
        # TODO: Logs which are observably relevant should be sent to the client (e.g. the warning of refusing to have more receivers active)
        logging.basicConfig(level=logging.INFO)
        log.startLoggingWithObserver(log.PythonLoggingObserver(loggerName='shinysdr').emit, False)
    
    # Option parsing is done before importing the main modules so as to avoid the cost of initializing gnuradio if we are aborting early. TODO: Make that happen for createConfig too.
    argParser = argparse.ArgumentParser(prog=argv[0])
    argParser.add_argument('config_path', metavar='CONFIG',
        help='path of configuration directory or file')
    argParser.add_argument('--create', dest='createConfig', action='store_true',
        help='write template configuration file to CONFIG and exit')
    argParser.add_argument('-g, --go', dest='openBrowser', action='store_true',
        help='open the UI in a web browser')
    argParser.add_argument('--force-run', dest='force_run', action='store_true',
        help='Run DSP even if no client is connected (for debugging).')
    args = argParser.parse_args(args=argv[1:])

    # Verify we can actually run.
    # Note that this must be done before we actually load core modules, because we might get an import error then.
    version_report = yield _check_versions()
    if version_report:
        print >>sys.stderr, version_report
        sys.exit(1)

    # We don't actually use shinysdr.devices directly, but we want it to be guaranteed available in the context of the config file.
    # pylint: disable=unused-variable
    import shinysdr.devices as lazy_devices
    import shinysdr.source as lazy_source  # legacy shim

    # Load config file
    if args.createConfig:
        write_default_config(args.config_path)
        log.msg('Created default configuration at: ' + args.config_path)
        sys.exit(0)  # TODO: Consider using a return value or something instead
    else:
        configObj = Config(reactor)
        execute_config(configObj, args.config_path)
        yield configObj._wait_and_validate()
        
        stateFile = configObj._state_filename
    
    def noteDirty():
        if stateFile is not None:
            # just immediately write (revisit this when more performance is needed)
            with open(stateFile, 'w') as f:
                json.dump(app.state_to_json(), f)
    
    def restore(root, get_defaults):
        if stateFile is not None:
            if os.path.isfile(stateFile):
                root.state_from_json(json.load(open(stateFile, 'r')))
                # make a backup in case this code version misreads the state and loses things on save (but only if the load succeeded, in case the file but not its backup is bad)
                shutil.copyfile(stateFile, stateFile + '~')
            else:
                root.state_from_json(get_defaults(root))
    
    log.msg('Constructing...')
    app = configObj._create_app()
    
    singleton_reactor.addSystemEventTrigger('during', 'shutdown', app.close_all_devices)
    
    log.msg('Restoring state...')
    restore(app, _app_defaults)
    
    log.msg('Starting web server...')
    services = MultiService()
    for maker in configObj._service_makers:
        IService(maker(app, noteDirty)).setServiceParent(services)
    services.startService()
    
    log.msg('ShinySDR is ready.')
    
    for service in services:
        # TODO: should have an interface (currently no proper module to put it in)
        service.announce(args.openBrowser)
    
    if args.force_run:
        log.msg('force_run')
        from gnuradio.gr import msg_queue
        # TODO kludge, make this less digging into guts
        app.get_receive_flowgraph().monitor.get_fft_distributor().subscribe(msg_queue(limit=2))
    
    if _abort_for_test:
        services.stopService()
        defer.returnValue((app, noteDirty))
    else:
        yield defer.Deferred()  # never fires

Example 47

Project: SubliminalCollaborator Source File: tap.py
def makeService(config):
    s = service.MultiService()
    if config['root']:
        root = config['root']
        if config['indexes']:
            config['root'].indexNames = config['indexes']
    else:
        # This really ought to be web.Admin or something
        root = demo.Test()

    if isinstance(root, static.File):
        root.registry.setComponent(interfaces.IServiceCollection, s)

    if config['logfile']:
        site = server.Site(root, logPath=config['logfile'])
    else:
        site = server.Site(root)

    site.displayTracebacks = not config["notracebacks"]

    if config['personal']:
        personal = strports.service(
            config['port'], makePersonalServerFactory(site))
        personal.setServiceParent(s)
    else:
        if config['https']:
            from twisted.internet.ssl import DefaultOpenSSLContextFactory
            i = internet.SSLServer(int(config['https']), site,
                          DefaultOpenSSLContextFactory(config['privkey'],
                                                       config['certificate']))
            i.setServiceParent(s)
        strports.service(config['port'], site).setServiceParent(s)

    return s

Example 48

Project: SubliminalCollaborator Source File: tap.py
def makeService(config):
    credCheckers = config.get('credCheckers', [])
    wordsRealm = service.InMemoryWordsRealm(config['hostname'])
    wordsPortal = portal.Portal(wordsRealm, credCheckers)

    msvc = MultiService()

    # XXX Attribute lookup on config is kind of bad - hrm.
    for plgName in config.interfacePlugins:
        port = config.get(plgName + '-port')
        if port is not None:
            factory = config.interfacePlugins[plgName].getFactory(wordsRealm, wordsPortal)
            svc = strports.service(port, factory)
            svc.setServiceParent(msvc)

    # This is bogus.  createGroup is async.  makeService must be
    # allowed to return a Deferred or some crap.
    for g in config['groups']:
        wordsRealm.createGroup(g)

    return msvc