コード例 #1
0
ファイル: alarmserver.py プロジェクト: habnabit/txalarmclock
 def attachAlarm(self, alarm, callable):
     service = self.alarmServices.get(alarm)
     if service is not None:
         raise ValueError('alarm %r already attached' % (alarm,))
     service = self.alarmServices[alarm] = (
         AlarmService(self.collection[alarm], callable))
     service.setServiceParent(self.serviceParent)
コード例 #2
0
    def test_nonAsciiLog(self):
        """
        Make sure that the file based error log can write non ascii data
        """

        logpath = self.mktemp()
        service = ErrorLoggingMultiService(
            True,
            logpath,
            10000,
            10,
            False,
        )
        app = Application("non-ascii")
        service.setServiceParent(app)

        observer = app.getComponent(ILogObserver, None)
        self.assertTrue(observer is not None)

        log = Logger(observer=observer)
        log.error(u"Couldn\u2019t be wrong")

        with open(logpath) as f:
            logentry = f.read()
        self.assertIn("Couldn\xe2\x80\x99t be wrong", logentry)
コード例 #3
0
ファイル: app.py プロジェクト: patron-it/opencanary
def start_mod(application, klass):
    try:
        obj = klass(config=config, logger=logger)
    except Exception as e:
        err = 'Failed to instantiate instance of class %s in %s. %s' % (
            klass.__name__, klass.__module__, traceback.format_exc())
        logMsg({'logdata': err})
        return

    if hasattr(obj, 'startYourEngines'):
        try:
            obj.startYourEngines()
            msg = 'Ran startYourEngines on class %s in %s' % (klass.__name__,
                                                              klass.__module__)
            logMsg({'logdata': msg})

        except Exception as e:
            err = 'Failed to run startYourEngines on %s in %s. %s' % (
                klass.__name__, klass.__module__, traceback.format_exc())
            logMsg({'logdata': err})
    elif hasattr(obj, 'getService'):
        try:
            service = obj.getService()
            service.setServiceParent(application)
            msg = 'Added service from class %s in %s to fake' % (
                klass.__name__, klass.__module__)
            logMsg({'logdata': msg})
        except Exception as e:
            err = 'Failed to add service from class %s in %s. %s' % (
                klass.__name__, klass.__module__, traceback.format_exc())
            logMsg({'logdata': err})
    else:
        err = 'The class %s in %s does not have any required starting method.' % (
            klass.__name__, klass.__module__)
        logMsg({'logdata': err})
コード例 #4
0
ファイル: service.py プロジェクト: zzl0/Kenshin-backup
def createBaseService(options):
    root_service = RurouniRootService()
    root_service.setName('rurouni')

    receive_services = (
        (settings.LINE_RECEIVER_INTERFACE,
         settings.LINE_RECEIVER_PORT,
         protocols.MetricLineReceiver
        ),
        (settings.PICKLE_RECEIVER_INTERFACE,
         settings.PICKLE_RECEIVER_PORT,
         protocols.MetricPickleReceiver
        ),
    )
    for interface, port, protocol in receive_services:
        if port:
            factory = ServerFactory()
            factory.protocol = protocol
            service = TCPServer(int(port), factory, interface=interface)
            service.setServiceParent(root_service)

    from rurouni.state.instrumentation import InstrumentationService
    service = InstrumentationService()
    service.setServiceParent(root_service)

    return root_service
コード例 #5
0
ファイル: smtp_provider.py プロジェクト: alexbrasetvik/Piped
    def configure(self, runtime_environment):
        self.setServiceParent(runtime_environment.application)

        self.smtp_configs = runtime_environment.get_configuration_value('smtp', dict())

        for server_name, server_config in self.smtp_configs.items():
            service = PipedSMTPServer(**server_config)
            service.configure(runtime_environment)
            service.setServiceParent(self)
コード例 #6
0
ファイル: tap.py プロジェクト: gf0842wf/cpapp
 def SSHServer(self, port, passwd, namespace=None):
     namespace = namespace or {}
     namespace.update(
         root=self,
         version=version,
         share=share,
     )
     service = internet.TCPServer(port, ssh.SSHFactory(passwd, namespace))
     service.setServiceParent(self)
     return service
コード例 #7
0
ファイル: pclient.py プロジェクト: anjensan/twoost
    def _initClientService(self, connection, params):

        p = self._prepareParams(params)
        logger.debug("create protocol service %r, params %r", connection, p)

        factory = self.buildClientFactory(p)
        endpoint = self.buildClientEndpoint(p)
        service = self.buildClientService(endpoint, factory, p)

        service.setName(connection)
        service.setServiceParent(self)
