
    -                     $   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  S rS rS rS	 rS
 rS rS rS rS rS rS rS r " S S\R4                  5      rSS jr\S:X  a  \R<                  " \" 5       5        gg)z%Command-line interface to gen_client.    N)
exceptions)gen_client_lib)utilc                    [         R                  " [        R                  " U S5      5       n[        R
                  " SU 5      nUc  [        R                  " SU -  5      eUR                  U5        S S S 5        g ! , (       d  f       g = f)Nwapitools.base.pyzCould not find file %s)	
contextlibclosingioopenpkgutilget_datar   GeneratedClientErrorwrite)filenameoutsrc_datas      *lib/third_party/apitools/gen/gen_client.py_CopyLocalFiler   !   sk    			BGGHc2	3s##*11(835 5		( 
4	3	3s   AA::
Bc                    U R                   (       a!   [        R                  " U R                   5      $ [        R                  R                  U R                  5      =(       d    Sn[        R                  " USS9 n[        R                  " [        R                  " UR                  5       5      5      sSSS5        $ ! [        R                   a    [        R
                  " S5      ef = f! , (       d  f       g= f)z!Get the discovery doc from flags.zCould not fetch discovery docz
/dev/stdinutf8encodingN)discovery_urlr   FetchDiscoveryDocr   CommunicationErrorr   ospath
expanduserinfiler   r   jsonloadsReplaceHomoglyphsread)argsr    fs      r   _GetDiscoveryDocFromFlagsr'   +   s    	1))$*<*<==
 WW,<F	&	)Qzz$00:; 
*	) ,, 	111/1 1	1
 
*	)s   B< :8C*<+C'*
C8c                    [        U 5      n[        R                  " U R                  U R                  U R
                  5      nU R                  (       a   [        R                  " U R                  SS9 n[        R                  " [        R                  " UR                  5       5      5      nUR                  SUR                  S0 5      5      nUR                  S5      nUR                  S5      nSSS5        OU R"                  nU R$                  nW(       d  [&        R(                  " S	5        S
nW(       d  [&        R(                  " S5        S
n[        R*                  R-                  XR.                  XgU R0                  X R2                  U R4                  5      n[6        R8                  R;                  U R<                  5      =(       d    UR>                  n	[6        R8                  RA                  U	5      (       a'  U RB                  (       d  [        RD                  " S5      e[6        R8                  RA                  U	5      (       d  [6        RF                  " U	5        [H        RJ                  " XX RL                  U	U RN                  U RP                  U RR                  S:H  U RT                  U RV                  U RX                  S9$ ! , (       d  f       GN= f! [         a$    [        R                   " SU R                  -  5      ef = f)z#Create a codegen object from flags.r   r   	installedweb	client_idclient_secretNz#Failed to open client json file: %szNo client ID supplied zNo client secret suppliedzHOutput directory exists, pass --overwrite to replace the existing files.	wildcards)base_packageprotorpc_packageinit_wildcards_file
use_proto2unelidable_request_methodsapitools_version)-r'   r   Namesstrip_prefixexperimental_name_conventionexperimental_capitalize_enumsclient_jsonr   r   r!   r"   r#   r$   getIOErrorr   NotFoundErrorr+   r,   loggingwarning
ClientInfoCreatescope
user_agentapi_keyversion_identifierr   r   r   outdirdefault_directoryexists	overwriteConfigurationValueErrormakedirsr   DescriptorGeneratorroot_packager/   r0   	init_fileexperimental_proto2_outputr3   r4   )
r%   discovery_docnamesr9   r&   r*   r+   r,   client_inforE   s
             r   _GetCodegenFromFlagsrR   9   s>   -d3MJJ))**,E
 	J))F;{JJt55k6F6F6HIJeeKub)9:GGK0	 # 8	 <; NN	**/0	34//((zz9d.E.EGK WW,M0M0MF	ww~~fdnn00"# 	# 77>>&!!
F--E+<+<f&&..!^^{:22#'#B#B..0 0? <;
  	J**58H8HHJ J	Js+   K 3A=K 0K  
K
K K .L c                     [         R                  " U R                  5         [        S5        [        S5        [        S5        S S S 5        g ! , (       d  f       g = f)Nzbase_api.pyzcredentials_lib.pyzexceptions.py)r   ChdirrE   r   )codegens    r   _WriteBaseFilesrV   m   s7    	GNN	#}%+,' 
$	#	#s   "A
Ac                     [         R                  " SS5       nU R                  U5        S S S 5        g ! , (       d  f       g = fNz__init__.pyr   )r   r   WriteIntermediateInitrU   r   s     r   _WriteIntermediateInitr[   t   s,    		$%%c* 
%	$	$	   3
Ac                    [         R                  " U R                  5         [        R                  " U R
                  R                  S5       nU R                  U5        S S S 5        [        R                  " U R
                  R                  S5       nU R                  U5        S S S 5        S S S 5        g ! , (       d  f       N\= f! , (       d  f       N(= f! , (       d  f       g = fNr   )
r   rT   rE   r   r   rQ   messages_proto_file_nameWriteMessagesProtoFileservices_proto_file_nameWriteServicesProtoFilerZ   s     r   _WriteProtoFilesrc   y   s    	GNN	#WWW((AA3G3**3/ HWWW((AA3G3**3/ H 
$	#GGGG 
$	#s;   ,CB53CC$C5
C	?C
C	C
C%c                    UR                   (       a  [        U5        [        R                  " UR                  5         [
        R                  " UR                  R                  S5       nUR                  U5        S S S 5        [
        R                  " UR                  R                  S5       nUR                  U5        S S S 5        S S S 5        g ! , (       d  f       N\= f! , (       d  f       N(= f! , (       d  f       g = fr^   )r2   rc   r   rT   rE   r   r   rQ   messages_file_nameWriteMessagesFileclient_file_nameWriteClientLibrary)r%   rU   r   s      r   _WriteGeneratedFilesri      s    !	GNN	#WWW((;;SAS%%c* BWWW((993?3&&s+ @ 
$	#AA?? 
$	#s;   ,C3)C;3C3.C" C3
C	C3"
C0	,C33
Dc                     [         R                  " U R                  5         [        R                  " SS5       nU R                  U5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = frX   )r   rT   rE   r   r   	WriteInitrZ   s     r   
_WriteInitrl      sM    	GNN	#WW]C(Cc" ) 
$	#(( 
$	#s"   A-AA-
A*	&A--
A;c                     [         R                  " SS5       nU R                  U5        S S S 5        g ! , (       d  f       g = f)Nzsetup.pyr   )r   r   WriteSetupPyrZ   s     r   _WriteSetupPyro      s,    	S	!SS! 
"	!	!r\   c                     [        U 5      nUc  [        R                  " S5        g[        X5        U R                  S:w  a  [        U5        gg)z"Driver for client code generation.N"Failed to create codegen, exiting.   none)rR   r=   errorri   rM   rl   r%   rU   s     r   GenerateClientrv      sD     #4(G:;'~~7      c                    [        U 5      nUS   n[        R                  R                  U R                  5      n[        R                  R                  U R                  SU-  5      U l        SU-  U l        [        U 5      nUc  [        R                  " S5        g[        X5        [        U5        [        R                  " U5         [        U5        [        R                  " S5         [        U5        [        R                  " S5         [        U5        SSS5        SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       N(= f! , (       d  f       g= f)	z/Generate a client as a pip-installable tarball.namezapitools/clients/%szapitools.clients.%sNrq      apitoolsclients)r'   r   r   r   rE   joinrL   rR   r=   rt   ri   rl   r   rT   ro   r[   )r%   rO   packageoriginal_outdirrU   s        r   GeneratePipPackager      s     .d3MF#Ggg((5O'',,*W46DK-7D"4(G:;'w	O	$gZZ
#"7+I&&w/ ' $ 
%	$ '& $# 
%	$s<   "E)"ED0EE0
D>:E
E	E
E c                 0    [        U 5      n[        U5        g)z2Generate just the two proto files for a given API.N)rR   rc   ru   s     r   GenerateProtor      s     #4(GWrw   c                       \ rS rSrSS jrSrg)_SplitCommaSeparatedList   Nc                 N    [        X R                  UR                  S5      5        g )N,)setattrdestsplit)selfparser	namespacevaluesoption_strings        r   __call__!_SplitCommaSeparatedList.__call__   s    	99fll3&78rw    N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   rw   r   r   r      s    9rw   r   c                 F   U c  [         R                  n [        R                  " SS9nUR	                  5       nUR                  SSS9  UR                  SSS9  UR                  SS	S
S9  UR                  SSSS9  UR                  SSS9  UR                  SSSS9  UR                  SSSSS9  UR                  SSSS9  UR                  SS/ SS9  UR                  SS S9  UR                  S!S"S9  UR                  S#S$S%S9  UR                  S&S'S(S9  UR                  S)S/ S*S9  UR                  S+S,S-S9  UR                  S.S/SS0S19  UR                  S2S/S3S0S19  UR                  S4/ S5QS6 S7S8S99  UR                  S:[        / S;S<9  UR                  S=SS>S?S@9  UR                  SASSSBS9  UR                  SC[        R                  R                  [        R                  R                  SDSE9  UR                  SFSSSGS9  UR                  SHS9nUR                  SISJS9nUR                  [        SK9  UR                  SLSMS9nUR                  [        SK9  UR                  SNSOS9nUR                  [         SK9  UR#                  U SPS  5      nUR%                  U5      =(       d    SQ$ )RNzApitools Client Code Generator)descriptionz--infilezLFilename for the discovery document. Mutually exclusive with --discovery_url)helpz--discovery_urlz[URL (or "name.version") of the discovery document to use. Mutually exclusive with --infile.z--base_packager   z;Base package path of apitools (defaults to apitools.base.py)defaultr   z--protorpc_packagezapitools.base.protorpclitezEBase package path of protorpc (defaults to apitools.base.protorpclitez--version-identifierzVersion identifier to use for the generated client (defaults to "version" value in discovery doc). This must be a valid identifier when used in a Python module name.z--outdirr-   z<Directory name for output files. (Defaults to the API name.)z--overwriteF
store_truez>Only overwrite the output directory if this flag is specified.)r   actionr   z--root_packagezCPython import path for where these modules should be imported from.z--strip_prefix*z]Prefix to strip from type names in the discovery document. (May be specified multiple times.))nargsr   r   z	--api_keyzAPI key to use for API access.z--client_jsonzTUse the given file downloaded from the dev. console for client_id and client_secret.z--client_id	CLIENT_IDz*Client ID to use for the generated client.z--client_secretCLIENT_SECRETz'Client secret for the generated client.z--scopezKScopes to request in the generated client. May be specified more than once.z--user_agentx_Tw5K8nnjoRAqULM9PFAC2bzEUser agent for the generated client. Defaults to <api>-generated/0.1.z--generate_cligenerate_clizIgnored.)r   r   r   z--nogenerate_clistore_falsez--init-file)rs   emptyr.   c                 "    U R                  5       $ r   )lower)ss    r   <lambda>main.<locals>.<lambda>)  s
    qwwyrw   r.   z>Controls whether and how to generate package __init__.py file.)choicestyper   r   z--unelidable_request_methodsztFull method IDs of methods for which we should NOT try to elide the request type. (Should be a comma-separated list.)r   r   r   z--apitools_versionr4   zzApitools version used as a requirement in generated clients. Defaults to version of apitools used to generate the clients.)r   r   r   z--experimental_capitalize_enumsz:Dangerous: attempt to rewrite enum values to be uppercase.z--experimental_name_conventionz6Dangerous: use a particular style for generated names.)r   r   r   z--experimental_proto2_outputz-Dangerous: also output a proto2 message file.zType of generated codeclientz.Generate apitools client in destination folder)funcpip_packagez$Generate apitools client pip packageprotozGenerate apitools client protosrz   r   )sysargvargparseArgumentParseradd_mutually_exclusive_groupadd_argumentr   r   r5   NAME_CONVENTIONSDEFAULT_NAME_CONVENTIONadd_subparsers
add_parserset_defaultsrv   r   r   
parse_argsr   )r   r   discovery_group
subparsersclient_parserpip_package_parserproto_parserr%   s           r   mainr      s   |xx$$46F 99;O    ! "
   2 ! 4
 "J  L
 ,8  : >  @ K  M
 lM  O
 )  + 3  5 .  1 -  /
 9  ;
 6  8
 1  3 *1  3 ~l      . M  O &'K	  M +N  P )lI  K
 (

++

22E	  G &l<  >
 &&,D&EJ))G * IMN3#..B / D##);#<((7 ) 9L=1T!"X&D99T?arw   __main__r   )__doc__r   r	   r   r!   r=   r   r   r   apitools.base.pyr   apitools.genr   r   r   r'   rR   rV   r[   rc   ri   rl   ro   rv   r   r   Actionr   r   r   exitr   rw   r   <module>r      s   " ,   	   	  
 ' ' <00h(+
0,#"

009x 9Q h zHHTV rw   