
    &                     p    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J	r	  SSK
Jr  SSKrS rS	 rg)
z5This package provides tools for saving docker images.    )absolute_import)division)print_functionN)docker_name)docker_imagec                   ^ U4S jn[        5       n0 n[        R                  " U 5       GH  u  pV[        UR	                  5       5      nUR                  U0 5      nUR                  5       XR                  '   XU'   UR                  UR                  5       5       H  n	X;   d9  [        R                  " UR                  U	5      5      R                  S5      (       a  MC  UR                  U	5        U" U	S-   S5        UR                  U	5      n
U" U	S-   U
5        U" U	S-   UR                  U	5      R                  S5      5        M     GM     U" S[        R                  " US	S
9R                  S5      5        g)zProduce a "docker save" compatible tarball from the DockerImages.

Args:
  tag_to_image: A dictionary of tags to the images they label.
  tar: the open tarfile into which we are writing the image tarball.
c                    > [         R                  " U 5      n[        U5      Ul        TR	                  U[
        R                  " U5      S9  g N)tarinfofileobjtarfileTarInfolensizeaddfileioBytesIOfilenamecontentsinfotars      4lib/third_party/containerregistry/client/v1/save_.pyadd_file%multi_image_tarball.<locals>.add_file)   5    ??8$DHDIKKbjj&:K;    	throwawayz/VERSIONs   1.0z
/layer.tarz/jsonutf8repositoriesT)	sort_keysN)setsix	iteritemsstras_repositorygettoptagancestryjsonloadsadduncompressed_layerencodedumps)tag_to_imager   r   seenr!   r*   imagerepotagslayer_idcontents    `         r   multi_image_tarballr9      s8   <
 
$, mmL1lss  "#DD"%DIIKDMNN599;/		TZZ

8(<=AA+NN
hhx x*$f- ((2gx,&0 x'!5::h#7#>#>v#FG 0 22 >::ld3::6BDr   c                 x   ^ U4S jn[        X0T5        U" SUR                  5       R                  S5      5        g)zProduce a "docker save" compatible tarball from the DockerImage.

Args:
  name: The tag name to write into the repositories file.
  image: a docker image to save.
  tar: the open tarfile into which we are writing the image tarball.
c                    > [         R                  " U 5      n[        U5      Ul        TR	                  U[
        R                  " U5      S9  g r
   r   r   s      r   r   tarball.<locals>.add_file\   r   r   r)   r    N)r9   r)   r0   )namer4   r   r   s     ` r   tarballr>   R   s3    <
 tmS) 5%))+$$V,-r   )__doc__
__future__r   r   r   r   r,   r   containerregistry.clientr   containerregistry.client.v1r   r$   r9   r>    r   r   <module>rD      s1    < &  % 	   0 4 
0Df.r   