Ë
    ¸~Þeù&  ã                   ó„   — d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ  G d„ de
«      Z	 	 	 	 	 	 	 d
d	„Zy)é    N)Ú	getLogger)ÚFailure)Úlog_failure)ÚPluginRegistry)Úgather_resultsc                   óX   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zˆ xZS )ÚSysInfoPluginRegistryaG  
    When the sysinfo plugin registry is run, it will run each of the
    registered plugins so that they get a chance to feed information
    into the registry.

    There are three kinds of details collected: headers, notes, and footnotes.

    They are presented to the user in a way similar to the following:

        Header1: Value1   Header3: Value3
        Header2: Value2   Header4: Value4

        => This is first note
        => This is the second note

        The first footnote.
        The second footnote.

    Headers are supposed to display information which is regularly
    available, such as the load and temperature of the system.  Notes
    contain eventual information, such as warnings of high temperatures,
    and low disk space.  Finally, footnotes contain pointers to further
    information such as URLs.
    c                 óh   •— t         ‰| �  «        i | _        g | _        g | _        g | _        d| _        y )NF)ÚsuperÚ__init__Ú_header_indexÚ_headersÚ_notesÚ
_footnotesÚ_plugin_error)ÚselfÚ	__class__s    €ú;/usr/lib/python3/dist-packages/landscape/sysinfo/sysinfo.pyr   zSysInfoPluginRegistry.__init__'   s3   ø€ Ü‰ÑÔØˆÔØˆŒØˆŒØˆŒØ"ˆÕó    c                 ó"  — | j                   j                  |«      }|€@t        | j                  «      | j                   |<   | j                  j	                  ||f«       y|dz  }|| j                   |<   | j                  j                  |||f«       y)aj  Add a new information header to be displayed to the user.

        Header names can be repeated.

        Headers with value None are not returned by get_headers(), but
        they still allocate a position in the list.  This fact may be
        explored to create a deterministic ordering even when dealing
        with values obtained asynchornously.
        Né   )r   ÚgetÚlenr   ÚappendÚinsert)r   ÚnameÚvalueÚindexs       r   Ú
add_headerz SysInfoPluginRegistry.add_header/   s   € ð ×"Ñ"×&Ñ& tÓ,ˆØˆ=Ü'*¨4¯=©=Ó'9ˆD×Ñ˜tÑ$Ø�M‰M× Ñ  $¨ Õ/à�Q‰JˆEØ',ˆD×Ñ˜tÑ$Ø�M‰M× Ñ  ¨¨u¨Õ6r   c                 óL   — | j                   D �cg c]
  }|d   €Œ	|‘Œ c}S c c}w )z›Get all information headers to be displayed to the user.

        Headers which were added with value None are not included in
        the result.
        r   )r   )r   Úpairs     r   Úget_headersz!SysInfoPluginRegistry.get_headersB   s%   € ð "&§¡ÖF˜°$°q±'Ñ2E’ÒFÐFùÒFs   �
!š!c                 ó:   — | j                   j                  |«       y)z<Add a new eventual note to be shown up to the administrator.N)r   r   ©r   Únotes     r   Úadd_notezSysInfoPluginRegistry.add_noteJ   s   € à�‰×Ñ˜4Õ r   c                 ó   — | j                   S )z;Get all eventual notes to be shown up to the administrator.)r   ©r   s    r   Ú	get_noteszSysInfoPluginRegistry.get_notesN   s   € à�{‰{Ðr   c                 ó:   — | j                   j                  |«       y)z7Add a new footnote to be shown up to the administrator.N)r   r   r$   s     r   Úadd_footnotez"SysInfoPluginRegistry.add_footnoteR   s   € à�‰×Ñ˜tÕ$r   c                 ó   — | j                   S )z6Get all footnotes to be shown up to the administrator.)r   r(   s    r   Úget_footnotesz#SysInfoPluginRegistry.get_footnotesV   s   € à�‰Ðr   c                 óF  — g }| j                  «       D ]@  }	 |j                  «       }|j                  | j                  |«       |j	                  |«       ŒB t        |«      j                  | j                  «      S # t
        $ r | j                  t        «       |«       Y ŒŒw xY w)zÞRun all plugins, and return a deferred aggregating their results.

        This will call the run() method on each of the registered plugins,
        and return a deferred which aggregates each resulting deferred.
        )