コード例 #8
0
ファイル: pclient.py プロジェクト: anjensan/twoost
    def _initClientService(self, connection, params):

        p = self._prepareParams(params)
        logger.debug("create protocol service %r, params %r", connection, p)

        factory = self.buildClientFactory(p)
        endpoint = self.buildClientEndpoint(p)
        service = self.buildClientService(endpoint, factory, p)

        service.setName(connection)
        service.setServiceParent(self)
コード例 #9
0
def create_public_service(port, application):
    logger.info('Starting public Users HTTP API')
    if port:
        desc = get_tls_service_description(port)
    else:
        logger.warn('Using plain HTTP on public Users API.')
        desc = 'tcp:port=2424:interface=0.0.0.0'

    site = server.Site(entrypoints.UsersEntrypoint())
    service = strports.service(desc, site)
    service.setServiceParent(application)
コード例 #10
0
ファイル: protocols.py プロジェクト: xbernpa/carbon
  def build(cls, root_service):
    plugin_up = cls.plugin_name.upper()
    interface = settings.get('%s_RECEIVER_INTERFACE' % plugin_up, None)
    port = int(settings.get('%s_RECEIVER_PORT' % plugin_up, 0))
    protocol = cls

    if not port:
      return

    if hasattr(protocol, 'datagramReceived'):
      service = CarbonService(interface, port, protocol, None)
    else:
      factory = CarbonReceiverFactory()
      factory.protocol = protocol
      service = CarbonService(interface, port, protocol, factory)
    service.setServiceParent(root_service)
コード例 #11
0
        def helper(name, config, transport_names):
            # Helper closure passed to / called by L{_loadItemsFromConfig}
            # This will keep track of configured transports in transport_names
            # and set up a transport if applicable
            transport_names.add(name)

            # If this transport (or another with this name, which would be a
            # configuration error) is already registered, just ignore this
            # configuration item
            if name in self.registered_transports:
                return None

            log.msg('[CONTROLLER] Configuring transport %s' % name)
            # Create a transport (L{ITransport}) using the given configuration
            transport = self.loadTransport(name, config)

            # If the transport is an L{IServerTransport}...
            if IServerTransport.providedBy(transport):
                # Create a L{twisted.application.service.IService} from it
                # using settings provided in C{config}. This is *not* an
                # applicationserver  service but a Twisted service, ie a 
                # server handling incoming requests on a given socket.
                service = self.hookTransport(transport, config)
                # Set the IService name
                service.setName(name)
                # Set the IService parent to our MultiTransport
                service.setServiceParent(self.transports)

                # Parse the transport settings again so we can set up an
                # L{ITransportInfo} object for this transport
                port_info = strports.parse(config['transport'], transport)
                transport_info = transport.getTransportInfo(name, port_info)
                # Store the L{ITransportInfo}
                self.transport_info_map[name] = transport_info

                # Finally return the service
                return service
            else:
                # Set up the L{ITransportInfo} for the transport
                transport_info = transport.getTransportInfo(name)
                # Save it
                self.transport_info_map[name] = transport_info

                # And return it. We don't know how to handle this further,
                # since this is not an L{IServerTransport}, most likely the
                # 'mail' transport.
                return transport
コード例 #12
0
        def helper(name, config, transport_names):
            # Helper closure passed to / called by L{_loadItemsFromConfig}
            # This will keep track of configured transports in transport_names
            # and set up a transport if applicable
            transport_names.add(name)

            # If this transport (or another with this name, which would be a
            # configuration error) is already registered, just ignore this
            # configuration item
            if name in self.registered_transports:
                return None

            log.msg('[CONTROLLER] Configuring transport %s' % name)
            # Create a transport (L{ITransport}) using the given configuration
            transport = self.loadTransport(name, config)

            # If the transport is an L{IServerTransport}...
            if IServerTransport.providedBy(transport):
                # Create a L{twisted.application.service.IService} from it
                # using settings provided in C{config}. This is *not* an
                # applicationserver  service but a Twisted service, ie a
                # server handling incoming requests on a given socket.
                service = self.hookTransport(transport, config)
                # Set the IService name
                service.setName(name)
                # Set the IService parent to our MultiTransport
                service.setServiceParent(self.transports)

                # Parse the transport settings again so we can set up an
                # L{ITransportInfo} object for this transport
                port_info = strports.parse(config['transport'], transport)
                transport_info = transport.getTransportInfo(name, port_info)
                # Store the L{ITransportInfo}
                self.transport_info_map[name] = transport_info

                # Finally return the service
                return service
            else:
                # Set up the L{ITransportInfo} for the transport
                transport_info = transport.getTransportInfo(name)
                # Save it
                self.transport_info_map[name] = transport_info

                # And return it. We don't know how to handle this further,
                # since this is not an L{IServerTransport}, most likely the
                # 'mail' transport.
                return transport
