o
    O6uf0  ã                   @   s   d Z zddlZW n ey   ddlZY nw G dd„ deƒZG dd„ deƒZG dd„ deƒZd	d
„ ZG dd„ deƒZ	G dd„ deƒZ
G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )zR This provides a restricted tag language to define the sosreport
    index/report
é    Nc                   @   s    e Zd Zi Zdd„ Zdd„ ZdS )ÚNodec                 C   s   t  | j¡S ©N)ÚjsonÚdumpsÚdata©Úself© r	   ú6/usr/lib/python3/dist-packages/sos/report/reporting.pyÚ__str__   s   zNode.__str__c                 C   s   dS )NFr	   ©r   Únoder	   r	   r
   Úcan_add   s   zNode.can_addN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r	   r	   r	   r
   r      s    r   c                   @   s   e Zd ZdZdS )ÚLeafz0Marker class that can be added to a Section nodeN)r   r   r   Ú__doc__r	   r	   r	   r
   r   !   s    r   c                   @   ó(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚReportz?The root element of a report. This is a container for sections.c                 C   s
   i | _ d S r   )r   r   r	   r	   r
   Ú__init__)   ó   
zReport.__init__c                 C   ó
   t |tƒS r   )Ú
isinstanceÚSectionr   r	   r	   r
   r   ,   r   zReport.can_addc                 G   s&   |D ]}|   |¡r|j| j|j< qd S r   )r   r   Úname©r   Únodesr   r	   r	   r
   Úadd/   s
   
€þz
Report.addN©r   r   r   r   r   r   r   r	   r	   r	   r
   r   &   s
    r   c                 C   ó   t | tƒr| S |  dd¡S )z3returns a string text for a given unicode/str inputÚutf8Úignore©r   ÚstrÚdecode)Úsr	   r	   r
   Ú_decode5   s   r'   c                   @   r   )	r   zeA section is a container for leaf elements. Sections may be nested
    inside of Report objects only.c                 C   s   t |ƒ| _i | _d S r   )r'   r   r   )r   r   r	   r	   r
   r   >   s   

zSection.__init__c                 C   r   r   )r   r   r   r	   r	   r
   r   B   r   zSection.can_addc                 G   s0   |D ]}|   |¡r| j |jg ¡ |j¡ qd S r   )r   r   Ú
setdefaultÚADDS_TOÚappendr   r	   r	   r
   r   E   s
   
€þzSection.addNr   r	   r	   r	   r
   r   :   s
    r   c                   @   ó   e Zd ZdZdd„ ZdS )ÚCommandÚcommandsc                 C   s   t |ƒ|t |ƒdœ| _d S )N)r   Úreturn_codeÚhref©r'   r   )r   r   r.   r/   r	   r	   r
   r   O   s   þzCommand.__init__N©r   r   r   r)   r   r	   r	   r	   r
   r,   K   ó    r,   c                   @   r+   )Ú
CopiedFileÚcopied_filesc                 C   ó   t |ƒt |ƒdœ| _d S ©N)r   r/   r0   ©r   r   r/   r	   r	   r
   r   Y   ó   ÿzCopiedFile.__init__Nr1   r	   r	   r	   r
   r3   U   r2   r3   c                   @   r+   )ÚCreatedFileÚcreated_filesc                 C   r5   r6   r0   r7   r	   r	   r
   r   b   r8   zCreatedFile.__init__Nr1   r	   r	   r	   r
   r9   ^   r2   r9   c                   @   r+   )ÚAlertÚalertsc                 C   ó   t |ƒ| _d S r   r0   ©r   Úcontentr	   r	   r
   r   k   ó   zAlert.__init__Nr1   r	   r	   r	   r
   r;   g   r2   r;   c                   @   r+   )ÚNoteÚnotesc                 C   r=   r   r0   r>   r	   r	   r
   r   s   r@   zNote.__init__Nr1   r	   r	   r	   r
   rA   o   r2   rA   c                 C   s
   |   d¡S )a   Return True if 'string' ends with a backslash, and False otherwise.

        Define this as a named function for no other reason than that pep8
        now forbids binding of a lambda expression to a name:

        'E731 do not assign a lambda expression, use a def'
    ú\)Úendswith)Ústringr	   r	   r
   Úends_bsw   s   
