o
    *bS                     @   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   Z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 )CommandZ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*   )
CopiedFileZcopied_filesc                 C      t |t |d| _d S N)r   r-   r.   r   r   r-   r	   r	   r
   r   W      zCopiedFile.__init__Nr/   r	   r	   r	   r
   r1   S   r0   r1   c                   @   r*   )CreatedFileZcreated_filesc                 C   r2   r3   r.   r4   r	   r	   r
   r   `   r5   zCreatedFile.__init__Nr/   r	   r	   r	   r
   r6   \   r0   r6   c                   @   r*   )AlertZalertsc                 C      t || _d S r   r.   r   Zcontentr	   r	   r
   r   i      zAlert.__init__Nr/   r	   r	   r	   r
   r7   e   r0   r7   c                   @   r*   )NoteZnotesc                 C   r8   r   r.   r9   r	   r	   r
   r   q   r:   zNote.__init__Nr/   r	   r	   r	   r
   r;   m   r0   r;   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   
r?   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   Z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   rA   )r      rB   c                 S   r   )Nr    r!   r"   )ir	   r	   r
   <lambda>   s    z)PlainTextReport.unicode.<locals>.<lambda>)line_buflenHEADERr)   PLUGLISTHEADERrG   PLUGLISTITEMformatPLUGLISTMAXITEMSPLUGLISTSEPPLUGLISTFOOTERPLUGDIVIDERPLUGINFORMATsubsectionsprocess_subsectionr(   FOOTERjoinmap)r   rK   linerI   Z	plugcountZsection_name_Zsection_contentsZ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   rA   )r   rE   )xr	   r	   r
   rJ      s    z4PlainTextReport.process_subsection.<locals>.<lambda>)keyr   )rK   r)   rD   getrL   )r   sectionrc   r^   r]   r_   itemr	   r	   r
   rW      s   
z"PlainTextReport.process_subsectionN)r   r   r   r   rM   rX   LEAFALERTNOTErN   rO   rR   rQ   rS   rU   rT   r+   r1   r6   r7   r;   rV   rK   r   ra   rW   r	   r	   r	   r
   r@      s0    




"r@   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>rC   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   rM   rX   rg   rh   ri   rN   rO   rR   rQ   rS   rU   rT   r+   r1   r6   r7   r;   rV   r	   r	   r	   r
   rj      s(    




rj   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)indentZensure_ascii)r   r   rG   )r   r`   r	   r	   r
   ra      s   zJSONReport.unicodeN)r   r   r   r   ra   r	   r	   r	   r
   rk      s    rk   )r   r   ImportErrorZ
simplejsonobjectr   r   r   r&   r   r+   r1   r6   r7   r;   r?   r@   rj   rk   r	   r	   r	   r
   <module>   s(   	
		K&