コード例 #13
0
    def lookup(self, name):
        # walk through our configured services, see if we know about this one
        services = load_service_data(self.basedir)["services"]

        service_desc = services.get(name)

        if service_desc:
            service_basedir = os.path.join(self.basedir,
                                           service_desc["relative_basedir"])
            service_type = service_desc["type"]
            service_args = [arg for arg in service_desc["args"]]

            service = build_service(service_basedir, self.tub, service_type,
                                    service_args)
            service.setServiceParent(self)

            return service
コード例 #14
0
ファイル: sslecho.py プロジェクト: luodaobin/scratchbox
   def startService(self):

      pool = CreatePool()

      if False:
         factory = Factory()
         factory.protocol = Echo
      else:
         root = File(".")
         factory = Site(root)

      #hub_websocket_sslcontext = tlsctx.TlsContextFactory(cfg["hub-websocket-tlskey-pem"], cfg["hub-websocket-tlscert-pem"])
      context = ssl.DefaultOpenSSLContextFactory('server.key', 'server.crt')

      service = internet.SSLServer(8090, factory, context)
      service.setServiceParent(self)

      MultiService.startService(self)
コード例 #15
0
ファイル: sslecho.py プロジェクト: ktosiu/scratchbox
    def startService(self):

        pool = CreatePool()

        if False:
            factory = Factory()
            factory.protocol = Echo
        else:
            root = File(".")
            factory = Site(root)

        #hub_websocket_sslcontext = tlsctx.TlsContextFactory(cfg["hub-websocket-tlskey-pem"], cfg["hub-websocket-tlscert-pem"])
        context = ssl.DefaultOpenSSLContextFactory('server.key', 'server.crt')

        service = internet.SSLServer(8090, factory, context)
        service.setServiceParent(self)

        MultiService.startService(self)
コード例 #16
0
ファイル: __init__.py プロジェクト: monoid/w4
def buildApp(application, config):
    groupset = Groupset()

    service = W4Service(groupset, config['history'])
    service.setServiceParent(application)

    server = internet.TCPServer(config['port'], web.buildSite(groupset))
    server.setServiceParent(application)

    xmpp.buildXMPPApp(config['host'],
                      ('tcp:5269:interface=%s' % (config['host'], )),
                      config['secret'], groupset, application)

    # Create test group
    test = Group('test', config['host'])
    test.subject = "Testing group"
    groupset.addGroup(test)

    return application
コード例 #17
0
ファイル: service.py プロジェクト: zzl0/Kenshin-backup
def createCacheService(options):
    from rurouni.cache import MetricCache
    from rurouni.protocols import CacheManagementHandler

    MetricCache.init()
    state.events.metricReceived.addHandler(MetricCache.put)
    root_service = createBaseService(options)

    factory = ServerFactory()
    factory.protocol = CacheManagementHandler
    service = TCPServer(int(settings.CACHE_QUERY_PORT), factory,
                        interface=settings.CACHE_QUERY_INTERFACE)
    service.setServiceParent(root_service)

    from rurouni.writer import WriterService
    service = WriterService()
    service.setServiceParent(root_service)

    return root_service
コード例 #18
0
    def configure(self, runtime_environment):
        dependency_manager = runtime_environment.dependency_manager
        self.pipeline_dependency = dependency_manager.add_dependency(self, dict(provider='pipeline.%s'%self.pipeline_name))

        root = PipedPBRoot(server=self)

        if self.checker:
            Checker = reflect.namedAny(self.checker['name'])
            self.checker = Checker(**self.checker.get('arguments', dict()))

            self.realm = PipedPBRealm(server=self)

            root = portal.Portal(self.realm)
            root.registerChecker(self.checker)

        self.factory = PipedPBServerFactory(root)

        for listen in self.listen:
            service = strports.service(listen, self.factory)
            service.setServiceParent(self)
