%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/NvidiaDetector/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/NvidiaDetector/__pycache__/nvidiadetector.cpython-312.pyc

�

-.�fD��h�dZddlZddlmZmZddlZddlZddlZdZGd�de	�Z
Gd�de�Zy)	z* Detection tool for nVidia graphics cards �N)�Popen�PIPEz)/usr/share/ubuntu-drivers-common/obsoletec��eZdZdZy)�NoDatadirErrorz4Exception thrown when no modaliases dir can be foundN)�__name__�
__module__�__qualname__�__doc__���?/usr/lib/python3/dist-packages/NvidiaDetector/nvidiadetector.pyrr"s��:rrc�`�eZdZdZddefd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zy)�NvidiaDetectiona
    A simple class to:
      * Detect the available graphics cards
      * See what drivers support them (If they are
        NVIDIA cards). If more than one card is
        available, try to find the highest common
        driver version which supports them all.
        (READ the comments in the code for further
        details)
      * Return the recommended driver version
    Nc�6�ddi|_||_||_|j|�|_|j�|j
�|j�|j�|r|j�yt|j��y)a�
        printonly = if set to None will make an instance
                    of this class return the selected
                    driver.
                    If set to True it won't return
                    anything. It will simply and print
                    the choice.

        verbose   = if set to True will make the methods
                    print what is happening.
        �currenti�N)� _NvidiaDetection__driver_aliases�	printonly�verbose�getObsoletePackages�oldPackages�	detection�getData�getCards�removeUnsupported�printSelection�print�selectDriver)�selfrr�obsoletes    r
�__init__zNvidiaDetection.__init__3sz�� "+�D� 1���"�������3�3�H�=������������
�
����� �����!��$�#�#�%�&rc�Z�|jj�D]\}}||k(s�|cSy)z7Get the name of a driver from its corresponding integerN)r�items)r�value�k�vs    r
�__get_name_from_valuez%NvidiaDetection.__get_name_from_valueQs5���)�)�/�/�1�	�D�A�q��E�z���	�rc��|jj|�}|�7|jd�rt|j	dd��}t|�}|S)z2Get the integer associated to the name of a driverz-server�)r�get�endswith�int�replace)r�namer%s   r
�__get_value_from_namez%NvidiaDetection.__get_value_from_nameXsL���!�!�%�%�d�+���9��}�}�Y�'�����Y��3�4���D�	�A��rc���g}	t|�j�D�cgc]}|j���}}|D�cgc]
}|dk7s�	|��}}|Scc}wcc}w#t$rY|SwxYw)z.Read the list of obsolete packages from a filer()�open�	readlines�strip�IOError)rr�tempList�xs    r
rz#NvidiaDetection.getObsoletePackagesasr����	�+/��>�+C�+C�+E�F�a����	�F�H�F�#+�7�a�q�B�w��7�H�7����	G��7���	����	�s2�A�A�A�
A�A�A�
A�	A&�%A&c�(�g|_tddgtd��}|j�dj	d�}tjd�}tjd�}|D�]%}|j|�}|j|�}|r~|jd	�j�j�}|jd
�j�j�}	|dz|	z}
|jj|
���|s��|jd	�j�j�}|jd
�j�j�}	|dz|	z}
|jj|
���(y)
z^
        Detect the models of the graphics cards
        and store them in self.cards
        �lspciz-nT��stdout�universal_newlinesr�
