
                         H   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddj#                  dd      dZ e
j&                  e
j(                  j*                  e
j(                  j,                         G d de
j.                               Zy)zACommand for retrieving a screenshot from the designated instance.    )absolute_import)division)unicode_literalsN)base_classes)base)flags)log)filesLCapture a screenshot (JPEG image) of the virtual machine instance's display.zx        To get a screenshot from an instance named ``{0}'', run:

          $ {1} {0} --destination=output.jpg

        ztest-instancez	{command})DESCRIPTIONEXAMPLESc                   B    e Zd ZdZeZdZed        Zd Z	d Z
d Zd	dZy)
GetScreenshotr   Fc                 l    t         j                  j                  | d       | j                  dd       y )Nzget a screenshot from)operation_typez--destinationzBFilename, including the path, to save the screenshot (JPEG image).)help)r   INSTANCE_ARGAddArgumentadd_argument)parsers    /lib/surface/compute/instances/get_screenshot.pyArgszGetScreenshot.Args3   s<    	""6 # 8
       c                     t         j                  j                  ||j                  t        j                  |j
                              S )N)scope_lister)r   r   ResolveAsResource	resourcesGetInstanceZoneScopeListerclient)selfholderargss      r   _GetInstanceRefzGetScreenshot._GetInstanceRef<   s@    //55fmmD 0 F Fr   c                      |j                   j                  j                  di |j                         }|j                   j	                  |j                   j
                  j                  d|fg      d   S )NGetr    )r   messagesComputeInstancesGetRequestAsDictMakeRequestsapitools_client	instances)r    r!   instance_refrequests       r   _GetInstancezGetScreenshot._GetInstanceB   so    ?fmm$$?? !



!G==%%(E(E(O(O(-w(8 '9 ::;= =r   c                    t        j                  | j                               }| j                  ||      } |j                  j
                  j                  di |j                         }|j                  j                  |j                  j                  j                  d|fg      d   }d| _        |j                  d      rt        j                  |j                        5 }|j!                  t#        j$                  |j&                               d d d        |j(                  | _        |j                  | _        d| _        y |j&                  | _        y # 1 sw Y   ExY w)Nr   r   FdestinationTr&   )r   ComputeApiHolderReleaseTrackr#   r   r'   $ComputeInstancesGetScreenshotRequestr)   r*   r+   r,   _display_file_outputIsSpecifiedr
   BinaryFileWriterr1   writebase64	b64decodecontentsinstance_resource_name_destination_response_contents)r    r"   r!   r-   r.   responseoutputs          r   RunzGetScreenshot.RunH   s,   **4+<+<+>?F''5LIfmm$$II !



!G }}))		&	&	0	0/7K+ 
H !&D&!!$"2"23vV%%h&7&789 4(11d**d"&d  !) 1 1d
 43s   !/EEc                 0   | j                   rDt        j                  j                  dj	                  | j
                  | j                               y t        j                  j                  j                  t        j                  | j                               y )Nz#Output screenshot for [{}] to '{}'.)r5   r	   statusPrintformatr=   r>   sysstdoutbufferr8   r9   r:   r?   )r    resources_were_displayeds     r   EpilogzGetScreenshot.Epilog]   sg      	jj<CC


t002 3 
jjf..t/F/FGHr   N)F)__name__
__module____qualname____doc___DETAILED_HELPdetailed_help_display_outputstaticmethodr   r#   r/   rB   rK   r&   r   r   r   r   ,   s7    T -/   F=*Ir   r   )rO   
__future__r   r   r   r9   rG   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   ,googlecloudsdk.command_lib.compute.instancesr   googlecloudsdk.corer	   googlecloudsdk.core.utilr
   rF   rP   ReleaseTracksr3   BETAGACommandr   r&   r   r   <module>r^      s    H &  '  
 7 ( > # *
	
 F?K0 D%%**D,=,=,@,@A5IDLL 5I B5Ir   