コード例 #19
0
ファイル: __init__.py プロジェクト: monoid/w4
def buildApp(application, config):
    groupset = Groupset()

    service = W4Service(groupset, config['history'])
    service.setServiceParent(application)

    server = internet.TCPServer(config['port'], web.buildSite(groupset))
    server.setServiceParent(application)

    xmpp.buildXMPPApp(config['host'],
        ('tcp:5269:interface=%s' % (config['host'],)),
        config['secret'],
        groupset,
        application)

    # Create test group
    test = Group('test', config['host'])
    test.subject = "Testing group"
    groupset.addGroup(test)

    return application
コード例 #20
0
def attachConsumerService(processPath, port, app):
    service = internet.TCPServer(port, JobConsumerFactory(processPath))
    service.setServiceParent(app)
コード例 #21
0
                'disk': 2,
                'hostname': node[1] + '.test.plebia.org',
                'ip_address': node[1],
                'memory': 512,
                'onboot': 0,
                'ostemplate':
                'local:vztmpl/debian-6.0-fiboserver_6.0-4_amd64.tar.gz',
                'password': '******',
                'storage': 'local',
                'swap': 512,
                'vmid': node[0],
            })

        time.sleep(60)

        print api('POST', 'nodes/octopus/openvz/%d/status/start' % node[0])

        time.sleep(5)

        print api('GET', 'nodes/octopus/openvz/%d/status/current' % node[0])

        self.online_nodes_requests[node[1]] = []
        self.online_nodes.append(node[1])
        self.starting_server = False


application = service.Application("Fibonacci Distributed Service")
site = server.Site(RouterResource())
service = internet.TCPServer(7000, site)
service.setServiceParent(application)
コード例 #22
0
ファイル: tap.py プロジェクト: gf0842wf/cpapp
 def TCPServer(self, port, factory, backlog=50, interface=''):
     service = internet.TCPServer(port, factory, backlog, interface)
     service.setServiceParent(self)
     return service
コード例 #23
0
            #self.DATA["source"]["ion_description"] = request.args["data_resource_id"][0]
            self.DATA["source"]["visualization_url"] = "http://visualize.whirledpeas.edu/crazy-visuals"
            self.DATA.update({"dataResourceSummary":self.dataResourceSummary_one})
            return json.dumps(self.DATA)
        elif action == "findByUser":
            return json.dumps(self.findByUser)
        else:
            self.DATA.update({"dataResourceSummary":ALL_RESOURCES_DATA}) #self.dataResourceSummary*10})
            return json.dumps(self.DATA)

    def render_POST(self, request):
        return json.dumps({"success":True})


root = Resource()
root.putChild("", File(ROOTPAGE))
root.putChild("css", File("./css"))
root.putChild("js", File("./js"))
root.putChild("images", File("./images"))
root.putChild("static", File("./static"))
root.putChild("dataResource", DataResource())
root.putChild("subscription", Notifications())
root.putChild("createDownloadUrl", DownloadData())
root.putChild("userProfile", UserProfile())



application = service.Application("ux_dummmy_server")
service = internet.TCPServer(8080, Site(root)) #For LAN testing user: ,interface="x.x.x.x")
service.setServiceParent(application)
コード例 #24
0
ファイル: tap.py プロジェクト: gf0842wf/cpapp
 def TimerService(self, step, callable, *args, **kwargs):
     service = internet.TimerService(step, callable, *args, **kwargs)
     service.setServiceParent(self)
     return service
コード例 #25
0
ファイル: tap.py プロジェクト: gf0842wf/cpapp
 def UDPServer(self, port, protocol, interface='', maxPacketSize=8192):
     service = internet.UDPServer(port, protocol, interface, maxPacketSize)
     service.setServiceParent(self)
     return service
コード例 #26
0
ファイル: shell.py プロジェクト: Motoma/dywypi
def initialize_service(application, hub):
    from functools import partial
    service = LocalUrwidService(partial(DywypiShell, hub=hub))
    service.setServiceParent(application)

    application.setComponent(log.ILogObserver, DywypiShellLogObserver(service).emit)
コード例 #27
0
ファイル: service.py プロジェクト: vepkenez/tiempo
 def addNamedService(self, name, service):
     # to get this at runtime use service.getServiceNamed('service_name')
     service.setName(name)
     service.setServiceParent(self)
