def setUp(self):
    self.delegate = Delegate()
    super(self.__class__,self).setUp()
    self.runLoop = RunLoop.currentRunLoop()

    # Wire URLProtocol
    URLHTTPProtocol.run_loop = RunLoop
    URLHTTPProtocol.assembled()
    URLProtocol.registerClass(URLHTTPProtocol)
    URLConnection.URLProtocol = URLProtocol
    URLCache.assembled()
    URLConnection.URLCache = URLCache
    URLConnection.runLoop = RunLoop
        
    # Wire RunLoop
    ls = LogService()
    ls.useStreamHandler(sys.stderr)
    RunLoop.log = ls.__binding__('RunLoop', RunLoop)
示例#2
0
  def setUp(self):
    super(self.__class__,self).setUp()
    self.runLoop = RunLoop.currentRunLoop()
    # Wire URLHTTPProtocol
    URLHTTPProtocol.LRProtocol = LineReceiverProtocol
    URLHTTPProtocol.portFactory = Port

    # Wire URLProtocol
    URLProtocol.registerClass(URLDataProtocol)
    URLProtocol.registerClass(URLHTTPProtocol)
    
    # Wire URLConnection
    URLConnection.URLProtocol = URLProtocol
    URLConnection.runLoop = RunLoop
    URLConnection.URLRequest = URLRequest
      
    # Wire RunLoop
    ls = LogService()
    ls.useStreamHandler(sys.stderr)
    RunLoop.log = ls.__binding__('RunLoop', RunLoop)
    XMLSchemaService.URLConnection = URLConnection
    
    self.XMLSchemaService = XMLSchemaService
    self.schema = None
示例#3
0
    def __init__(self, appDir,  authoritativeOptions = None, **defaultComps):
        self.appBundle = Bundle(appDir)
        self.configFile = self.appBundle.pathForResource('app.conf')
        self.status = Application.STOPPED

        self.digest = ""
        self.name = os.path.basename(os.path.abspath(appDir))

        if not authoritativeOptions:
            authoritativeOptions = {}
        authoritativeOptions['application.name'] =  self.name
        authoritativeOptions['application.path'] =  os.path.abspath(appDir)
        authoritativeOptions['system.hostname'] =  socket.gethostname()

        self.loadConfig()

        logService = defaultComps.get("LogService")

        if logService is None:
            # everybody needs logging, especally  during devel. If one
            # isn't passed to us, set one up to go directly to syslog

            logService = LogService()
            logService.addData('app', self.name)

            logService.setFormat('[%(app)s:%(name)s:%(levelname)s] %(message)s')
            logService.useSyslogHandler()
            defaultComps["LogService"] = logService

        # load the module that adapts our logging to somthething that twisted deferred's and failuers likes
        defaultComps["StdioOnnaStick"] =  StdioOnnaStick()

        defaultComps["ErrorFactory"] = ErrorFactory()

        

        # these two are sessions so we put their classe rather than
        # instances in componentRegistry
        defaultComps["RunLoop"] = RunLoop
        defaultComps["PortFactory"] = Port

        # our os signal handling, has to be as light weight as
        # possible. so any signal this app receives will be processed
        # by the sameRunLoop that started this app (hopefully you
        # don't have it bogged down running long synchronous tasks)

        self.mainRunLoop = RunLoop.currentRunLoop()

        self.componentRegistry = CompBinder()
        for compName, component in defaultComps.items():
            self.componentRegistry.addComponent(compName, component)

        serviceRegistry = ServiceRegistry()
        # blehq, serviceRegistry needs the application name in order to
        # load services that have been configured by convention 
        serviceRegistry.app_name = self.name
        serviceRegistry.app = self
        self.componentRegistry.addComponent("ServiceRegistry", serviceRegistry)
        # need to bind ServiceRegistry's before we can add the App as
        # a service.
        self.componentRegistry.bind()
        

        # Set up the config service with authorative options
        configService = ciConfigService()
        for option, value in authoritativeOptions.items():
          configService.set_default(option, value)

        try: # todo, remove this crap afte we pull the last bits of corba/omniorb from Rambler
            from epo import ciIApplication, ciIConfigService
            # Register the application service so that we can be remotely managed
            serviceRegistry.addService("Application", self, ciIApplication, [])
            serviceRegistry.addService("ConfigService", configService, ciIConfigService, [])
        except ImportError:
            # corba isn't installed
            serviceRegistry.addService("Application", self, None, [])
            # Note: ConfigService is placed into the componentRegistry
            # via the service registry. Not sure why I did this.
            serviceRegistry.addService("ConfigService", configService, None, [])



        self.componentRegistry.bind()