HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/landscape/sysinfo/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/landscape/sysinfo/__pycache__/sysinfo.cpython-312.pyc
�

�~�e�&���ddlZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZGd�de
�Z
							d
d	�Zy)�N)�	getLogger)�Failure)�log_failure)�PluginRegistry)�gather_resultsc�X��eZdZdZ�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
�xZS)�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zSysInfoPluginRegistry.__init__'s3���
���������
�������"���c�"�|jj|�}|�@t|j�|j|<|jj	||f�y|dz
}||j|<|jj|||f�y)ajAdd 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�
�6rc�L�|jD�cgc]
}|d��	|��c}Scc}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_headersBs%��"&���F��$�q�'�2E��F�F��Fs�
!�!c�:�|jj|�y)z<Add a new eventual note to be shown up to the administrator.N)rr�r�notes  r�add_notezSysInfoPluginRegistry.add_noteJs�������4� rc��|jS)z;Get all eventual notes to be shown up to the administrator.)r�rs r�	get_noteszSysInfoPluginRegistry.get_notesNs���{�{�rc�:�|jj|�y)z7Add a new footnote to be shown up to the administrator.N)rrr$s  r�add_footnotez"SysInfoPluginRegistry.add_footnoteRs�������t�$rc��|jS)z6Get all footnotes to be shown up to the administrator.)rr(s r�
get_footnotesz#SysInfoPluginRegistry.get_footnotesVs�����rc�F�g}|j�D]@}	|j�}|j|j|�|j	|��Bt|�j|j�S#t
$r|jt
�|�Y��wxYw)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�	Exceptionrr�addCallback�_report_error_note)r�	deferreds�plugin�results    rr0zSysInfoPluginRegistry.runZs����	��&�&�(�	)�F�
)�������!�!�$�"8�"8�&�A�� � ��(�	)��i�(�4�4�T�5L�5L�M�M���
:��&�&�w�y�&�9�
:�s�A:�:#B �B c�v�d|_|jj�d�}td�}t	|||��y)NTz plugin raised an exception.zlandscape-sysinfo)�logger)rr�__name__rr)r�failurer7�messager:s     rr2z'SysInfoPluginRegistry._log_plugin_errorks;��!����%�%�.�.�/�/K�L���.�/���G�W�V�4rc��ddlm}|jr:tjj|�d�}|j
d|�d��|S)Nr)�get_landscape_log_directoryzsysinfo.logz@There were exceptions while processing one or more plugins. See z for more information.)�landscape.sysinfo.deploymentr?r�os�path�joinr&)rr8r?rBs    rr5z(SysInfoPluginRegistry._report_error_noteqsK��L�����7�7�<�<� ;� =�}�M�D��M�M���f�2�4�
��
r)r;�
__module__�__qualname__�__doc__rrr"r&r)r+r-r0r2r5�
__classcell__)rs@rr	r	
s<����2#�7�&G�!��%��N�"5�	rr	c�&��|t��z}t|�}d}|}	|D])\}
}t|	t|
�t|�zdz�}	�+ttjt|�|	t|�zz��}	ttj|t|�z��}
g}d}t
|�D]�}d}d}t
|
�D]B}||
z|z}||ks�||\}
}t|t|
��}t|t|��}�D|dkDr|t|�z
}|||zt|�zz
}|j||f���|dk(s||krn|dz}��g}t
|
�D]�}�}t
|�D]j}||
z|z}||ks�||\}
}||\}}|dkDr||z
}||
|zd|t|
�z
zz|zz
}||dz|
z|zkDs�W|d|t|�z
zz
}�l|j|���|rS|r|jd��|z}|D]6}|jtj||dt|�z|����8|r-|r|jd�|j�fd�|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: �rr� �)�initial_indent�subsequent_indent�widthc3�(�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�	footnotesrNrS�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�linerLr%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)rPrPrP�PrKz   z=> )rXrAr^�loggingr�twisted.python.failurer�landscape.lib.logr�landscape.lib.pluginr�landscape.lib.twisted_utilrr	rtrPrr�<module>r{sI���	���*�)�/�5�m�N�m�b
�
��
�
���Ur