z6.*03(80|0[0-2]): *(?P<vendor>.+):(?P<device>.+) \(.+\)z/.*03(80|0[0-2]): *(?P<vendor>.+):(?P<device>.+)�vendor�device�:N)�cardsrr�communicate�split�re�compile�match�groupr2�lower�append)r�p1�p�indentifier1�indentifier2�line�m1�m2�id1�id2�ids           r
rzNvidiaDetection.detectionksL��
��
�
�G�T�?�4�D�
I���N�N��Q��%�%�d�+���z�z�"[�\���z�z�"T�U���	&�D��#�#�D�)�B��#�#�D�)�B���h�h�x�(�.�.�0�6�6�8���h�h�x�(�.�.�0�6�6�8���3�Y��_���
�
�!�!�"�%���h�h�x�(�.�.�0�6�6�8���h�h�x�(�.�.�0�6�6�8���3�Y��_���
�
�!�!�"�%�	&rc�D�i|_tjd�}tjd�}tj�D�]�}|j
j
d�r*d|j
vsd|j
vsd|j
vr�J	|jjd}|j|j
�}|r|jd�}n#tjd	|j
z���|j|�}	|r�||j!d
�dzdj#dd
�}|j%d�D]�}|j|j'��}	|	s&tjd|j
�d|����J|	jd�j)�}
|	jd�j)�}|jj+|g�j-|
dz|z������t1|jj3��dk(r*t4j6j9�t;d�yy#ttf$rY��#wxYw#t.$r)tjd|j
�d|���Y��XwxYw)zi
        Get the data from the modaliases for each driver
        and store them in self.drivers
        zpci:v0000(.+)d0000(.+)svz5nvidia(?:\-driver|)\-([0-9]+)(:?\-server|)(:?\:i386|)�nvidia-�updates�experimentalr�
