
    9YfV-                         d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZmZ d dlmZ  G d de      Zd Zy)	    N)pretty_json)api)report_errorsreport_warnings	print_err)datetimec                       e Zd Zed        Zed        Zed        Zedd       Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zed        Zy)ScreenboardClientc                    |j                  dd      }|j                  dddd       |j                  d	d
      }d|_        |j                  dd      }|j                  dd       |j                  dd       |j                  ddd       |j                  dt        g d       |j                  dt
        d d       |j                  dt
        d d       |j                  | j                         |j                  dd       }|j                  d!d"       |j                  dd       |j                  dd       |j                  ddd       |j                  dt        g d       |j                  dt
        d d       |j                  dt
        d d       |j                  | j                         |j                  d#d$      }|j                  d!d%       |j                  | j                         |j                  d&d'      }|j                  d!d(       |j                  | j                         |j                  d)d*      }|j                  d!d+       |j                  | j                         |j                  d,d-      }	|	j                  d!d.       |	j                  | j                         |j                  d/d0      }
|
j                  d!d1       |
j                  d2d3       |
j                  | j                         |j                  d4d5      }|j                  d6dd7d8       |j                  d9d:d;t        j                  d<      =       |j                  | j                          |j                  d>d?      }|j                  d2d@       |j                  ddd       |j                  | j"                         y )ANscreenboardz&Create, edit, and delete screenboards.)helpz--string_ids
store_true
string_idsz<Represent screenboard IDs as strings instead of ints in JSON)actiondestr   Verbsverb)titler   TpostzCreate screenboards.r   ztitle for the new screenboarddescriptionz$short description of the screenboardgraphsz?graph definitions as a JSON string. if unset, reads from stdin.?)r   nargsz--template_variableszla json list of template variable dicts, e.g. [{'name': 'host', 'prefix': 'host', 'default': 'host:my-host'}])typedefaultr   z--widthzscreenboard width in pixelsz--heightzscreenboard height in pixels)funcupdatezUpdate existing screenboards.screenboard_idz/screenboard to replace  with the new definitionshowzShow a screenboard definition.zscreenboard to showdeletezDelete a screenboard.zscreenboard to deletesharez2Share an existing screenboard's with a public URL.zscreenboard to sharerevokez3Revoke an existing screenboard's with a public URL.zscreenboard to revokepullz2Pull a screenboard on the server into a local filezID of screenboard to pullfilenamezfile to pull screenboard intopushz;Push updates to screenboards from local files to the serverz--append_auto_textappend_auto_textzdWhen pushing to the server, appends filename and timestamp to the end of the screenboard descriptionfilez'screenboard files to push to the server+r)r   r   r   new_filez7Create a new screenboard and put its contents in a filez-name of file to create with empty screenboard)
add_parseradd_argumentadd_subparsersrequired_template_variablesintset_defaults_post_update_show_delete_share_revoke_pullargparseFileType_push	_new_file)cls
subparsersparserverb_parserspost_parserupdate_parsershow_parserdelete_parsershare_parserrevoke_parserpull_parserpush_parsernew_file_parsers                \/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/datadog/dogshell/screenboard.pysetup_parserzScreenboardClient.setup_parser   s.   &&};c&dO	 	 	
 ,,7,H $"--f;Q-R  /N O  5[ \  _gj 	! 	
 	  "$N	 	! 	
 	  dIf g  #tJh i  cii 0$//?^/_""#3:n"o""71P"Q""=7]"^""_gj 	# 	
 	"""$	 	# 	
 	""93Kh"i"":CLj"k"""4"--f;[-\  !18M N  cii 0$//?V/W""#3:Q"R"""4#..w=t.u!!"29O!P!!szz!2$//?w/x""#3:Q"R"""4"--f;r-s  !18S T  2Q R  cii 0"--Y . 
 	   #C	 	! 	
 	  B#T\TeTefiTj 	! 	
 	  cii 0&11Y 2 
 	$$Z6h$i$$_gj 	% 	
 	$$#--$8    c                     | j                  |j                  |j                  |j                  |j                  |j
                         y N)_write_screen_to_filer   r$   timeoutformatr   )r=   argss     rJ   r8   zScreenboardClient._pulls   s4    !!$"5"5t}}dllTXT_T_aeapapqrL   c                 r   |j                   t        _        |j                  D ]  }t	        j
                  |      }|j                  rct        j                         j                  d      }dj                  ||j                  |d   t        j                               }|dxx   |z  cc<   d|v r1t        |d         |d<   t        j                  j                   d	i |}nt        j                  j"                  d	i |}d|v r(t%        dj                  |d   |j                               t'        |       t)        |       t        dk(  rt+        t-        |             nt+        t	        j.                  |             |j                  dk(  skt+        dj                  |j                  |d                 y )
