o
    idS                     @   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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      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
   _decode3   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   @   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   C   s
   
zSection.addNr   r	   r	   r	   r
   r   8   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   M   s   zCommand.__init__Nr   r   r   r)   r   r	   r	   r	   r
   r,   I       r,   c                   @   r+   )
CopiedFilecopied_filesc                 C      t |t |d| _d S N)r   r/   r0   r   r   r/   r	   r	   r
   r   W      zCopiedFile.__init__Nr1   r	   r	   r	   r
   r3   S   r2   r3   c                   @   r+   )CreatedFilecreated_filesc                 C   r5   r6   r0   r7   r	   r	   r
   r   `   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   i      zAlert.__init__Nr1   r	   r	   r	   r
   r;   e   r2   r;   c                   @   r+   )Notenotesc                 C   r=   r   r0   r>   r	   r	   r
   r   q   r@   zNote.__init__Nr1   r	   r	   r	   r
   rA   m   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_bsu   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 ]!\}}|| jj|d7 }|d7 }|| j dkrE||k rE|| j	7 }q$|| j
7 }|| | jD ](\}}|| j || jj|d | jD ]\}}	}
}| ||j|
|	| qjqSt| jdkr|| j dtdd |}|S )Nr   rH   )r      rI   c                 S   r    )Nr!   r"   r#   )ir	   r	   r
   <lambda>   s    z)PlainTextReport.unicode.<locals>.<lambda>)line_buflenHEADERr*   PLUGLISTHEADERrN   PLUGLISTITEMformatPLUGLISTMAXITEMSPLUGLISTSEPPLUGLISTFOOTERPLUGDIVIDERPLUGINFORMAT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   sectionro   rj   ri   rk   itemr	   r	   r
   r_      s   
z"PlainTextReport.process_subsectionN)r   r   r   r   rU   r`   LEAFALERTNOTErV   rW   rZ   rY   r[   r]   r\   r,   r3   r9   r;   rA   r^   rS   r   rm   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`   rs   rt   ru   rV   rW   rZ   rY   r[   r]   r\   r,   r3   r9   r;   rA   r^   r	   r	   r	   r
   rv      s(    




rv   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   rl   r	   r	   r
   rm      s   zJSONReport.unicodeN)r   r   r   r   rm   r	   r	   r	   r
   rw      s    rw   )r   r   ImportError
simplejsonobjectr   r   r   r'   r   r,   r3   r9   r;   rA   rF   rG   rv   rw   r	   r	   r	   r
   <module>   s(   	
		K&