rF   c                   @   s’   e Zd ZdZdZdZdZdZdZdZ	dZ
dZd	ZdZd
ZdZeeddfeeddfeeddfeeddfeeddffZg Zdd„ Zdd„ Zdd„ ZdS )ÚPlainTextReportz@Will generate a plain text report from a top_level Report objectÚ z  * %(name)sz  ! %sz  * %szLoaded Plugins:z  {name}Ú
é   z{name}zH========================================================================z-  commands executed:z-  files copied:z-  files created:z
-  alerts:z	-  notes:c                 C   s   t t |j¡ƒ| _d S r   )ÚsortedÚdictÚitemsr   Úreport_data)r   Úreport_noder	   r	   r
   r   œ   s   zPlainTextReport.__init__c              	   C   s  g  | _ }t| jƒdkr| | j¡ | | j¡ d}d}t| jƒ}| jD ]\}}|d|› �7 }|d7 }|| j dkrC||k rC|| j7 }q$|| j7 }| |¡ | jD ]$\}}| | j	¡ | |› ¡ | j
D ]\}}	}
}|  ||j|
|	|¡ qdqQt| jƒdkrƒ| | j¡ d tdd„ |ƒ¡}|S )Nr   rH   z  é   rI   c                 S   r    )Nr!   r"   r#   )Úir	   r	   r
   Ú<lambda>¼   s    z)PlainTextReport.unicode.<locals>.<lambda>)Úline_bufÚlenÚHEADERr*   ÚPLUGLISTHEADERrN   ÚPLUGLISTMAXITEMSÚPLUGLISTSEPÚPLUGLISTFOOTERÚPLUGDIVIDERÚsubsectionsÚprocess_subsectionr)   ÚFOOTERÚjoinÚmap)r   rS   ÚlinerQ   Ú	plugcountÚsection_nameÚ_Úsection_contentsÚtype_Úformat_ÚheaderÚfooterÚoutputr	   r	   r
   ÚunicodeŸ   s:   


€


ÿÿþzPlainTextReport.unicodec                 C   sd   ||v r.| j  |¡ t| |¡dd„ d�D ]
}| j  || ¡ qt|ƒdkr0| j  |¡ d S d S d S )Nc                 S   s   t | tƒr	| d S dS )Nr   rH   )r   rL   )Úxr	   r	   r
   rR   Æ   s    z4PlainTextReport.process_subsection.<locals>.<lambda>)Úkeyr   )rS   r*   rK   ÚgetrT   )r   Úsectionrl   rg   rf   rh   Úitemr	   r	   r
   r\   Á   s   
þøz"PlainTextReport.process_subsectionN)r   r   r   r   rU   r]   ÚLEAFÚALERTÚNOTErV   ÚPLUGLISTITEMrX   rW   rY   ÚPLUGINFORMATrZ   r,   r3   r9   r;   rA   r[   rS   r   rj   r\   r	   r	   r	   r
   rG   ‚   s0    




û"rG   c                   @   sv   e Zd ZdZdZdZdZdZdZdZ	dZ
dZd	Zd
ZdZdZeeddfeeddfeeddfeeddfeeddffZdS )Ú
HTMLReportz:Will generate a HTML report from a top_level Report objectaÿ  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
        <head>
            <meta http-equiv="Content-Type" content="text/html;
                  charset=utf-8" />
            <title>Sos System Report</title>
            <style type="text/css">
                td {
                    padding: 0 5px;
                   }
            </style>
        </head>
        <body>
z</body></html>z(<li><a href="%(href)s">%(name)s</a></li>z<li>%s</li>z#<h3>Loaded Plugins:</h3><table><tr>z&<td><a href="#{name}">{name}</a></td>
z
</tr>
<tr>rJ   z</tr></table>z+<h2 id="{name}">Plugin <em>{name}</em></h2>z<hr/>
z<p>Commands executed:</p><ul>z</ul>z<p>Files copied:</p><ul>z<p>Files created:</p><ul>z<p>Alerts:</p><ul>z<p>Notes:</p><ul>N)r   r   r   r   rU   r]   rp   rq   rr   rV   rs   rX   rW   rY   rt   rZ   r,   r3   r9   r;   rA   r[   r	   r	   r	   r
   ru   Í   s(    




ûru   c                   @   r+   )Ú
JSONReportz:Will generate a JSON report from a top_level Report objectc                 C   s   t j| jddd�}|S )Né   F)ÚindentÚensure_ascii)r   r   rN   )r   ri   r	   r	   r
   rj   ö   s   zJSONReport.unicodeN)r   r   r   r   rj   r	   r	   r	   r
   rv   ó   s    rv   )r   r   ÚImportErrorÚ
simplejsonÚobjectr   r   r   r'   r   r,   r3   r9   r;   rA   rF   rG   ru   rv   r	   r	   r	   r
   Ú<module>   s(   ÿ
		K&