Úget_pluginsÚrunÚ
addErrbackÚ_log_plugin_errorr   Ú	Exceptionr   r   ÚaddCallbackÚ_report_error_note)r   Ú	deferredsÚpluginÚresults       r   r0   zSysInfoPluginRegistry.runZ   s˜   € ð ˆ	Ø×&Ñ&Ó(ò 	)ˆFð)ØŸ™›�ð ×!Ñ! $×"8Ñ"8¸&ÔAØ× Ñ  Õ(ð	)ô ˜iÓ(×4Ñ4°T×5LÑ5LÓMÐMøô ò :Ø×&Ñ&¤w£y°&Ö9ð:ús   —A:Á:#B ÂB c                 óv   — d| _         |j                  j                  › d�}t        d«      }t	        |||¬«       y )NTz plugin raised an exception.zlandscape-sysinfo)Úlogger)r   r   Ú__name__r   r   )r   Úfailurer7   Úmessager:   s        r   r2   z'SysInfoPluginRegistry._log_plugin_errork   s;   € Ø!ˆÔØ×%Ñ%×.Ñ.Ð/Ð/KÐLˆÜÐ.Ó/ˆÜ�G˜W¨VÖ4r   c                 óž   — ddl m} | j                  r:t        j                  j                   |«       d«      }| j                  d|› d�«       |S )Nr   )Úget_landscape_log_directoryzsysinfo.logz@There were exceptions while processing one or more plugins. See z for more information.)Úlandscape.sysinfo.deploymentr?   r   ÚosÚpathÚjoinr&   )r   r8   r?   rB   s       r   r5   z(SysInfoPluginRegistry._report_error_noteq   sK   € ÝLà×ÒÜ—7‘7—<‘<Ñ ;Ó =¸}ÓMˆDØ�M‰MðØ�fÐ2ð4ôð ˆr   )r;   Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r&   r)   r+   r-   r0   r2   r5   Ú__classcell__)r   s   @r   r	   r	      s<   ø„ ñô2#ò7ò&Gò!òò%òòNò"5ö	r   r	   c                 ó&  ‡— |t        ‰«      z  }t        | «      }d}|}	| D ])  \  }
}t        |	t        |
«      t        |«      z   dz   «      }	Œ+ t        t        j                  t        |«      |	t        |«      z   z  «      «      }	 t        t        j                  |t        |«      z  «      «      }g }d}t        |«      D ]�  }d}d}t        |«      D ]B  }||z  |z   }||k  sŒ| |   \  }
}t        |t        |
«      «      }t        |t        |«      «      }ŒD |dkD  r|t        |«      z  }|||z   t        |«      z   z  }|j                  ||f«       Œ’ |dk(  s||k  rn|dz  }ŒÝg }t        |«      D ]�  }‰}t        |«      D ]j  }||z  |z   }||k  sŒ| |   \  }
}||   \  }}|dkD  r||z  }||
|z   d|t        |
«      z
  z  z   |z   z  }||dz   |z  |z   kD  sŒW|d|t        |«      z
  z  z  }Œl |j                  |«       Œ� |rS|r|j                  d«       ‰|z   }|D ]6  }|j                  t        j                  ||dt        |«      z  |¬«      «       Œ8 |r-|r|j                  d«       |j                  ˆfd„|D «       «       d	j                  |«      S )