コード例 #28
0
    def __init__(self, appName = 'example', checkRoom = None, suggest = False, options=None):
        splash = None

        FXUI.app = QtGui.QApplication(sys.argv)
        FXUI.app.setApplicationName("wallaby - " + appName)

        for s in ['16', '32', '64', '128', '256']:
            FXUI.app.setWindowIcon(QtGui.QIcon(QtGui.QPixmap(':/icons/images/wallaby_logo_' + s + '.png')))

        pixmap = QtGui.QPixmap(":/images/images/wallaby_splash.png")
        splash = QtGui.QSplashScreen(pixmap)
        splash.show()
        splash.raise_()
        FXUI.app.processEvents()

        if USES_PYSIDE or FXUI.qt4reactor:
            print "Install qt4reactor. USES_PYSIDE =", USES_PYSIDE
            import wallaby.frontends.qt.reactor.qt4reactor as qtreactor
            qtreactor.install()
        else:
            threadedselect.install()
             
            from twisted.internet import reactor
            ii = Interleaver()
            reactor.interleave(ii.toInterleave)
            reactor.suggestThreadPoolSize(50)

        FXUI.mineIcon = QtGui.QIcon(':/icons/images/mine.png')
        FXUI.theirsIcon = QtGui.QIcon(':/icons/images/theirs.png')

        tapp = twisted.application.service.Application("gui")
        service  = FXLogger('wallaby.log')
        service.setServiceParent(tapp)
        service.startService()

        FX.appModule = 'wallaby.apps.' + appName

        try:
            from twisted.plugin import getCache
            pkg = __import__(FX.appModule, globals(), locals(), ["*"], 0)
            if pkg is not None and len(pkg.__path__) > 0 and os.path.exists(pkg.__path__[0]):
                FX.appPath = pkg.__path__[0]
            else:
                FX.appPath = os.path.join(".", "wallaby", "apps", appName)
        except:
            FX.appPath = os.path.join(".", "wallaby", "apps", appName)

        FXUI.css = None

        try:
            print "importing", options.module, "from", FX.appModule
            if options.module == "WallabyApp2" and os.path.exists(os.path.join(FX.appPath, "mainWindow.py")):
                mod = FX.imp(FX.appModule + '.mainWindow', False)
                if os.path.exists(os.path.join(FX.appPath, "mainWindow.css")):
                    FXUI.css = open(os.path.join(FX.appPath, "mainWindow.css")).read()
            else:
                module = options.module
                module = module[0].lower() + module[1:]
                mod = FX.imp(FX.appModule + '.' + module, False)

                if os.path.exists(os.path.join(FX.appPath, module + ".css")):
                    FXUI.css = open(os.path.join(FX.appPath, module + ".css")).read()
        except:
            mod = None

        if mod == None:
            FX.crit('Module', FX.appModule, 'not found')
            reactor.callWhenRunning(self.myQuit)
            if USES_PYSIDE or FXUI.qt4reactor: reactor.runReturn()
            FXUI.app.exec_()
            return

        try:
            FXUI.mainWindow = mod.MainWindow(self.myQuit, options)
            if FXUI.css is not None:
                FXUI.app.setStyle("plastique")
                FXUI.mainWindow.setStyleSheet(FXUI.css)
        except Exception as e:
            import traceback
            traceback.print_exc(file=sys.stdout)

            from twisted.internet import reactor
            reactor.callWhenRunning(self.myQuit)
            if USES_PYSIDE or FXUI.qt4reactor: reactor.runReturn()
            FXUI.app.exec_()
            return

        FXUI.mainWindow.setSplash(splash)

        from twisted.internet import reactor
        reactor.callWhenRunning(self.run, mod, options, checkRoom)

        FXUI.mainWindow.enabled = False
        FXUI.mainWindow.configure()
        FXUI.mainWindow.show()
        FXUI.mainWindow.raise_()

        signal.signal(signal.SIGINT, self.sigint_handler)
        signal.signal(signal.SIGTERM, self.sigint_handler)

        # self.gc = GarbageCollector(FXUI.mainWindow, True)

        if USES_PYSIDE or FXUI.qt4reactor: reactor.runReturn()
        FXUI.app.exec_()
コード例 #29
0
def create_local_service(port, application):
    logger.info('Starting local Services HTTP API')
    desc = 'tcp:%s:interface=127.0.0.1' % port
    site = server.Site(entrypoints.ServicesEntrypoint())
    service = strports.service(desc, site)
    service.setServiceParent(application)
コード例 #30
0
def attachProducersService(port, app, jobsched):
    service =  internet.TCPServer(port, QueueFactory(jobsched))
    service.setServiceParent(app)