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]) if options.dev_appserver_log_setup_script: try: execfile(options.dev_appserver_log_setup_script, {}, {}) except Exception as e: logging.exception("Error executing log setup script at %r.", options.dev_appserver_log_setup_script) 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. api_server.set_filesapi_enabled(options.blobstore_enable_files_api) 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) try: default = self._dispatcher.get_module_by_name('default') apis.set_balanced_address(default.balanced_address) except request_info.ModuleDoesNotExistError: logging.warning('No default module found. Ignoring.')
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. api_server.set_filesapi_enabled(options.blobstore_enable_files_api) 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) try: default = self._dispatcher.get_module_by_name('default') apis.set_balanced_address(default.balanced_address) except request_info.ModuleDoesNotExistError: logging.warning('No default module found. Ignoring.')
def start(self, options): """Start devappserver2 servers based on the provided command line arguments. Args: options: An argparse.Namespace containing the command line arguments. """ self._options = options logging.getLogger().setLevel(constants.LOG_LEVEL_TO_PYTHON_CONSTANT[ options.dev_appserver_log_level]) runtime = 'vm' if options.runtime == 'python-compat' else options.runtime parsed_env_variables = dict(options.env_variables or []) configuration = application_configuration.ApplicationConfiguration( config_paths=options.config_paths, app_id=options.app_id, runtime=runtime, env_variables=parsed_env_variables) if options.google_analytics_client_id: metrics_logger = metrics.GetMetricsLogger() metrics_logger.Start( options.google_analytics_client_id, options.google_analytics_user_agent, {module.runtime for module in configuration.modules}) 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() != constants.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(), constants.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, constants.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_go_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) wsgi_request_info_ = wsgi_request_info.WSGIRequestInfo( self._dispatcher) storage_path = api_server.get_storage_path(options.storage_path, configuration.app_id) # TODO: Remove after the Files API is really gone. api_server.set_filesapi_enabled(options.blobstore_enable_files_api) if options.blobstore_warn_on_files_api_use: api_server.enable_filesapi_tracking(wsgi_request_info_) apiserver = api_server.create_api_server(wsgi_request_info_, storage_path, options, configuration) apiserver.start() self._running_modules.append(apiserver) if options.grpc_apis: grpc_apiserver = api_server.GRPCAPIServer(options.grpc_api_port) grpc_apiserver.start() self._running_modules.append(grpc_apiserver) self._dispatcher.start(options.api_host, apiserver.port, wsgi_request_info_, options.grpc_apis) 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) try: default = self._dispatcher.get_module_by_name('default') apiserver.set_balanced_address(default.balanced_address) except request_info.ModuleDoesNotExistError: logging.warning('No default module found. Ignoring.')