
                         :   S r SSKJr  SSKJr  SSKJ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S	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  Sr\R@                   " S S\RB                  5      5       r"SS jr#g)z6A command that regenerates existing or new gcloud API.    )absolute_import)division)unicode_literalsN)third_party)generate)arg_parsers)base)parser_errors)regen)log)encoding)files)mapz([a-z0-9_]+)/([a-z0-9_]+)c                   .    \ rS rSrSr\S 5       rS rSrg)Regen.   z"Regenerate given API(s) in gcloud.c                     U R                  S[        R                  " 5       SS9  U R                  SSS9  U R                  SSS9  U R                  S	S
S9  g )Napia.  The APIs to regenerate in api_name/api_version format. These can be filename glob expressions to regenerate multiple apis. For example */* to regegenerate all apis and versions, or */*beta* to only regenerate existing beta apis. Note that if discovery doc is supplied this cannot contain any wildcards.)typehelpz--api-discovery-docz_Path to json file describing the api. If not specified, an existing discovery doc will be used.)r   z--configzRRegeneration config yaml filename. If not specified canonical config will be used.z
--base-dirzaDirectory where generated code will be written. By default googlecloudsdk/generated_clients/apis.)add_argumentr   ArgList)parsers    lib/surface/meta/apis/regen.pyArgs
Regen.Args2   s    
  "&  ' 7  8
 
O  P <  =    c                 >   [        UR                  5      nUS   nSnUR                  (       Ga  [        R                  R                  UR                  5      (       d/  [        R                  " SR                  UR                  5      5      e[        UR                  5      S:w  a  [        R                  " S5      e[        R                  " [        UR                  S   5      nU(       d)  [        R                  " SR                  [        5      5      eUR!                  S5      UR!                  S5      pvXbS	   ;  a&  ["        R$                  " S
U5        USS00US	   U'   SnO1XrS	   U   ;  a&  ["        R$                  " SU5        SS0US	   U   U'   SnUS	   R'                  U5      R'                  U0 5      nUS-   U-   S-   n	[        R                  R)                  UR                  5      n
[        R                  R)                  [        R                  R+                  UR,                  X95      5      nX:w  aD  ["        R.                  R1                  SR                  U
5      5        [2        R4                  " X5        US   U	:w  a  SnXS'   UR!                  S5      UR!                  S5      U4/nOSR+                  [7        [8        R:                  UR                  5      5      n[<        R>                  " US	   5       VVVVs/ s HL  u  ph[<        R>                  " U5        H,  u  p~[        R                  " XS-   U-   5      (       d  M(  XgU4PM.     MN     nnnnnU(       dG  [        R@                  " SR                  SR+                  UR                  5      UR                  S95      eUR,                  =(       dJ    [        R                  RC                  [        R                  RC                  [D        RF                  5      5      n[I        U5       H  u  pgn["        R.                  R1                  SR                  UU[        R                  R+                  X>S   5      5      5        [        R                  R+                  XUS   5      n	[        R                  R+                  X5      nURK                  SS5      n[L        RN                  " U	UUXgU5        [L        RP                  " U	UUUUR'                  S0 5      5        M     [        R                  R+                  XS5      n[R        RT                  " [V        5      nUS	   RY                  5        H'  u  nnU H  nURK                  SS5      UU   U'   M     M)     [L        RZ                  " UUUS	   5        U(       ak  ["        R$                  " SUR                  5        [\        R^                  " UR                  5       n[`        Rb                  Re                  UU5        S S S 5        g g s  snnnnf ! , (       d  f       g = f)Nroot_dirFzFile not found {}   z8Can only specify one api when discovery doc is provided.r   z>Api name must match {} pattern when discovery doc is specified   apisz#No such api %s in config, adding...discovery_doc Tz+No such api version %s in config, adding..._z.jsonzCopying in {}|/zqapi [{api_name}] not found in "apis" section of {config_file}. Use [gcloud meta apis list] to see available apis.,)api_nameconfig_filezGenerating {} {} from {}.	resourceszapis_map.pyz
Updated %s)3_LoadConfigconfigapi_discovery_docospathisfileregen_utilsDiscoveryDocErrorformatlenr   r
   ArgumentErrorrematch
_API_REGEXgroupr   warninggetrealpathjoinbase_dirstatusPrintshutilcopyfiler   fnmatch	translatesix	iteritems
UnknownApidirnamegooglecloudsdk__file__sortedreplacer   GenerateApitoolsApiGenerateApitoolsResourceModulecollectionsdefaultdictdictitemsGenerateApiMapr   
FileWriterruamelyamlround_trip_dump)selfargsr.   r   changed_configr9   r)   api_versionapi_version_configr#   new_discovery_docold_discovery_docregenerate_listregex_patern
api_configr@   
output_dirroot_packageapis_map_filepackage_mapversions_configversionstreams                          r   Run	Regen.RunL   s   %Fj!HNWW^^D2233++&&t'='=>@ 	@	TXX!	))FH 	H hhz488A;/e++!6*-/ 	/ $kk!nekk!n		'98D$//21F#Gvx VnX66A;O1@"0Evx -!&>--h7;;KLn{2W<m''**4+A+AB''**
'',,t}}h
>@ 
	/

//0ABC)=	O	,	=.;?+ ;;q>5;;q>+=
>o XXc'"3"3TXX>?l /2mmF6N.K.K*h),7I)J%kXXlsN[$@A .8*
-)J ..K   ""N6388DHH-"kk  +, , }} 2
//0!2H-3O-D)z	jj
$6('',,xO)DEGH
 ggll
j9;m77<<3j%%c3/l""
\8
 --




..b
) .E, GGLL]CM))$/K%+F^%9%9%;!/$')1)9)9#s)CHg& % &< M;vG 	kk,,DKK(F##FF3 )( _b )(s    AX
X
!X
X N)	__name__
__module____qualname____firstlineno____doc__staticmethodr   rk   __static_attributes__rm   r   r   r   r   .   s    *= =2b4r   r   c                 j   U =(       d_    [         R                  R                  [         R                  R                  [        R
                  " [        R                  5      5      S5      n [         R                  R                  U 5      (       d%  [        R                  " SR                  U 5      5      e[        R                  " U 5       n[        R                  R!                  U5      nSSS5        W(       a  SU;  a%  [        R                  " SR                  U 5      5      eU$ ! , (       d  f       NB= f)z'Loads regen config from given filename.zregen_apis_config.yamlz{} Not foundNr   z1{} does not have format of gcloud api config file)r0   r1   r?   rJ   r   Decoder   rL   r2   r3   ConfigFileErrorr5   r   
FileReaderrW   rX   round_trip_load)config_file_namerj   r.   s      r   r-   r-      s    %  ggoohook&:&:;<*  
(	)	)

%
%n&;&;<L&M
NN()V[[((0F *	:V+

%
%;	 	!# # 
- *)s    D$$
D2)N)$rr   
__future__r   r   r   rQ   rE   r0   r8   rC   rK   r   googlecloudsdk.api_lib.regenr   googlecloudsdk.callioper   r	   r
   googlecloudsdk.command_lib.metar   r3   googlecloudsdk.corer   googlecloudsdk.core.utilr   r   ruamel.yamlrW   rG   	six.movesr   r:   UniverseCompatibleCommandr   r-   rm   r   r   <module>r      s|     = &  '   	 	   & 1 / ( 1 @ # - *  
 (
 4DLL 4 4Dr   