o
    wvXjk  ã                   @   sd   d Z ddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZ dZG d	d
„ d
eƒZdS )z@The :program:`celery graph` command.

.. program:: celery graph
é    )Úabsolute_importÚunicode_literals)Ú
itemgetter)ÚitemsÚpython_2_unicode_compatible)ÚDependencyGraphÚGraphFormatteré   )ÚCommand)Úgraphc                   @   s.   e Zd ZdZdZd
dd„Zdd„ Zdd	„ ZdS )r   zThe ``celery graph`` command.zq<TYPE> [arguments]
            .....  bootsteps [worker] [consumer]
            .....  workers   [enumerate]
    Nc                 O   sN   | j | jdœ}|s|  d¡‚||vr|  d |d |¡¡¡‚|| |i |¤ŽS )N)Ú	bootstepsÚworkerszmissing typezno graph {0} in {1}ú|)r   r   Ú
UsageErrorÚErrorÚformatÚjoin)ÚselfÚwhatÚargsÚkwargsÚmap© r   úM/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/bin/graph.pyÚrun   s   
z	graph.runc                 O   sd   | j  ¡ }dd„ |pddgD ƒ}d|v r%|jj}d|v r$|j |jj¡ n|jjj}| | j¡ d S )Nc                 S   s   h | ]}|  ¡ ’qS r   )Úlower©Ú.0Úargr   r   r   Ú	<setcomp>$   ó    z"graph.bootsteps.<locals>.<setcomp>ÚworkerÚconsumer)ÚappÚWorkControllerÚ	blueprintr   Úconnect_withr"   Úto_dotÚstdout)r   r   r   r!   ÚincludeÚworker_graphr   r   r   r   "   s   
€
zgraph.bootstepsc                    sþ  ‡fdd„‰d,dd„‰t ‡fdd„ˆD ƒƒ‰dˆv ‰d	d
„ ‰tG dd„ dtƒƒ}G ‡ ‡fdd„d|ƒ‰ G ‡ fdd„dtƒ}dd„ ‰G dd„ d|ƒ}G ‡‡fdd„d|ƒ}G ‡‡fdd„d|ƒ}ddlm} |dƒ‰tˆ dd¡pqdƒ}	tˆ dd¡p{dƒ}
|	f‡‡fd d!„	}zˆd" }ˆ d#¡p‘g }W n/ tyÂ   | j	j
 ¡  ¡ p£i }g g }}t|ƒD ]\}}| |¡ | |d$ d% ¡ q­Y nw t|ƒ}ˆ d&| j	jj¡}i }||dƒ}|	rè||	krè|dd… |d' g }t|ƒD ]\}}|ttt|ƒƒƒd(|
ƒ||| < qì|ˆ d)| j	 ¡  ¡ ¡ƒ}|�r||ƒnd }t|ƒ d*�}| |¡ |�r*| |¡ dg}t|ƒD ]E\}}|||d+�}| |¡ | ||¡ |�rO| ||¡ | |j¡}|�rm|D ]}ˆ |ƒ}| |¡ | ||¡ �qZ|d  d7  < �q1| | j¡ d S )-Nc                    s   ˆ t ddƒ|  d¡ƒƒS )Nr   é   ú:)r   Ú	partition)r   )Ú
maybe_listr   r   Ú	simplearg/   s   z graph.workers.<locals>.simpleargú,c                 S   s,   | d || d v r| d   |¡fS | d fS )Nr   r	   )Úsplit)ÚlÚsepr   r   r   r.   2   s   ,z!graph.workers.<locals>.maybe_listc                 3   s   � | ]}ˆ |ƒV  qd S ©Nr   r   )r/   r   r   Ú	<genexpr>5   s   € z graph.workers.<locals>.<genexpr>Úgenericc                 S   s   d  t| ƒj| j d¡d ¡S )Nz{0} ({1}://)z://r   )r   ÚtypeÚ__name__Ú_labelr1   )Únoder   r   r   Úgeneric_label8   s   ÿz$graph.workers.<locals>.generic_labelc                   @   s.   e Zd ZdZi Zddd„Zdd„ Zdd„ ZdS )	zgraph.workers.<locals>.NodeNc                 S   s   || _ || _d S r4   )r9   Úpos)r   Úlabelr<   r   r   r   Ú__init__A   s   
z$graph.workers.<locals>.Node.__init__c                 S   s   | j S r4   ©r9   ©r   r   r   r   r=   E   s   z!graph.workers.<locals>.Node.labelc                 S   s   |   ¡ S r4   ©r=   r@   r   r   r   Ú__str__H   s   z#graph.workers.<locals>.Node.__str__r4   )r8   Ú
__module__Ú__qualname__Úforce_labelÚschemer>   r=   rB   r   r   r   r   ÚNode<   s    
rG   c                       s2   e Zd ZdddddddœZ‡‡ ‡fdd	„Z‡  ZS )
zgraph.workers.<locals>.ThreadÚ
lightcyan4ÚyellowÚovalé
   g333333Ó?Úblack)Ú	fillcolorÚ	fontcolorÚshapeÚfontsizeÚwidthÚcolorc                    s(   || _ tˆ | ƒjd tˆƒ¡dd� d S )Nzthr-{0}r   )r=   r<   )Ú
real_labelÚsuperr>   r   Únext)r   r=   r   )ÚThreadÚ	__class__Útidsr   r   r>   U   s
   