Nz%x %Xz*<br/>
Updated at {0} from {1} ({2}) on {3}idr   errorsz/Upload of screenboard {0} from file {1} failed.prettyz#Uploaded file {0} (screenboard {1}) )rP   r   _timeoutr'   jsonloadr&   r   nowstrftimerQ   nameplatformnoder0   Screenboardr   creater   r   r   printr   dumps)r=   rR   f
screen_objdatetime_str	auto_textress          rJ   r;   zScreenboardClient._pushx   s^   || 	^A1J$$'||~66w?IPP !&&*T*:HMMO	 =)Y6)z!#&z$'7#8
4 oo,,:z:oo,,:z:3KRRS]^bScefekeklmC #!k#&'djjo&{{h&;BB166:VZK[\];	^rL   c                    t        |d      5 }t        j                  j                  |      }t	        |       t        |       |}d|v r|d= d|v r|d= |rt        |d         |d<   t        j                  ||d       |dk(  rt        dj                  ||             nt        d	j                  ||             d d d        y # 1 sw Y   y xY w)
NwresourceurlrT      )indentrV   z&Downloaded screenboard {0} to file {1}z{0} {1})openr   r`   getr   r   strrY   dumprb   rQ   )	r=   r   r$   rP   rQ   r   rd   rh   re   s	            rJ   rO   z'ScreenboardClient._write_screen_to_file   s    (C  	BA//%%n5CC #JZ'z*
"u%#&z$'7#8
4 IIj!A.!>EEnV^_`i&&~x@A'	B 	B 	Bs   B-CCc                 d   t         j                  j                         }|j                  t        _        |j                  }|j                  }|j                  t         j                  j                         }t        j                  |      }t        j                  j                  |j                  |j                  |g|j                  |j                  |j                         }t#        |       t%        |       |dk(  rt'        t)        |             y t'        t        j*                  |             y )N)r   r   r   template_variableswidthheightrV   )sysstdinreadrP   r   rX   rQ   r   rY   loadsr`   ra   r   r   rt   ru   rv   r   r   rb   r   rc   )r=   rR   r   rQ   rh   s        rJ   r2   zScreenboardClient._post   s    !||;;YY^^%FF#oo$$**((8#66**;; % 
 	cX+c"#$**S/"rL   c           	      <   |j                   t        _        |j                  }|j                  }|j                  t
        j                  j                         }t        j                  |      }t        j                  j                  |j                  |j                  |j                  ||j                  |j                   |j"                        }t%        |       t'        |       |dk(  rt)        t+        |             y t)        t        j,                  |             y )N)board_titler   widgetsrt   ru   rv   rV   )rP   r   rX   rQ   r   rw   rx   ry   rY   rz   r`   r   r   r   r   rt   ru   rv   r   r   rb   r   rc   r=   rR   rQ   r   rh   s        rJ   r3   zScreenboardClient._update   s    ||;;YY^^%FF#oo$$

((#66**;; % 
 	cX+c"#$**S/"rL   c                     t        j                  |j                        d   }t        j                  dj                  |      z   }t        j                  |       y )NrT   z/dash/dash/{0})rY   rZ   r'   r   	_api_hostrQ   
webbrowserro   )r=   rR   dash_idrl   s       rJ   	_web_viewzScreenboardClient._web_view   s?    ))DII&t,mm.55g>>rL   c                 n   |j                   t        _        |j                  }t        j                  j                  |j                        }t        |       t        |       |j                  rt        |d         |d<   |dk(  rt        t        |             y t        t        j                  |             y )NrT   rV   )rP   r   rX   rQ   r`   rp   r   r   r   r   rq   rb   r   rY   rc   r=   rR   rQ   rh   s       rJ   r4   zScreenboardClient._show   s}    ||oo!!$"5"56c??CICIX+c"#$**S/"rL   c                     |j                   t        _        t        j                  j	                  |j
                        }|t        |       t        |       y y rN   )rP   r   rX   r`   r    r   r   r   )r=   rR   rh   s      rJ   r5   zScreenboardClient._delete   sA    ||oo$$T%8%89?C # rL   c                    |j                   t        _        |j                  }t        j                  j                  |j                        }|dk(  rt        t        |             y t        t        j                  |             y NrV   )rP   r   rX   rQ   r`   r!   r   rb   r   rY   rc   r   s       rJ   r6   zScreenboardClient._share  sU    ||oo##D$7$78X+c"#$**S/"rL   c                    |j                   t        _        |j                  }t        j                  j                  |j                        }|dk(  rt        t        |             y t        t        j                  |             y r   )rP   r   rX   rQ   r`   r"   r   rb   r   rY   rc   r   s       rJ   r7   zScreenboardClient._revoke  sU    ||oo$$T%8%89X+c"#$**S/"rL   c                 p   |j                   t        _        |j                  }|j                  }|j                  t
        j                  j                         }t        j                  |      }t        j                  j                  |j                  dj                  |j                        |g      }t        |       t        |       | j                  |d   |j                  |j                   ||j                          |dk(  rt#        t%        |             y t#        t        j&                  |             y )NzDescription for {0})r|   r   r}   rT   rV   )rP   r   rX   rQ   r   rw   rx   ry   rY   rz   r`   ra   r$   r   r   rO   r   rb   r   rc   r~   s        rJ   r<   zScreenboardClient._new_file  s    ||;;YY^^%FF#oo$$3H3O3OPTP]P]3^iohp % 
 	c!!#d)T]]DLL&RVRaRabX+c"#$**S/"rL   N)rawF)__name__
__module____qualname__classmethodrK   r8   r;   rO   r2   r3   r   r4   r5   r6   r7   r<   rW   rL   rJ   r
   r
      s    [9 [9z r r ^ ^B B B, # #. # #0  
 # #   # # # # # #rL   r
   c                     d| vr-| j                  d      D cg c]  }|j                          c}S 	 t        j                  |       S c c}w # t        $ r t        j                  d      w xY w)N[,z$bad template_variable json parameter)splitstriprY   rz   	Exceptionr9   ArgumentTypeError)tpl_var_inputvs     rJ   r/   r/   -  sk    
-#0#6#6s#;<a	<<	U::m,, =  	U,,-STT	Us   AA A,)r9   rY   r^   rw   r   datadog.util.formatr   datadogr   datadog.dogshell.commonr   r   r   r   objectr
   r/   rW   rL   rJ   <module>r      s>   
    
  ,  M M V# V#rUrL   