
     i3              	       V   S 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J	r	J
r
  S\S\4S jrS\S\4S jrS\S\4S	 jrS\S\4S
 jrS\S\4S jrS\S\4S jrS\S\4S jrS\S\S\4S jrSS\S\S\S\4S jjrSS\S\S\4S jjrS r\S:X  a  \R6                  " \" 5       5        gg)zv
gunicornc - Gunicorn control interface CLI

Interactive and single-command modes for controlling Gunicorn instances.
    N)_get_default_control_socket)ControlClientControlClientErrorparse_commanddatareturnc           
      <   U R                  S/ 5      nU(       d  g/ nUR                  SS SSS SSS	 SS
 35        UR                  S5        U H{  nUR                  SS5      nUR                  SS5      nUR                  S5      (       a  SOSnUR                  S5      nUb  U S3OSnUR                  US SUS SUS	 SU 35        M}     UR                  S5        UR                  SU R                  S[        U5      5       S35        SR                  U5      $ )z"Format workers output for display.workerszNo workers runningPID<10 AGE<6BOOTED<8	LAST_BEATz(----------------------------------------pid?agebootedyesnolast_heartbeats agon/a Total: countz workers
getappendlenjoin)	r   r
   lineswr   r   r   hbhb_strs	            B/var/www/ias/venv/lib/python3.13/site-packages/gunicorn/ctl/cli.pyformat_workersr*      s   hhy"%G#E	LLE#;abz8B-qFG	LLeeE3eeE3%%//tUU#$!#B4uUCy#b6"+Qvh?@  
LL	LL7488GS\:;8DE99U    c           
      .   U R                  S5      (       d  g/ nUR                  SU R                  S5       35        UR                  S5        U R                  S/ 5      nU(       a  UR                  S5        UR                  SS	 S
SS S
SS S
S 35        UR                  S5        U H  nUR                  SS5      nUR                  SS5      nSR                  UR                  S/ 5      5      SS nUR                  S5      nUb  U S3OSnUR                  US	 S
US S
US S
U 35        M     UR                  S5        U R                  S/ 5      nU(       a  UR                  S5        UR                  SS S
SS	 S
S 35        UR                  S5        U Hf  n	U	R                  SS5      SS n
U	R                  S S!5      nU	R                  S"5      nUb  [        U5      OS#nUR                  U
S S
US	 S
U 35        Mh     S$R                  U5      $ )%z(Format dirty workers output for display.enabledzDirty arbiter not runningzDirty arbiter PID: r   r   r
   zDIRTY WORKERS:r   r   r   r   r   APPSz<30r   z<------------------------------------------------------------r   r   , appsN   r   r   r   zDIRTY APPS:APPWORKERSLIMIT2--------------------------------------------------import_pathcurrent_workersr   worker_countnoner   )r!   r"   r$   str)r   r%   r
   r&   r   r   r0   r'   r(   apppathcurrentlimit	limit_strs                 r)   format_dirtyr@   -   s   88I*E	LL&txx&789	LLhhy"%G%&c{!E":Qvcl!K=IJXA%%s#C%%s#C99QUU62./4D'(B%'^t5\FLLC9Ac"XQtCj&BC  	R88FBD]#c{!Ic?!G9=>XC77=#.s3Dgg/3GGGN+E&+&7E
VILLD:Qwsm1YK@A  99Ur+   c                 8   / nU R                  S5      nU(       aV  [        US-  5      n[        US-  S-  5      n[        US-  5      nU(       a  U SU SU S3nOU(       a	  U SU S3nOU S3nOSnUR                  SU 35        UR                  S	U R                  S
S5       35        UR                  SU R                  SS5       35        UR                  SU R                  SS5       35        UR                  SU R                  SS5       35        UR                  SU R                  SS5       35        UR                  SU R                  SS5       35        U R                  S5      nU(       a  UR                  SU 35        SR                  U5      $ )z Format stats output for display.uptimei  <   zh zm sunknownzUptime:           zPID:              r   zWorkers current:  workers_currentr   zWorkers target:   workers_targetzWorkers spawned:  workers_spawnedzWorkers killed:   workers_killedzReloads:          reloadsdirty_arbiter_pidzDirty arbiter:    r   )r!   intr"   r$   )r   r%   rB   hoursminutesseconds
uptime_str	dirty_pids           r)   format_statsrR   W   s   EXXhFFdN#v}+,frk"!7"WIRy:J#9Bwiq1J#9AJ
	LL%j\23	LL%dhhui&@%ABC	LL%dhh/@!&D%EFG	LL%dhh/?&C%DEF	LL%dhh/@!&D%EFG	LL%dhh/?&C%DEF	LL%dhhy!&<%=>?,-I))5699Ur+   c           	         U R                  S/ 5      nU(       d  g/ nUR                  SS SSS SS 35        UR                  S	5        U HT  nUR                  S
S5      nUR                  SS5      nUR                  SS5      nUR                  US SUS SU 35        MV     UR                  S5        UR                  SU R                  S[        U5      5       S35        SR                  U5      $ )z$Format listeners output for display.	listenerszNo listeners boundADDRESSz<40r   TYPEr   FDz7-------------------------------------------------------addressr   typefdr   r   r   z
 listenersr   r    )r   rT   r%   lnraddrltyperZ   s          r)   format_listenersr^   x   s    b)I#E	LLIc?!F2;av67	LLwwy#&$WWT3Sz5*AbT23	  
LL	LL7488GS^<=ZHI99Ur+   c                     / n[        U R                  5       5       HJ  nX   n[        U[        5      (       a  SR	                  S U 5       5      nUR                  U SU 35        ML     SR	                  U5      $ )z!Format config output for display.r/   c              3   8   #    U  H  n[        U5      v   M     g 7fN)r:   ).0vs     r)   	<genexpr> format_config.<locals>.<genexpr>   s     4ec!ffe   z: r   )sortedkeys
isinstancelistr$   r"   )r   r%   keyvalues       r)   format_configrm      sn    E diik"	eT""II4e44EuBug&'	 # 99Ur+   c                 b   U R                  S0 5      n/ nUR                  S5        UR                  S5        U(       a   [        S UR                  5        5       5      OSn[	        UR                  5       5       H#  u  pEUR                  SUSUS-    3 S	U 35        M%     S
R                  U5      $ )zFormat help output for display.commandszAvailable commands:r   c              3   8   #    U  H  n[        U5      v   M     g 7fra   )r#   )rb   cmds     r)   rd   format_help.<locals>.<genexpr>   s     6os#c((orf   r     <   r   r   )r!   r"   maxrh   rg   itemsr$   )r   ro   r%   max_lenrq   descs         r)   format_helprz      s    xx
B'HE	LL&'	LL ;Cc6hmmo66GHNN,-	r#a!}_-Qtf56 . 99Ur+   c                    / nU R                  S0 5      nUR                  S5        UR                  SUR                  SS5       35        UR                  S5        U R                  S/ 5      nUR                  SU R                  S	S
5       S35        U(       a  UR                  SSS SSS SSS SS 35        UR                  SS 35        U H|  nUR                  SS5      nUR                  SS5      nUR                  S5      (       a  SOSnUR                  S5      nUb  U S3OSn	UR                  SUS SUS SUS SU	 35        M~     OUR                  S5        UR                  S5        U R                  S5      n
U
(       Ga  UR                  S 5        UR                  SU
R                  SS5       35        UR                  S5        U R                  S!/ 5      nUR                  S"U R                  S#S
5       S35        U(       Ga  UR                  SSS SSS SS$ 35        UR                  SS% 35        U H  nUR                  SS5      nUR                  SS5      nUR                  S&/ 5      nU(       aq  US
   R                  S'5      S(   nUR                  SUS SUS SU 35        US)S  H3  nUR                  S'5      S(   nUR                  SSS SSS SU 35        M5     M  UR                  SUS SUS S*35        M     O4UR                  S5        O"UR                  S 5        UR                  S+5        S,R                  U5      $ )-z#Format show all output for display.arbiterzARBITER (master)z  PID: r   r   r   web_workerszWEB WORKERS (web_worker_countr   )rs   r   r   r   r   r   r   r   r   z&--------------------------------------r   r   r   r   r   Nr   r   z  (none)dirty_arbiterzDIRTY ARBITERdirty_workerszDIRTY WORKERS (dirty_worker_countr.   r5   r0   :   z
 (no apps)z  (not running)r   )r!   r"   splitr$   )r   r%   r|   r}   r&   r   r   r   r'   r(   r   r   r0   	first_appr;   app_names                   r)   
format_allr      s2   E hhy"%G	LL#$	LL77;;uc2345	LL ((="-K	LL=*<a!@ ACDr%AeBZq"Q{mLMr(_%A%%s#C%%s#CeeHooU4F'(B%'^t5\FLL2c#YaBxq1VHEF  	Z 	LL HH_-M_%w}00<=>?R "5txx0Da'H&IKLLL2eC[%1VH=>LL2hZ)"eeE3'eeE3'uuVR( $Qc 22 6ILL2c#YaBxq!DE#ABx#&99S>"#5r"S2b'8*%EF  ( LL2c#YaBxz!BC # LL$_%&'99Ur+   commandc                 f   U R                  5       R                  5       nUS:X  a  [        U5      $ US:X  a  [        U5      $ US:X  a  [	        U5      $ US:X  a  [        U5      $ US:X  a  [        U5      $ US:X  a  [        U5      $ US:X  a  [        U5      $ U(       a  [        R                  " USS	9$ g
)z
Format response data based on command.

Args:
    command: Original command string
    data: Response data dictionary

Returns:
    Formatted string for display
zshow allzshow workersz
show dirtyz
show statszshow listenerszshow confighelpru   indentOK)lowerstripr   r*   r@   rR   r^   rm   rz   jsondumps)r   r   	cmd_lowers      r)   format_responser      s     %%'I J$	n	$d##	l	"D!!	l	"D!!	&	&%%	m	#T""	f	4   ::d1--r+   socket_pathjson_outputc                     [        U 5       n[        U5      u  pEU(       a$  U SSR                  U5       3R                  5       OUnUR	                  U5      nU(       a  [        [        R                  " USS95        O[        XG5      n[        U5         SSS5        g! , (       d  f       g= f! [         a%  n	[        SU	 3[        R                  S9   Sn	A	gSn	A	f[         a     g	f = f)
z
Execute single command and exit.

Args:
    socket_path: Path to control socket
    command: Command to execute
    json_output: If True, output raw JSON

Returns:
    Exit code (0 for success, 1 for error)
r   ru   r   Nr   Error: filer      )r   r   r$   r   send_commandprintr   r   r   r   sysstderrKeyboardInterrupt)
r   r   r   clientrq   argsfull_commandresultoutputes
             r)   run_commandr     s    ;'6%g.IC@DcU!CHHTN#34::<#L((6Fdjj23(5f (''  sm#**- s;   B0 B	BB0 
B-)B0 -B0 0
C*:CC*)C*c                     SSK nSn [        U 5      nUR                  5         [        SU  35        [        S	5        [        5         [        R                  R                  S
5      nU(       a   WR                  U5        Sn   [        S5      R                  5       nU(       d  M$  UR!                  5       S;   a  O [#        U5      u  pU
(       a$  U	 SSR%                  U
5       3R                  5       OU	nUR'                  U5      nU(       a  [        [(        R*                  " USS95        O[-        X5      n[        U5         [        5         M  UR/                  5         U(       a   WR3                  U5        U$  U$ ! [         a    Sn GNf = f! [         a%  n[        SU 3[        R                  S9   SnAgSnAff = f! [         a     GNQf = f! [         a    [        5          M  f = f! [         a[  n[        SU 35         UR/                  5         UR                  5          SnAN! [         a    [        S5        Sn  SnAM  f = fSnAff = f! [0         a    [        5         Sn GN f = f! [4         a     U$ f = f! UR/                  5         U(       a#   WR3                  U5        f ! [4         a     f f = ff = f)z
Run interactive CLI with readline support.

Args:
    socket_path: Path to control socket
    json_output: If True, output raw JSON

Returns:
    Exit code
r   NTFr   r   r   zConnected to z3Type 'help' for available commands, 'quit' to exit.z~/.gunicornc_historyz
gunicorn> )quitexitqr   ru   r   zConnection lost. Exiting.r   )readlineImportErrorr   connectr   r   r   r   osr<   
expanduserread_history_fileFileNotFoundErrorinputr   EOFErrorr   r   r$   r   r   r   r   closer   write_history_file	Exception)r   r   r   has_readliner   r   history_file	exit_codelinerq   r   r   r   r   s                 r)   run_interactiver   .  s   {+
 
M+
'(	
?@	G 77%%&<=L	&&|4 I/\*002
 zz|44)$/	DH#a'78>>@c,,\:$**VA67,S9F&M GG R 	++L9   S    sm#**- ! 		  * & 	sm$LLNNN$$) 56 !I	  	  	 	++L9  s%  E> F .G I G I :J <A0G/ ,I -G/ I (I4 >FF
G F;;G 
GGG,(I )J +G,,I /
I9I H-(I -III 	J IIII I1-J 0I11J 4
JJKJ0/K0
J=:K<J==Kc                     [         R                  " S[         R                  SS9n U R                  SS[	        5       SS9  U R                  SS	S
S9  U R                  SSSSS9  U R                  SSSSS9  U R                  5       nUR                  (       a  SSKJn  [        SU S35        gUR                  n[        R                  R                  U5      (       d3  [        R                  R                  [        R                  " 5       U5      nUR                   (       a   [#        X1R                   UR$                  5      $ ['        X1R$                  5      $ )z#Main entry point for gunicornc CLI.zGunicorn control interfacea?  
Examples:
  gunicornc                      # Interactive mode (default socket)
  gunicornc -s /tmp/myapp.ctl    # Interactive mode with custom socket
  gunicornc -c "show workers"    # Single command mode
  gunicornc -c "worker add 2"    # Add 2 workers
  gunicornc -c "show stats" -j   # Output stats as JSON
        )descriptionformatter_classepilogz-sz--socketzUControl socket path (default: auto-detected based on XDG_RUNTIME_DIR or ~/.gunicorn/))defaultr   z-cz	--commandzExecute single command and exit)r   z-jz--json
store_truezOutput raw JSON (for scripting))actionr   z-vz	--versionzShow version and exitr   )__version__zgunicornc (gunicorn r   )argparseArgumentParserRawDescriptionHelpFormatteradd_argumentr   
parse_argsversiongunicornr   r   socketr   r<   isabsr$   getcwdr   r   r   r   )parserr   r   r   s       r)   mainr     s5   $$0 <<F j+-d   k.  
 h.   k$   D||($[M34++K 77==%%ggll299;<||;dii@@{II66r+   __main__)F)__doc__r   r   r   r   gunicorn.configr   gunicorn.ctl.clientr   r   r   dictr:   r*   r@   rR   r^   rm   rz   r   r   boolrL   r   r   r   __name__r    r+   r)   <module>r      s(  
   	 
 7 P P # 2't ' 'Tt  B4 C ,  d s  ;T ;c ;| S      FS 3 T c BW W4 WC Wt67r zHHTV r+   