þz&graph.workers.<locals>.Thread.__init__)r8   rC   rD   rF   r>   Ú__classcell__r   )rV   rX   )rW   r   rV   K   s    ú	rV   c                       s4   e Zd Zdd„ Z‡ fdd„Zdd„ Z‡ fdd„Zd	S )
z graph.workers.<locals>.Formatterc                 S   s   |o|  ¡ S r4   rA   ©r   Úobjr   r   r   r=   ^   s   z&graph.workers.<locals>.Formatter.labelc                    sD   |j rt|jƒn|j}t|ˆ ƒr|j|d< |  |t| jfi |¤Ž¡S )Nr=   )r<   ÚdictrF   Ú
isinstancerS   Ú	draw_nodeÚnode_scheme)r   r[   rF   ©rV   r   r   r:   a   s   

ÿz%graph.workers.<locals>.Formatter.nodec                 S   s   |   |t| jfi |j¤Ž¡S r4   )r^   r\   Úterm_schemerF   rZ   r   r   r   Úterminal_nodei   s   ÿz.graph.workers.<locals>.Formatter.terminal_nodec                    s*   t |ˆ ƒr|jddd� |  ||| j|¡S )NÚnoneÚtee)Ú	arrowheadÚ	arrowtail)r]   ÚupdateÚ	draw_edgeÚedge_scheme)r   ÚaÚbÚattrsr`   r   r   Úedgen   s   
z%graph.workers.<locals>.Formatter.edgeN)r8   rC   rD   r=   r:   rb   rm   r   r`   r   r   Ú	Formatter\   s
    rn   c                    s6   ddddddddd	d
dœ
‰ d  ‡ fdd„t| ƒD ƒ¡S )Nu   â‚€u   â‚�u   â‚‚u   â‚ƒu   â‚„u   â‚…u   â‚†u   â‚‡u   â‚ˆu   â‚‰)
Ú0Ú1Ú2Ú3Ú4Ú5Ú6Ú7Ú8Ú9Ú c                    s   g | ]}ˆ | ‘qS r   r   )r   Úi©ÚSr   r   Ú
<listcomp>v   r    z4graph.workers.<locals>.subscript.<locals>.<listcomp>)r   Ústr)Únr   r{   r   Ú	subscripts   s   

ÿz graph.workers.<locals>.subscriptc                   @   s   e Zd ZdS )zgraph.workers.<locals>.WorkerN)r8   rC   rD   r   r   r   r   ÚWorkerx   s    r�   c                       s*   e Zd ZddddddœZ‡ ‡fdd„Zd	S )
zgraph.workers.<locals>.BackendÚfolderr+   r	   rL   Ú
peachpuff3)rO   rQ   ÚheightrR   rM   c                    ó   ˆ rˆ| ƒS | j S r4   r?   r@   ©r6   r;   r   r   r=   „   ó   z$graph.workers.<locals>.Backend.labelN©r8   rC   rD   rF   r=   r   r†   r   r   ÚBackend{   s    ûr‰   c                       s(   e Zd ZdddddœZ‡ ‡fdd„ZdS )	zgraph.workers.<locals>.BrokerÚcircleÚ
cadetblue3Ú
cadetblue4r	   )rO   rM   rR   r„   c                    r…   r4   r?   r@   r†   r   r   r=   �   r‡   z#graph.workers.<locals>.Broker.labelNrˆ   r   r†   r   r   ÚBroker‡   s    ür�   r   )Úcountr	   Úwmaxé   Útmaxé   c                    s~   t | ƒ}|o	||k}dˆv r‡ ‡fdd„t| ƒD ƒ} |r=| d|d … | |d  g } d ˆ d ˆ||d  ƒ¡| |d < | S )NÚ	enumeratec                    s$   g | ]\}}d   ˆ ˆ|d ƒ¡‘qS )z{0}{1}r	   )r   )r   rz   r[   )Únamer€   r   r   r}   ›   s    ÿz5graph.workers.<locals>.maybe_abbr.<locals>.<listcomp>r   r	   u   {0}âŽ¨â€¦{1}âŽ¬r+   )Úlenr“   r   )r2   r”   ÚmaxÚsizeÚabbr)r   r€   )r”   r   Ú
maybe_abbr—   s   ÿÿz!graph.workers.<locals>.maybe_abbrÚnodesÚthreadsÚpoolzmax-concurrencyÚbackendéÿÿÿÿÚPÚbroker)Ú	formatter)r<   )r0   )r\   r   Úobjectr   Ú	itertoolsrŽ   ÚintÚgetÚKeyErrorr#   ÚcontrolÚinspectÚstatsr   Úappendr•   ÚconfÚresult_backendr“   ÚlistÚrangeÚconnection_for_readÚas_urir   Úadd_arcÚadd_edger9   r'   r(   )r   r   r   rG   rn   r�   r‰   r�   rŽ   ÚWmaxÚTmaxr™   r   r›   Úrepliesr!   ÚreplyÚwlenr�   Úthreads_forrz   r    ÚdepsÚ	curworkerÚthreadr   )rV   r   r6   r;   r.   r/   r€   rX   r   r   -   s|   


þý
ÿÿ



zgraph.workersr4   )r8   rC   rD   Ú__doc__r   r   r   r   r   r   r   r   r      s    
r   N)r¼   Ú
__future__r   r   Úoperatorr   Úcelery.fiver   r   Úcelery.utils.graphr   r   Úbaser
   Ú__all__r   r   r   r   r   Ú<module>   s   