parameters: (self)
return_statement: return True
docstring: Starts up a http server with specified document root and port.
docstring_summary: Starts up a http server with specified document root and port.
docstring_tokens: Starts up a http server with specified document root and port .
function: def StartupHttpServer(self):
      """Starts up a http server with specified document root and port."""
      # If we want a specific port, make sure no one else is listening on it.
      if self.fixed_port:
        self._KillProcessListeningOnPort(self.fixed_port)
      while True:
        if self.base_config_path:
          # Read the config
          with codecs.open(self.base_config_path, 'r', 'utf-8') as f:
            config_contents = f.read()
        else:
          config_contents = self._GetDefaultBaseConfig()
        if self.extra_config_contents:
          config_contents += self.extra_config_contents
        # Write out the config, filling in placeholders from the members of |self|
        with codecs.open(self.config_path, 'w', 'utf-8') as f:
          f.write(config_contents % self.__dict__)
        if (not os.path.exists(self.lighttpd_path) or
            not os.access(self.lighttpd_path, os.X_OK)):
          raise EnvironmentError(
              'Could not find lighttpd at %s.\n'
              'It may need to be installed (e.g. sudo apt-get install lighttpd)'
              % self.lighttpd_path)
        # pylint: disable=no-member
        self.process = pexpect.spawn(self.lighttpd_path,
                                     ['-D', '-f', self.config_path,
                                      '-m', self.lighttpd_module_path],
                                     cwd=self.temp_dir)
        client_error, server_error = self._TestServerConnection()
        if not client_error:
          assert int(open(self.pid_file, 'r').read()) == self.process.pid
          break
        self.process.close()
  
        if self.fixed_port or 'in use' not in server_error:
          print('Client error:', client_error)
          print('Server error:', server_error)
          return False
        self.port = self._GetRandomPort()
      return True
function_tokens: def StartupHttpServer ( self ) : # If we want a specific port, make sure no one else is listening on it. if self . fixed_port : self . _KillProcessListeningOnPort ( self . fixed_port ) while True : if self . base_config_path : # Read the config with codecs . open ( self . base_config_path , 'r' , 'utf-8' ) as f : config_contents = f . read ( ) else : config_contents = self . _GetDefaultBaseConfig ( ) if self . extra_config_contents : config_contents += self . extra_config_contents # Write out the config, filling in placeholders from the members of |self| with codecs . open ( self . config_path , 'w' , 'utf-8' ) as f : f . write ( config_contents % self . __dict__ ) if ( not os . path . exists ( self . lighttpd_path ) or not os . access ( self . lighttpd_path , os . X_OK ) ) : raise EnvironmentError ( 'Could not find lighttpd at %s.\n' 'It may need to be installed (e.g. sudo apt-get install lighttpd)' % self . lighttpd_path ) # pylint: disable=no-member self . process = pexpect . spawn ( self . lighttpd_path , [ '-D' , '-f' , self . config_path , '-m' , self . lighttpd_module_path ] , cwd = self . temp_dir ) client_error , server_error = self . _TestServerConnection ( ) if not client_error : assert int ( open ( self . pid_file , 'r' ) . read ( ) ) == self . process . pid break self . process . close ( ) if self . fixed_port or 'in use' not in server_error : print ( 'Client error:' , client_error ) print ( 'Server error:' , server_error ) return False self . port = self . _GetRandomPort ( ) return True