o
    wvXj}  ã                   @   s¶   d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
 dZe d	¡Ze d
¡Ze d¡Ze d¡Ze d¡ZdZG dd„ deƒZdd„ ZG dd„ deƒZG dd„ de
ƒZdS )zDThe :program:`celery logtool` command.

.. program:: celery logtool
é    )Úabsolute_importÚunicode_literalsN)ÚCounter)Ú	FileInputé   )ÚCommand)Úlogtoolz^\[\d\d\d\d\-\d\d-\d\d z.+?\] Receivedz
.+?\] Taskz.+?([\w\.]+)\[(.+?)\].+z.+?[\w\.]+\[.+?\] (.+)zª
Report
======

Task total: {task[total]}
Task errors: {task[errors]}
Task success: {task[succeeded]}
Task completed: {task[completed]}

Tasks
=====
{task[types].format}
c                   @   s   e Zd Zedd„ ƒZdS )Ú_task_countsc                 C   s   d  dd„ | D ƒ¡S )NÚ
c                 s   s   � | ]}d j |Ž V  qdS )z{0}: {1}N)Úformat)Ú.0Úi© r   úO/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/bin/logtool.pyÚ	<genexpr>*   s   € z&_task_counts.format.<locals>.<genexpr>)Újoin©Úselfr   r   r   r   (   s   z_task_counts.formatN)Ú__name__Ú
__module__Ú__qualname__Úpropertyr   r   r   r   r   r	   &   s    r	   c                 C   s   t  | ¡}| ¡ S ©N)ÚRE_TASK_INFOÚmatchÚgroups)ÚlineÚmr   r   r   Ú	task_info-   s   
r   c                   @   sN   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚAuditNc                 C   sF   t ƒ | _i | _i | _t ƒ | _tƒ | _d| _|| _|| _	|| _
d | _d S )Nr   )ÚsetÚidsÚnamesÚresultsÚreadyr   Ú
task_typesÚtask_errorsÚon_task_errorÚon_traceÚon_debugÚ	prev_line)r   r'   r(   r)   r   r   r   Ú__init__4   s   
zAudit.__init__c                 C   s   t |ƒD ]}|  |¡ q| S r   )r   Úfeed)r   Úfilesr   r   r   r   Úrun@   s   z	Audit.runc                 C   s,   || j |< | j |¡ | j|  d7  < d S ©Nr   )r"   r!   Úaddr%   )r   r   Ú	task_nameÚtask_idr   r   r   Útask_receivedE   s   
zAudit.task_receivedc                 C   s6   | j  |¡ || j|< d|vr|  ||||¡ d S d S )NÚ	succeeded)r$   r0   r#   Ú
task_error©r   r   r1   r2   Úresultr   r   r   Ú
task_readyJ   s
   
ÿzAudit.task_readyc                 C   s,   |  j d7  _ | jr|  ||||¡ d S d S r/   )r&   r'   r6   r   r   r   r5   P   s   ÿzAudit.task_errorc                 C   s¶   t  |¡rEt |¡rt|ƒ\}}|  |||¡ n(t |¡r8t|ƒ\}}t |¡}|r/| ¡ \}|  ||||¡ n| j	r@|  	|¡ || _
d S | jrV|  d td | j
|gƒ¡¡ d | _
d S )Nr
   )ÚRE_LOG_STARTr   ÚRE_TASK_RECEIVEDr   r3   ÚRE_TASK_READYÚRE_TASK_RESULTr   r8   r)   r*   r(   r   Úfilterr6   r   r   r   r,   U   s    







z
Audit.feedc                 C   s   | j | jA S r   )r!   r$   r   r   r   r   Úincomplete_tasksi   s   zAudit.incomplete_tasksc                 C   s8   dt | j ¡ ƒt| jƒ| jt| jƒt| jƒ| j dœiS )NÚtask)ÚtypesÚtotalÚerrorsÚ	completedr4   )r	   r%   Úmost_commonÚlenr!   r&   r$   r   r   r   r   Úreportl   s   ûÿzAudit.report)NNN)r   r   r   r+   r.   r3   r8   r5   r,   r>   rF   r   r   r   r   r   2   s    
r   c                   @   sN   e Zd ZdZdZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )r   zThe ``celery logtool`` command.a'  <action> [arguments]
            .....  stats      [file1|- [file2 [...]]]
            .....  traces     [file1|- [file2 [...]]]
            .....  errors     [file1|- [file2 [...]]]
            .....  incomplete [file1|- [file2 [...]]]
            .....  debug      [file1|- [file2 [...]]]
    Nc                 O   sT   | j | j| j| j| jdœ}|s|  d¡‚||vr$|  d |d |¡¡¡‚|| |ƒS )N)ÚstatsÚtracesrB   Ú
incompleteÚdebugzmissing actionzaction {0} not in {1}ú|)	rG   rH   rB   rI   rJ   Ú
UsageErrorÚErrorr   r   )r   Úwhatr-   ÚkwargsÚmapr   r   r   r.   ƒ   s   û
ÿzlogtool.runc                 C   s&   |   tjdi tƒ  |¡ ¡ ¤Ž¡ d S )Nr   )ÚoutÚREPORT_FORMATr   r   r.   rF   ©r   r-   r   r   r   rG   ”   s   ÿzlogtool.statsc                 C   ó   t | jd� |¡ d S )N)r(   ©r   rQ   r.   rS   r   r   r   rH   ™   ó   zlogtool.tracesc                 C   rT   )N)r'   )r   Úsay1r.   rS   r   r   r   rB   œ   rV   zlogtool.errorsc                 C   s2   t ƒ }| |¡ | ¡ D ]
}|  d|f ¡ qd S )NzDid not complete: %r)r   r.   r>   Úerror)r   r-   Úauditr2   r   r   r   rI   Ÿ   s
   
ÿzlogtool.incompletec                 C   rT   )N)r)   rU   rS   r   r   r   rJ   ¥   rV   zlogtool.debugc                 G   s   |   |¡ d S r   )rQ   )r   r   Ú_r   r   r   rW   ¨   s   zlogtool.say1r   )r   r   r   Ú__doc__Úargsr.   rG   rH   rB   rI   rJ   rW   r   r   r   r   r   x   s    
r   )r[   Ú
__future__r   r   ÚreÚcollectionsr   Ú	fileinputr   Úbaser   Ú__all__Úcompiler9   r:   r;   r   r<   rR   Úlistr	   r   Úobjectr   r   r   r   r   r   Ú<module>   s"   




F