def __init__(self, discovery_doc, client_info, names, root_package, outdir, base_package, protorpc_package, generate_cli=False, init_wildcards_file=True, use_proto2=False, unelidable_request_methods=None, apitools_version=''): self.__discovery_doc = discovery_doc self.__client_info = client_info self.__outdir = outdir self.__use_proto2 = use_proto2 self.__description = util.CleanDescription( self.__discovery_doc.get('description', '')) self.__package = self.__client_info.package self.__version = self.__client_info.version self.__revision = discovery_doc.get('revision', '1') self.__generate_cli = generate_cli self.__init_wildcards_file = init_wildcards_file self.__root_package = root_package self.__base_files_package = base_package self.__protorpc_package = protorpc_package self.__names = names # Order is important here: we need the schemas before we can # define the services. self.__message_registry = message_registry.MessageRegistry( self.__client_info, self.__names, self.__description, self.__root_package, self.__base_files_package, self.__protorpc_package) schemas = self.__discovery_doc.get('schemas', {}) for schema_name, schema in schemas.items(): self.__message_registry.AddDescriptorFromSchema( schema_name, schema) # We need to add one more message type for the global parameters. standard_query_schema = _StandardQueryParametersSchema( self.__discovery_doc) self.__message_registry.AddDescriptorFromSchema( standard_query_schema['id'], standard_query_schema) # Now that we know all the messages, we need to correct some # fields from MessageFields to EnumFields. self.__message_registry.FixupMessageFields() self.__command_registry = command_registry.CommandRegistry( self.__package, self.__version, self.__client_info, self.__message_registry, self.__root_package, self.__base_files_package, self.__protorpc_package, self.__names) self.__command_registry.AddGlobalParameters( self.__message_registry.LookupDescriptorOrDie( 'StandardQueryParameters')) self.__services_registry = service_registry.ServiceRegistry( self.__client_info, self.__message_registry, self.__command_registry, self.__names, self.__root_package, self.__base_files_package, unelidable_request_methods or []) services = self.__discovery_doc.get('resources', {}) for service_name, methods in sorted(services.items()): self.__services_registry.AddServiceFromResource( service_name, methods) # We might also have top-level methods. api_methods = self.__discovery_doc.get('methods', []) if api_methods: self.__services_registry.AddServiceFromResource( 'api', {'methods': api_methods}) # pylint: disable=protected-access self.__client_info = self.__client_info._replace( scopes=self.__services_registry.scopes) # The apitools version that will be used in prerequisites for the # generated packages. self.__apitools_version = (apitools_version if apitools_version else _ApitoolsVersion())
def __init__(self, discovery_doc, client_info, names, root_package, outdir, base_package, generate_cli=False, use_proto2=False, unelidable_request_methods=None): self.__discovery_doc = discovery_doc self.__client_info = client_info self.__outdir = outdir self.__use_proto2 = use_proto2 self.__description = util.CleanDescription( self.__discovery_doc.get('description', '')) self.__package = self.__client_info.package self.__version = self.__client_info.version self.__generate_cli = generate_cli self.__root_package = root_package self.__base_files_package = base_package self.__base_files_target = ( '//cloud/bigscience/apitools/base/py:apitools_base') self.__names = names self.__base_url, self.__base_path = _ComputePaths( self.__package, self.__client_info.url_version, self.__discovery_doc) # Order is important here: we need the schemas before we can # define the services. self.__message_registry = message_registry.MessageRegistry( self.__client_info, self.__names, self.__description, self.__root_package, self.__base_files_package) schemas = self.__discovery_doc.get('schemas', {}) for schema_name, schema in schemas.items(): self.__message_registry.AddDescriptorFromSchema( schema_name, schema) # We need to add one more message type for the global parameters. standard_query_schema = _StandardQueryParametersSchema( self.__discovery_doc) self.__message_registry.AddDescriptorFromSchema( standard_query_schema['id'], standard_query_schema) # Now that we know all the messages, we need to correct some # fields from MessageFields to EnumFields. self.__message_registry.FixupMessageFields() self.__command_registry = command_registry.CommandRegistry( self.__package, self.__version, self.__client_info, self.__message_registry, self.__root_package, self.__base_files_package, self.__base_url, self.__names) self.__command_registry.AddGlobalParameters( self.__message_registry.LookupDescriptorOrDie( 'StandardQueryParameters')) self.__services_registry = service_registry.ServiceRegistry( self.__client_info, self.__message_registry, self.__command_registry, self.__base_url, self.__base_path, self.__names, self.__root_package, self.__base_files_package, unelidable_request_methods or []) services = self.__discovery_doc.get('resources', {}) for service_name, methods in sorted(services.items()): self.__services_registry.AddServiceFromResource( service_name, methods) # We might also have top-level methods. api_methods = self.__discovery_doc.get('methods', []) if api_methods: self.__services_registry.AddServiceFromResource( 'api', {'methods': api_methods}) self.__client_info = self.__client_info._replace( scopes=self.__services_registry.scopes)