aè  Format sysinfo headers, notes and footnotes to be displayed.

    This function will format headers notes and footnotes in a way that
    looks similar to the following:

        Header1: Value1   Header3: Value3
        Header2: Value2   Header4: Value4

        => This is first note
        => This is the second note

        The first footnote.
        The second footnote.

    Header columns will be dynamically adjusted to conform to the size
    of header labels and values.
    z: é   r   r   ú Ú )Úinitial_indentÚsubsequent_indentÚwidthc              3   ó(   •K  — | ]	  }‰|z   –— Œ y ­w)N© )Ú.0ÚfootnoteÚindents     €r   ú	<genexpr>z!format_sysinfo.<locals>.<genexpr>  s   øè ø€ ÒA¨8�V˜hÕ&ÑAùs   ƒú
)r   ÚminÚintÚmathÚceilÚfloatÚrangeÚmaxr   ÚextendÚtextwrapÚwraprC   )ÚheadersÚnotesÚ	footnotesrN   rS   Úcolumn_separatorÚnote_prefixÚheaders_lenÚvalue_separatorÚ
min_lengthÚheaderr   ÚcolumnsÚheaders_per_columnÚheader_lengthsÚtotal_lengthÚcolumnÚwidest_header_lenÚwidest_value_lenÚrowÚheader_indexÚlinesÚlinerL   r%   s       `                    r   Úformat_sysinfort   }   s:  ø€ ð8 
ŒS�‹[Ñ€Eä�g“,€KØ€Oð
 €JØ ò 
‰ˆ�ÜØÜ�‹Kœ#˜e›*Ñ$ qÑ(ó
‰
ð
ô
 Ü�	‰	”%˜“, *¬sÐ3CÓ/DÑ"DÑEÓFó€Gð ô !¤§¡¨;¼¸w»Ñ+GÓ!HÓIÐØˆØˆÜ˜G“nò 	IˆFð !"ÐØ ÐÜÐ/Ó0ò I�Ø%Ð(:Ñ:¸SÑ@�ð   +Ó-Ø$+¨LÑ$9‘M�F˜EÜ(+Ð,=¼sÀ6»{Ó(KÐ%Ü'*Ð+;¼SÀ»ZÓ'HÑ$ðIð ˜Šzà¤Ð$4Ó 5Ñ5�àØ!Ð$4Ñ4´s¸?Ó7KÑKñˆLð
 ×!Ñ!Ð#4Ð6FÐ"GÕHð1	Ið4 �aŠ<˜<¨%Ò/ð ð 	�1‰ˆðY ð^ €EÜÐ'Ó(ò ˆØˆô
 ˜G“nò 	BˆFØ!Ð$6Ñ6¸Ñ<ˆLð ˜kÓ)Ø '¨Ñ 5‘�˜à6DÀVÑ6LÑ3Ð!Ð#3Ø˜A’:àÐ,Ñ,�DàØØ%ñ&àÐ.´°V³Ñ<Ñ=ñ>ð ññ�ð  &¨1¡*Ð0BÑ!BÀSÑ!HÓHØ˜CÐ#3´c¸%³jÑ#@ÑAÑA‘Dð+	Bð, 	�‰�TÕð9ñ< Ùà�L‰L˜ÔØ +Ñ-ˆØò 	ˆDØ�L‰LÜ—‘ØØ#1Ø&)¬C°Ó,?Ñ&?Øô	õð	ñ ÙØ�L‰L˜ÔØ�‰ÓA°yÔAÔAà�9‰9�UÓÐr   )rP   rP   rP   éP   rK   z   z=> )rX   rA   r^   Úloggingr   Útwisted.python.failurer   Úlandscape.lib.logr   Úlandscape.lib.pluginr   Úlandscape.lib.twisted_utilr   r	   rt   rP   r   r   ú<module>r{      sI   ðÛ Û 	Û Ý å *å )Ý /Ý 5ôm˜Nô mðb Ø
ØØ
ØØØôUr   