コード例 #1
0
    def start(self, options):
        """Start devappserver2 servers based on the provided command line arguments.

    Args:
      options: An argparse.Namespace containing the command line arguments.
    """
        logging.getLogger().setLevel(
            _LOG_LEVEL_TO_PYTHON_CONSTANT[options.dev_appserver_log_level])

        configuration = application_configuration.ApplicationConfiguration(
            options.config_paths, options.app_id)

        if options.enable_cloud_datastore:
            # This requires the oauth server stub to return that the logged in user
            # is in fact an admin.
            os.environ['OAUTH_IS_ADMIN'] = '1'
            gcd_module = application_configuration.ModuleConfiguration(
                gcd_application.generate_gcd_app(
                    configuration.app_id.split('~')[1]))
            configuration.modules.append(gcd_module)

        if options.skip_sdk_update_check:
            logging.info('Skipping SDK update check.')
        else:
            update_checker.check_for_updates(configuration)

        # There is no good way to set the default encoding from application code
        # (it needs to be done during interpreter initialization in site.py or
        # sitecustomize.py) so just warn developers if they have a different
        # encoding than production.
        if sys.getdefaultencoding() != _PROD_DEFAULT_ENCODING:
            logging.warning(
                'The default encoding of your local Python interpreter is set to %r '
                'while App Engine\'s production environment uses %r; as a result '
                'your code may behave differently when deployed.',
                sys.getdefaultencoding(), _PROD_DEFAULT_ENCODING)

        if options.port == 0:
            logging.warn(
                'DEFAULT_VERSION_HOSTNAME will not be set correctly with '
                '--port=0')

        _setup_environ(configuration.app_id)

        self._dispatcher = dispatcher.Dispatcher(
            configuration, options.host, options.port, options.auth_domain,
            _LOG_LEVEL_TO_RUNTIME_CONSTANT[options.log_level],
            self._create_php_config(options),
            self._create_python_config(options),
            self._create_java_config(options),
            self._create_cloud_sql_config(options),
            self._create_vm_config(options),
            self._create_module_to_setting(options.max_module_instances,
                                           configuration,
                                           '--max_module_instances'),
            options.use_mtime_file_watcher, options.automatic_restart,
            options.allow_skipped_files,
            self._create_module_to_setting(options.threadsafe_override,
                                           configuration,
                                           '--threadsafe_override'))

        request_data = wsgi_request_info.WSGIRequestInfo(self._dispatcher)
        storage_path = _get_storage_path(options.storage_path,
                                         configuration.app_id)

        apis = self._create_api_server(request_data, storage_path, options,
                                       configuration)
        apis.start()
        self._running_modules.append(apis)

        self._dispatcher.start(options.api_host, apis.port, request_data)

        xsrf_path = os.path.join(storage_path, 'xsrf')
        admin = admin_server.AdminServer(options.admin_host,
                                         options.admin_port, self._dispatcher,
                                         configuration, xsrf_path)
        admin.start()
        self._running_modules.append(admin)
コード例 #2
0
ファイル: devappserver2.py プロジェクト: 404minds/quiz-forest
  def start(self, options):
    """Start devappserver2 servers based on the provided command line arguments.

    Args:
      options: An argparse.Namespace containing the command line arguments.
    """
    logging.getLogger().setLevel(
        _LOG_LEVEL_TO_PYTHON_CONSTANT[options.dev_appserver_log_level])

    configuration = application_configuration.ApplicationConfiguration(
        options.config_paths, options.app_id)

    if options.enable_cloud_datastore:
      # This requires the oauth server stub to return that the logged in user
      # is in fact an admin.
      os.environ['OAUTH_IS_ADMIN'] = '1'
      gcd_module = application_configuration.ModuleConfiguration(
          gcd_application.generate_gcd_app(configuration.app_id.split('~')[1]))
      configuration.modules.append(gcd_module)

    if options.skip_sdk_update_check:
      logging.info('Skipping SDK update check.')
    else:
      update_checker.check_for_updates(configuration)

    # There is no good way to set the default encoding from application code
    # (it needs to be done during interpreter initialization in site.py or
    # sitecustomize.py) so just warn developers if they have a different
    # encoding than production.
    if sys.getdefaultencoding() != _PROD_DEFAULT_ENCODING:
      logging.warning(
          'The default encoding of your local Python interpreter is set to %r '
          'while App Engine\'s production environment uses %r; as a result '
          'your code may behave differently when deployed.',
          sys.getdefaultencoding(), _PROD_DEFAULT_ENCODING)

    if options.port == 0:
      logging.warn('DEFAULT_VERSION_HOSTNAME will not be set correctly with '
                   '--port=0')

    _setup_environ(configuration.app_id)

    self._dispatcher = dispatcher.Dispatcher(
        configuration,
        options.host,
        options.port,
        options.auth_domain,
        _LOG_LEVEL_TO_RUNTIME_CONSTANT[options.log_level],
        self._create_php_config(options),
        self._create_python_config(options),
        self._create_java_config(options),
        self._create_custom_config(options),
        self._create_cloud_sql_config(options),
        self._create_vm_config(options),
        self._create_module_to_setting(options.max_module_instances,
                                       configuration, '--max_module_instances'),
        options.use_mtime_file_watcher,
        options.automatic_restart,
        options.allow_skipped_files,
        self._create_module_to_setting(options.threadsafe_override,
                                       configuration, '--threadsafe_override'),
        options.external_port)

    request_data = wsgi_request_info.WSGIRequestInfo(self._dispatcher)
    storage_path = _get_storage_path(options.storage_path, configuration.app_id)

    # TODO: Remove after the Files API is really gone.
    if options.blobstore_warn_on_files_api_use:
      api_server.enable_filesapi_tracking(request_data)

    apis = self._create_api_server(
        request_data, storage_path, options, configuration)
    apis.start()
    self._running_modules.append(apis)

    self._dispatcher.start(options.api_host, apis.port, request_data)

    xsrf_path = os.path.join(storage_path, 'xsrf')
    admin = admin_server.AdminServer(options.admin_host, options.admin_port,
                                     self._dispatcher, configuration, xsrf_path)
    admin.start()
    self._running_modules.append(admin)