def GenDiscoveryDoc(service_class_names, doc_format, output_path, hostname=None):
 output_files = []
 service_configs = GenApiConfig(service_class_names, hostname=hostname)
 for (service_class_name, config) in service_configs.iteritems():
  body = json.dumps({'config': config}, indent=2, sort_keys=True)
  request = urllib2.Request((DISCOVERY_DOC_BASE + doc_format), body)
  request.add_header('content-type', 'application/json')
  try:
   with contextlib.closing(urllib2.urlopen(request)) as response:
    content = response.read()
    (_, base_service_class_name) = service_class_name.rsplit('.', 1)
    discovery_name = (base_service_class_name + '.discovery')
    output_files.append(_WriteFile(output_path, discovery_name, content))
  except urllib2.HTTPError as error:
   raise ServerRequestException(error)
 return output_files

def GenDiscoveryDoc ( service_class_names , doc_format , output_path , hostname = None ) : output_files = [ ] service_configs = GenApiConfig ( service_class_names , hostname = hostname ) for ( service_class_name , config ) in service_configs . iteritems ( ) : body = json . dumps ( { 'config' : config } , indent = 2 , sort_keys = True ) request = urllib2 . Request ( ( DISCOVERY_DOC_BASE + doc_format ) , body ) request . add_header ( 'content-type' , 'application/json' ) try : with contextlib . closing ( urllib2 . urlopen ( request ) ) as response : content = response . read ( ) ( _ , base_service_class_name ) = service_class_name . rsplit ( '.' , 1 ) discovery_name = ( base_service_class_name + '.discovery' ) output_files . append ( _WriteFile ( output_path , discovery_name , content ) ) except urllib2 . HTTPError as error : raise ServerRequestException ( error ) return output_files
write discovery documents generated from a cloud service to file .