
    #                         S 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 rS rS rS rS rS rS rg)z*File utils for Artifact Registry commands.    N)	protojson)
exceptions)filter_rewriter)common_args)requests)util)
properties)	resourcesc           
          [         R                  R                  SU R                  U R                  U R
                  U R                  R                  SS5      R                  SS5      R                  SS5      S9$ 	z4Escapes slashes, pluses and hats from request names.6artifactregistry.projects.locations.repositories.files/%2F+%2B^%5E
projectsIdlocationsIdrepositoriesIdfilesId)r
   REGISTRYCreater   r   r   r   replace)refs    5lib/googlecloudsdk/command_lib/artifacts/file_util.pyEscapeFileNamer      sf    				"	">//''kk!!#u-wsEwsE 
# 
     c           
      "   [         R                  R                  SU R                  U R                  U R
                  U R                  R                  SS5      R                  SS5      R                  SS5      S9nUR                  5       Ul	        U$ r   )
r
   r   r   r   r   r   r   r   RelativeNamename)r   unused_argsreqfiles       r   EscapeFileNameHookr&   ,   sz    				"	">//''kk!!#u-wsEwsE 
# 
$  #(	*r   c           
          [         R                  R                  SU UUUR                  SS5      R                  SS5      R                  SS5      S9$ )	z.Escapes slashes and pluses from request names.r   r   r   r   r   r   r   r   )r
   r   r   r   )
project_idlocation_idrepo_idfile_ids       r   EscapeFileNameFromIDsr,   ;   sR    				"	">ooc5)wsEwsE 
# 
 r   c                 F    U  Vs/ s H  n[        US5      PM     sn$ s  snf )z+Convert hashes of file list to hex strings.N)ConvertFileHashes)filesfs     r   ConvertFilesHashesr1   H   s"    .3	4e
At
$e	44	4s   c                    [         R                  " [        R                  " U 5      5      n/ nU R                   H9  nUR                  UR                  UR                  R                  5       S.5        M;     U(       a  X2S'   0 nU R                  (       a5  U R                  R                   H  nUR                  XVR                  '   M     U(       a  XRS'   U$ )z#Convert file hashes to hex strings.)typevaluehashesannotations)jsonloadsr   encode_messager5   appendr3   r4   hexr6   additionalPropertieskey)responser#   json_objr5   hr6   ps          r   r.   r.   M   s     ZZ	00:;(&??a
MM  
 X
 +!!6677k%% 7)]	/r   c                 V   [         R                  " 5       n[         R                  " 5       n[        R                  " U 5      n[        R
                  " U 5      n[        R                  " U 5      nU R                  nU R                  n[        R                  R                  [        R                  R                  SUUUUUS95      nSR                  U5      n	[        R                  R                  [        R                  R                  SUUUS95      n
[         R                  " XX5      nU$ )zLists the Generic Files stored.Bartifactregistry.projects.locations.repositories.packages.versionsr   r   r   
packagesId
versionsId
owner="{}"0artifactregistry.projects.locations.repositoriesr   r   r   )r   	GetClientGetMessagesr   
GetProjectGetLocationGetRepopackageversionr
   Resourcer!   r   r   format	ListFiles)argsclientmessagesprojectlocationreporO   rP   version_patharg_filters	repo_pathr/   s               r   ListGenericFilesr]   o   s   &!!#(OOD!'d#(	d	$LL'LL'##00
N   	, ##L1+  --
<	   ) 

Vy
F%	,r   c                    [         R                  " 5       n[         R                  " 5       n[        R                  " U 5      nU R
                  =(       d2    [        R                  R                  R
                  R                  5       n[        R                  " U 5      nU R                  nU R                  nU R                  nU R                  n	[        R                   " U R"                  5      n
[$        R&                  " 5       R)                  U R*                  5      u  pU
b  SU
;   a  Sn
U(       d  U(       d  U(       a  Sn
U R,                  b  U R*                  b  Ub  U R,                  n	OSn	U(       a  U(       d  U(       d  U(       a  SnU(       a  [.        R0                  " SU5      (       a  UR3                  SSS5      R3                  SSS5      R3                  S	SS5      R3                  S
SS5      R5                  S5      n[7        [9        U5      5       Vs/ s H  oU   PM	     snu  p4pVU(       a4  UR3                  SS5      R3                  SS5      nUR3                  SS5      nU(       a  U(       a  [:        R<                  " S5      eU(       a]  U(       aV  [>        R@                  RC                  [>        RD                  RG                  SUUUUUS95      n[         RH                  " XU5      nU(       aX  U(       aQ  [>        R@                  RC                  [>        RD                  RG                  SUUUUUS95      nSRK                  U5      nO{U(       aP  [>        R@                  RC                  [>        RD                  RG                  SUUUUS95      nSRK                  U5      nO$U(       d  U(       a  [:        R<                  " S5      e[>        R@                  RC                  [>        RD                  RG                  SUUUS95      nUUUUU	U
S.n[        RL                  " [         RN                  40 UD6u  nnU(       d+  U(       a  XR*                  :X  a  SU l        U
(       a  SU l        [Q        U5      $ s  snf )z`Lists files in a given project.

Args:
  args: User input arguments.

Returns:
  List of files.
N,z;projects\/.*\/locations\/.*\/repositories\/.*\/packages\/.*z	projects/    z/locations/ z/repositories/z
/packages/r   r   r   r   r   r   z:Specify either --version or --tag with --package argument.z>artifactregistry.projects.locations.repositories.packages.tags)r   r   r   rE   tagsIdrC   rD   rG   z9artifactregistry.projects.locations.repositories.packages)r   r   r   rE   z8Package name is required when specifying version or tag.rH   rI   )rU   rV   rY   server_filter	page_sizeorder_by))r   rJ   rK   r   rL   rX   r	   VALUES	artifactsGetrN   rO   rP   tagre   r   ParseSortByArgsort_byr   RewriterRewritefilterlimitrematchr   splitrangelenr   InvalidInputValueErrorr
   rQ   r!   r   r   GetVersionFromTagrR   RetryOnInvalidArgumentsrS   r1   )rT   rU   rV   rW   rX   rY   rO   rP   rj   re   rf   _rd   paramsitag_pathrZ   package_pathr\   server_argsserver_args_skippedlfiless                         r   rS   rS      s    &!!#(OOD!']]Hj//99BBFFH(	d	$LL'LL'#nn)''5($--/77D!
h h'S h	ZZ 7  **i i'S m 	xxF  //+r1
-7=#q)7#S!,7<a(5:  >C3v;=O)P=O)=O)P&g ooc5)11#u=Gooc5)G 

+
+D  !!..!!L  	" 	
	H ((8DG%%22!!P  	" 	
	L !''5M%%22!!G  	" 	
L !''5M#

+
+B    --
<	   ) $+ !% < <!'!v 
 ++5dkdl	F	##a *Qs   Q2)__doc__r7   rq   apitools.base.protorpcliter    googlecloudsdk.api_lib.artifactsr   r   googlecloudsdk.api_lib.utilr   $googlecloudsdk.command_lib.artifactsr   r   googlecloudsdk.corer	   r
   r   r&   r,   r1   r.   r]   rS    r   r   <module>r      sP    1  	 0 7 < 3 9 5 * )

5
DBJ$r   