Modaliases�z/%s package has unexpected name scheme. Skipping�(N�)r(�,zPackage z has unexpected modalias: �r>z has invalid modalias header: r�none)�driversrBrC�apt�Cacher-�
startswith�	candidate�record�KeyError�AttributeErrorrDrE�logging�error�%_NvidiaDetection__get_value_from_name�findr,rA�lstriprF�
setdefaultrG�
ValueError�len�keys�sysr9�flushr)r�vendor_product_re�
package_re�package�m�
package_match�stripped_package_name�driver_version�alias�vpr<�products            r
rzNvidiaDetection.getData�s?��
����J�J�'A�B���Z�Z� X�Y�
��y�y�{�*	&�G��L�L�+�+�I�6�����-�"�g�l�l�2�����-��
��%�%�,�,�\�:��'�,�,�W�\�\�:�M��(5�(;�(;�A�(>�%��
�
�O��L�L�"�#��!�7�7�8M�N�N�
&���1�6�6�#�;�q�=�*�+�3�3�C��<�A�!"�����
8��.�4�4�U�\�\�^�D��!�#�M�M� '���e�+5�6�$�!#���!��!2�!2�!4��"$�(�(�1�+�"3�"3�"5�����/�/���C�J�J� &���w� 6�8�
8��;*	&�\�t�|�|� � �"�#�q�(��J�J�����&�M�)��M�n�-�
��	
��@�
&��
�
��L�L�!�%�&�
&�s%�I�C5I-�I*�)I*�-.J�Jc�z�i|_g|_	|jD]R}|d|jd�dk(s�|jrtd|zdz�|jj
|��Tt|jd��|_		|jD]�}d}|jD]^}||j|vs�d}|jrtd	|�d
|���|jj|g�j
|��`|r�u|jj|g�j
d���y)z�
        See if the detected graphics cards are NVIDIA cards.
        If they are NVIDIA cards, append them to self.nvidiaCards
        rr>�10dezNVIDIA card found (rYT��reverseFzCard z supported by driver N)�driversForCards�nvidiaCardsr?rhrrrG�sortedr]�orderedListrj)r�card�	supported�drivers    r
rzNvidiaDetection.getCards�s3��
 "������		��J�J�	.�D��A�t�y�y��~�&�&�0��<�<��/�$�6��<�=�� � �'�'��-�		.�"�$�,�,��=���	��$�$�		G�D��I��*�*�
M���4�<�<��/�/� $�I��|�|��$��O�P��(�(�3�3�D�"�=�D�D�V�L�
M���$�$�/�/��b�9�@�@��F�		Grc��g}|jD]%}d|j|vs�|j|��'|D]D}|jrtd|z�|jj|�|j|=�Fy)zf
        Remove unsupported cards from self.nvidiaCards and from
        self.driversForCards
        NzRemoving unsupported card )r~rGrrr�remove)r�unsupportedCardsr��unsupporteds    r
rz!NvidiaDetection.removeUnsupported�s���
���(�(�	.�D��t�+�+�D�1�1� �'�'��-�	.�,�	2�K��|�|��2�[�@�A����#�#�K�0��$�$�[�1�		2rc��t|j�}|dkD�r�|dkDr�	i}|jD]5}|j|D]!}|j|d�||xxdz
cc<�#�7t	|d��}	g}|D]}|||k(s�|j|��t|�dkDr?	|j
d��|d}|jr�|js�td|z�n�	|d}|jrx|jsltd|z�n]	|jt|jj��dd}|jr|jstd|z�	|j|�}	|	�|dk\xrd	xsd
t|	�z}|S|dk\xrd	xsd
t|�z}|S	|jrtd�d}|S)zZ
        If more than one card is available, try to get the highest common driver
        rrWTr|zRecommended NVIDIA driver: zRecommended NVIDIA driver: %dNi�znvidia-driver-rSzNo NVIDIA package to install)rlrr~rjr�rG�sortrrr�listrm�%_NvidiaDetection__get_name_from_value�str)
r�cardsNumber�
occurrencer��drv�occurrences�
candidatesr��choice�driver_names
          r
rzNvidiaDetection.selectDrivers���$�*�*�+����?��Q��� �
� �0�0�-�D�#�3�3�D�9�-��"�-�-�c�1�5�"�3��1�,��-�-�
%�Z��>��� �
�)�2�F�!�&�)�[�8�"�)�)�&�1�2��z�?�Q�&���O�O�D�O�1�'��]�F��|�|�D�N�N��;�f�D�E�
�)��^�F��|�|�D�N�N��;�f�D�E��
�-�-�d�4�3G�3G�3L�3L�3N�.O�PQ�.R�S�TU�V���<�<�����9�F�B�C�
��4�4�V�<�K��&� �C�-�<�,<�I�	�S�Q\�M]�]���
�!�C�-�<�,<�I�	�S�QW�[�X���
�
��|�|��4�5��F��
rc��	g}g}tddgtd��}|j�d}|jd�}|D]:}|j	d�dk7s�|j|jd	�d��<t
|t�r	|j|�r	|S|D]}	|j|�r	�|S#t$r|j|�Y|SwxYw#t$r|j|�Y�WwxYw)
z�
        USAGE:
            * pkglist is the list of packages  you want to check
            * use lists for one or more packages
            * use a string if it is only one package
            * lists will work well in both cases
        �dpkgz--get-selectionsTr8rr;z	install����	)
rrr@rArhrG�
isinstancer��indexrk)	r�pkglist�lines�notinstalledrHrI�crL�pkgs	         r
�checkpkgzNvidiaDetection.checkpkgds��	�����
�F�.�/��QU�
V���N�N��Q���
�G�G�D�M���	2�D��y�y��%��+����T�Z�Z��-�a�0�1�	2��g�s�#�
-��;�;�w�'�����
-��-��{�{�3�'���
-�����
-��#�#�G�,���
-��"�-� �'�'��,�-�s$�B>�(C�>C�C�C<�;C<c�z�|j|j�}t|�t|j�k7S)z�
        oldPackages = a list of the names of the obsolete drivers
        notInstalled = a list of the obsolete drivers which are not
                       installed
        )r�rrl)r�notInstalleds  r
�
getDriverszNvidiaDetection.getDrivers�s5���}�}�T�%5�%5�6���L�!�S��)9�)9�%:�:�;rc�B�|j�}|j�rV|r*tjj	�t|�ytjj	�td�ytjj	�t|�y)z6
        Part for the kernel postinst.d/ hook
        r\N)rr�rnr9ror)rr�s  r
rzNvidiaDetection.printSelection�sf���"�"�$���?�?����
�
� � �"��f�
��
�
� � �"��f�
�
�J�J�����&�Mr)rrr	r
�obsoletePackagesPathr r�rgrrrrrrr�r�rrrr
rr&sT��
�"&�t�>R�'�<���&�B9�x,G�\2� \�|"�H<� rr)
r
rB�
subprocessrrrnrer^r��	Exceptionr�objectrrrr
�<module>r�s;��1�,
�"�
��
�B��;�Y�;�A�f�Ar

Zerion Mini Shell 1.0