403Webshell
Server IP : 178.105.222.151  /  Your IP : 216.73.216.38
Web Server : nginx/1.28.3
System : Linux MNK 7.0.0-15-generic #15-Ubuntu SMP PREEMPT_DYNAMIC Wed Apr 22 16:06:43 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.5.4
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/UbuntuDrivers/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/UbuntuDrivers/__pycache__/detect.cpython-314.pyc
+
�w�i�_���Rt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIH	t	H
t
HtHtH
t
HtHt^RIHt^RIt^RIHt!RR]RR7t!R	R
]RR7t!RR]RR7tR
s/tRt!RR]4tRRltR�RRlltRRltRRltRRlt RRlt!R�RRllt"RR lt#R!R"lt$R#R$lt%R%R&lt&R'R(lt'R)R*lt(R+R,lt)R-R.lt*R/R0lt+R1R2lt,R3R4lt-R5R6lt.R�R7R8llt/R9R:lt0R;R<lt1R=R>lt2R�R?R@llt3R�RARBllt4R�RCRDllt5RERFlt6R�RGRHllt7RIRJlt8RKRLlt9!RMRN]4t:RORPlt;R�RQRRllt<R�RSRTllt=RURVlt>R�RWRXllt?R�RYRZllt@R�R[R\lltAR�R]R^lltBR_R`ltCRaRbltDRcRdltEReRfltFRgRhltGRiRjltHRkRlltIRmRnltJRoRpltKRqRrltLRsRtltMRuRvltNRwRxltOR�RyRzlltPR{R|ltQR}R~ltRRR�ltSR�R�ltTR�R�ltUR�R�ltVR#)�zGHardware and driver package detection functionality for Ubuntu systems.N)�Optional�Dict�List�Set�Tuple�Any�	TypedDict)�
cmp_to_key)�kerneldetectionc�0a�]tRt^toRtV3RltRtVtR#)�
DriverInfoz2Type definition for individual driver information.c�J<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&#)��free�builtin�from_distro�recommended��bool)�format�
__classdict__s"��6/usr/lib/python3/dist-packages/UbuntuDrivers/detect.py�__annotate__�DriverInfo.__annotate__s7�����J���M�	�
�����
��N��__name__�
__module__�__qualname__�__firstlineno__�__doc__�__annotate_func__�__static_attributes__�__classdictcell__�rs@rrrs����<��rrF)�totalc�0a�]tRt^#toRtV3RltRtVtR#)�
DeviceInfoz?Type definition for device information with associated drivers.c�l<�V^8�dQh/S[;R&S[;R&S[;R&S[S[S[3,;R&S[;R&#)r�modalias�vendor�model�drivers�manual_install)�strrrr)rrs"�rr�DeviceInfo.__annotate__#sL�����M��
�K�	�
�J���#�z�/�
"�"�
���rrNrr%s@rr(r(#s����I��rr(c�0a�]tRt^-toRtV3RltRtVtR#)�PackageInfoz<Type definition for driver package information dictionaries.c�<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&S[;R&S[;R&S[;R&S[;R&S[S[,;R	&S[;R
&S[;R&#)rr*�syspath�pluginrrr+r,r�support�open_preferred�metapackage)r/rr)rrs"�rr�PackageInfo.__annotate__-s������M���L�	�

�K���J�
����
�K���J������c�]��������rrNrr%s@rr2r2-s����F��rr2�z/etc/custom_supported_gpus.jsonc�a�]tRt^BtoRtV3RlRltV3RlRltV3RlRltV3RlR	ltV3R
lRlt	V3RlR
lt
V3RlRltRtVt
R#)�NvidiaPkgNameInfoz%Class to process NVIDIA package namesc�$<�V^8�dQhRS[RR/#)r�pkg_name�returnN�r/)rrs"�rr�NvidiaPkgNameInfo.__annotate__Es���+�+��+��+rc��WnRVnRVnRVnRVnRVnRVnVPVP4R#)Fr:N���)�	_pkg_name�_obsolete_name_scheme�_server�_open�
_major_ver�_flavour�is_valid�
_process_name)�selfr>s&&r�__init__�NvidiaPkgNameInfo.__init__EsD��!��%*��"������
������
���
����4�>�>�*rc�$<�V^8�dQhRS[RR/#)r�namer?Nr@)rrs"�rrrAOs���.!�.!�#�.!�$�.!rc���RV9d\P!RV4R#\P!R4pVP	V4pV'dJRVn\
VP^44Vn\VP4Vn
RVnR#\P!R4pVP	V4pV'd�VP^4PR4R
8gVn
VP^4PR4R
8gVnVP^4:VP'dRMR:VP'dRMR:2Vn
\
VP^44VnRVn\P!R	4pVP	V4pV'd�VP^4PR4R
8gVn
VP^4PR4R
8gVnVP^4:VP'dRMR:VP'dRMR:2Vn
\
VP^44VnRVnR#R#)�nvidiaz8NvidiaPkgNameInfo: %s is not an NVIDIA package. SkippingNznvidia-([0-9]+)T�nvidia-driver-([0-9]+)(.*)z-serverz-openr:z nvidia-headless(.*)-([0-9]+)(.*)rC)�logging�debug�re�compile�matchrE�int�grouprHr/rIrJ�findrFrG)rLrP�patternrXs&&  rrK�NvidiaPkgNameInfo._process_nameOs����4���M�M�J�D�
�
��*�*�.�/���
�
�d�#���)-�D�&�!�%�+�+�a�.�1�D�O�����0�D�M� �D�M���*�*�9�:���
�
�d�#��� �;�;�q�>�.�.�y�9�R�?�D�L����Q��,�,�W�5��;�D�J����A��!�\�\�\�	�r�1��:�:�:��2�-��D�M�
"�%�+�+�a�.�1�D�O� �D�M��*�*�?�@���
�
�d�#��� �;�;�q�>�.�.�y�9�R�?�D�L����Q��,�,�W�5��;�D�J����A��!�\�\�\�	�r�1��:�:�:��2�-��D�M�
"�%�+�+�a�.�1�D�O� �D�M�rc� <�V^8�dQhRS[/#�rr?r)rrs"�rrrAs���*�*�$�*rc��VP#�N)rE�rLs&r�has_obsolete_name_scheme�*NvidiaPkgNameInfo.has_obsolete_name_schemes���)�)�)rc� <�V^8�dQhRS[/#r_r)rrs"�rrrA�s�����4�rc��VP#ra)rFrbs&r�	is_server�NvidiaPkgNameInfo.is_server�s���|�|�rc� <�V^8�dQhRS[/#r_r)rrs"�rrrA�s������rc��VP#ra)rGrbs&r�is_open�NvidiaPkgNameInfo.is_open�s���z�z�rc� <�V^8�dQhRS[/#r_)rY)rrs"�rrrA�s�����3�rc��VP#ra)rHrbs&r�get_major_version�#NvidiaPkgNameInfo.get_major_version�s�����rc� <�V^8�dQhRS[/#r_r@)rrs"�rrrA�s�����S�rc��VP#ra)rIrbs&r�get_flavour�NvidiaPkgNameInfo.get_flavour�s���}�}�r)rIrHrErGrDrFrJN)rrrr r!rMrKrcrgrkrorsr#r$r%s@rr<r<BsO����/�+�+�.!�.!�`*�*��������rr<c�$�V^8�dQhR\/#r_r@)rs"rrr�s����c�rc�^�\'g\P!4^,s\#)zCache system architecture)�system_architecture�apt_pkg�get_architecturesrrr�get_apt_archrz�s$����%�7�7�9�!�<���rc�h�V^8�dQhR\\,R\\\3,/#)r�sys_pathr?)rr/r)rs"rrr�s&��-�-���
�-��c�3�h��-rc�:�/pV'dVR2MRp\P!V4EF�wr4pRpRV9d[\\PP	VR44;_uu_4pVP4P
4pRRR4M�RV9d�RV9d�\\PP	VR44;_uu_4p	V	FCp
V
PR4'gKV
PR	^4^,P
4pM	RRR4V'gEK\PP	VR
4p\PP	VR4p\PPV4'd)\PPV4'gEK�W1V&EK�	V# +'giL�;i \d$p\P!RY84Rp?EK�Rp?ii;i +'giL�;i)u�Get modaliases present in the system.

This ignores devices whose drivers are statically built into the kernel, as
you cannot replace them with other driver packages anyway.

Return a modalias → sysfs path map.
z/devicesz/sys/devicesNr*z0system_modaliases(): Cannot read %s/modalias: %s�ssb�ueventz	MODALIAS=�=�driver�module)
�os�walk�open�path�join�read�strip�IOErrorrTrU�
startswith�split�islink)
r|�aliases�devicesr��dirs�filesr*�f�e�fd�line�
driverlink�modlinks
&            r�system_modaliasesr��s����G�'/��
�(�#�^�G��W�W�W�-���E������
��"�'�'�,�,�t�Z�8�9�9�Q� �v�v�x�~�~�/�H�:�9��d�]�x�5�0��b�g�g�l�l�4��2�3�3�r��D����{�3�3�#'�:�:�c�1�#5�a�#8�#>�#>�#@����4����W�W�\�\�$��1�
��'�'�,�,�z�8�4��
�7�7�>�>�*�%�%�b�g�g�n�n�W�.E�.E�� ���C.�F�N�;:�9���
��
�
�F�����	
��4�3�sG�1G�*G�	G�H
�0+H
�G�G�G�H�$H�H�
Hc�d�V^8�dQhR\PR\PR\/#)r�	apt_cache�packager?�rx�Cache�Packager)rs"rrr�s/��E�E�w�}�}�E�w���E�SW�Erc��RpVPPR4'd&VPPRR4pW,p\P!V4pVPV4pRpVPPR4F+pVF"wr�p
VPR4'gKRpK)	K-	V'g*\P
!R	VP,4R#VR
,pTPT4pTPF!wr�pTPR4'gKTpK#	T'd�Y,pTPF+pTPPTP8XgK*R#	\P
!RTPT4\P
!T:R
TPUu.uFpTPNK	up:24R#R# \d"\P
!RT,4R#i;i \\3d$\P
!RT,4RpEL�i;i \d\P
!R4R#i;iuupi)N�nvidia-driver-zxserver-xorg-video-nvidia-z5Cannot find %s package in the cache. Cannot check ABITF�Dependszxorg-video-abi-z@The %s package seems to have no dependencies. Skipping ABI checkz;Skipping check for %s since it does not depend on video abizxserver-xorg-corez1xserver-xorg-core not available, cannot check ABIzBDriver package %s is incompatible with current X.org server ABI %sz is not in )rPr��replace�KeyErrorrTrUrx�DepCache�get_candidate_ver�depends_list_str�get�	TypeError�
provides_list�rev_depends_list�
parent_pkg)r�r��xorg_video_abi�xorg_driver_name�depcache�	candidate�needs_video_abi�dep_list�dep_name�dep_ver�dep_op�	xorg_core�
provides_name�provides_ver�	p_version�abi_pkg�dep�xs&&                r�_check_video_abi_compatr��s:���N��|�|���/�0�0�"�<�<�/�/��:�
��	��1�G����	�*�H��*�*�7�3�I��O� �!�2�2�6�6�y�A�H�-5�)��6��&�&�'8�9�9�&*�O��.6�B���
�
�I�G�L�L�X�	
����1�2�	�
�*�*�9�5�I�2;�2I�2I�.�
�Y��#�#�$5�6�6�*�N�3J���+���+�+�C��~�~�"�"�g�l�l�2��,�	�
�
�P��L�L��	
�
	�
�
��w�/G�/G�H�/G�!����/G�H�
J�	
����y�	��M�M�G�#�%�
��	��"
�i� � ��
�
�N��
�	
� �� �� ���
�
�I�J����.IsB�G,�3:H�2H�/	I�	I:�,(H�H�0I�I�!I7�6I7c��V^8�dQhR\PR\\\\
\\\\,3,3,3,/#�rr�r?)rxr�rr/rrr)rs"rrrsA��;�;��}�}�;�	�#�u�S�$�s�C��H�}�-�-�.�
.�/�;rc���\P!V4p\P!V4p/pVPEFGpVP	V4pVPVP^,4VR,pV'gKKTPR\439dKi\Y4'gK|TPR4F�pTPR4pT'gKTPR4wr�T	PR4Fop
T
P4p
T
PR^4^,pTPT/4PT
\!44P#TP$4Kq	K�	EKJ	/pVP-4Fpwr�\.P0!R
P3V
P54Uu.uFp\6P8!V4NK	up4\.P:4pW�3W�&Kr	V# \\\3dEK�i;i \&d.\(P*!RTP$:R	T:24EK)i;iuupi)a5Build a modalias map from an apt_pkg.Cache object.

This filters out uninstallable video drivers (i. e. which depend on a video
ABI that xserver-xorg-core does not provide).

Return a map bus -> modalias -> [package, ...], where "bus" is the prefix of
the modalias up to the first ':' (e. g. "pci" or "usb").
�
Modaliases�all�)�, �(�,�:zPackage z has invalid modalias header: �|)rxr��PackageRecords�packagesr��lookup�	file_listr��AttributeError�UnicodeDecodeError�architecturerzr�r�r��
setdefault�set�addrP�
ValueErrorrT�error�itemsrVrWr��keys�fnmatch�	translate�
IGNORECASE)r�r��records�resultr�r��m�partr��lst�alias�bus�result2�	alias_map�pats&              r�apt_cache_modalias_mapr�s������	�*�H��$�$�Y�/�G�-/�F��%�%��	� �2�2�7�;�I��N�N�9�.�.�q�1�2���%�A��������|�~�'>�>��&�y�:�:��	��������z�z�$�'����"�j�j��o��� �Y�Y�s�^�E�!�K�K�M�E��+�+�c�1�-�a�0�C��%�%�c�2�.�9�9�%���G�K�K�����,�%�)&�H;=�G� �,�,�.����j�j��H�H�	���8H�I�8H��g�'�'��,�8H�I�J��M�M�
���'���)��N��I�.�*<�=�	��	��.�	��M�M�@G���a�P�
�
�	��Js,�AH�8C
H-�I(�H*�)H*�-3I%�$I%c�$�V^8�dQhR\/#r_r@)rs"rrrMs��&�&��&rc��\#ra)�custom_supported_gpus_jsonrrr�path_get_custom_supported_gpusr�Ms��%�%rc�F�V^8�dQhR\R\\,/#)r�didr?�r/r)rs"rrrQs��������
�rc�B�\4pRp\VR4;_uu_4p\\P!V4R,4pVF\pVR,V8XgKVR,PR4^,p\P!RV:RVR	,:R
V:R24M	RRR4V# \d\P!R4L-i;i +'giT#;i \d"\P!R
T,4T#i;i)zpGet nvidia allowing driver for specific devices.

did: 0x1234
Return the situable nvidia driver version for it.
N�r�chips�devid�branch�.z#Found a specific nv driver version z for rPr�r�z;package_get_nv_allowing_driver(): unexpected json detected.z3package_get_nv_allowing_driver(): unable to read %s)
r�r��list�json�loadr�rT�info�	ExceptionrU)r�r��version�stream�gpus�gpus&     r�package_get_nv_allowing_driverr�Qs���*�+�D��G�
�
�$��_�_��
��D�I�I�f�-�g�6�7���C��7�|�s�*�"%�h�-�"5�"5�c�":�1�"=�����&��F���S�:��� ��&�N���
��
�
�Q���	
���_�&�N���
��
�
�K�d�R�S���N�
�sd�C2�C�6B7�A
B7�)C�*B7�,C�-C2�7!C�C�C�C�C/	�)C2�/C2�2(D�Dc��V^8�dQhR\PR\R\\\\
\\\\\,3,3,3,,R\R,/#)rr�r*�modalias_mapr?zapt_pkg.Package)	rxr�r/rrrrrr)rs"rrrps`��'(�'(��}�}�'(��'(��4��U�3��S�#�c�(�]�0C�+C�%D� D�E�F�'(�
�
��	'(rc�L�\4pVf\V4pVPVPR^4^,R/34wrE\	V4wrgRp^p	VR8Xd�\RV,4pVecRV,p
RV,pVPF@pVP4PR4^,V
8XgK0\V
.4W[&^p	KB	Ve&V	'g\P!RX
,4V	'gVeVPV4'g.#VF^p
\P!VP4V
P44'gK>W],FpVPV4K	K`	VUu.uFq�V,NK
	up#uupi)zWSearch packages which match the given modalias.

Return a list of apt.Package objects.
Nr��10DE�0xznvidia-driver-%szpci:v000010DEd0000%s*z%s is not in the package pool.)r�r�r�r��_get_vendor_model_from_aliasr�r��get_fullnamerTrUrXr��fnmatchcase�lowerr�)r�r*r��pkgsr��bus_map�vidr��nvamd�found�nvamdn�nvamda�pr�s&&&           r�packages_for_modaliasrpsa���5�D���-�i�8���#�#�H�N�N�3��$:�1�$=��b�z�J�L�C�+�H�5�H�C��E�
�E�
�f�}�.�t�c�z�:����'�%�/�F�,�s�2�F��'�'���>�>�#�)�)�#�.�q�1�V�;�&)�6�(�m�G�O��E�(���U��M�M�:�V�C�D���;�c�i�i��1�1��I������x�~�~�/�����?�?��^�^�������$��
#'�'�$�Q�a�L�L�$�'�'��'s�
F!c�d�V^8�dQhR\PR\PR\/#�rr��pkgr?r�)rs"rrr�s)�����
�
��G�O�O���rc��\P!V4pVPV4pVfQhVPP	R4'dR#\P
!V4pVP
VP^,4VP^,PF<wrVVP'gVR,pVR9u#VPR9gK;R#	R# \dR#i;i)NrRF�	ComponentT)�
restricted�
multiverse)rxr�r�rPr�r�r�r��version_list�	componentr�)r�rr�r�r��pfile�_rs&&      r�_is_package_freer�s������	�*�H��*�*�3�/�I�� � � ��x�x���8�$�$���$�$�Y�/�G��N�N�9�&�&�q�)�*��$�$�Q�'�1�1�������
�#�K�0�	� �(D�D�D����">�>��2����
��
�s�>
C(�(C8�7C8c�d�V^8�dQhR\PR\PR\/#rr�)rs"rrr�s)��	�	�w�}�}�	�7�?�?�	�t�	rc���\P!V4pVPV4pVfR#VP^,^,PR8H# \
dR#i;i)NF�Ubuntu)rxr�r�r��originr�)r�rr�r�s&&  r�_is_package_from_distror�sc�����	�*�H��*�*�3�/�I������"�"�1�%�a�(�/�/�8�;�;������s�&A�A%�$A%c�z�V^8�dQhR\PR\PR\\,/#r)rxr�r�rr)rs"rrr�s0�����}�}��#*�?�?��
�c�]�rc��\P!V4pVPV4p\P!V4pVP	VP
^,4VR,pTR9d%\P!RTPT4R#T# \\3d&\P!RTP4R#i;i)z>Determine if -open package is prefered from apt Package objectzPrefer-VariantzM_pkg_get_open_preference %s: package has Prefer-Open header, cannot determineFzb_pkg_get_open_preference %s: package has invalid Prefer-Open %sheader, cannot determine preferenceN)�Open�Closed�rxr�r�r�r�r�r�r�rTrUrP)r�rr�r�r��
preferences&&    r�_pkg_get_open_preferencer$�s������	�*�H��*�*�3�/�I��$�$�Y�/�G��N�N�9�&�&�q�)�*���-�.�
��+�+��
�
�
2��H�H��		
�����!
�n�%���
�
�[��H�H�	
�����!	B�2C
�C
c�z�V^8�dQhR\PR\PR\\,/#r�rxr�r�rr/)rs"rrr�s.����w�}�}��7�?�?��x�PS�}�rc���\P!V4pVPV4p\P!V4pVP	VP
^,4VR,pTPR4pT^8:d$\P!RTP4R#TRTpT# \\3d&\P!RTP4R#i;i)z-Determine module name from apt Package objectr�zM_pkg_get_module %s: package has no Modaliases header, cannot determine moduleNr�zR_pkg_get_module %s: package has invalid Modaliases header, cannot determine module)rxr�r�r�r�r�r�r�rTrUrPr[)r�rr�r�r�r��parenr�s&&      r�_pkg_get_moduler*�s������	�*�H��*�*�3�/�I��$�$�Y�/�G��N�N�9�&�&�q�)�*���L�!��
�F�F�3�K�E���z��
�
�`��H�H�	
��
�v��Y�F��M��!
�n�%���
�
�[��H�H�	
���s�!	B,�,2C"�!C"c�z�V^8�dQhR\PR\PR\\,/#rr')rs"rrr�s.�����
�
��G�O�O���QT�
�rc��\P!V4pVPV4p\P!V4pVP	VP
^,4VR,pTR9d%\P!RTPT4R#T# \\3d&\P!RTP4R#i;i)z/Determine support level from apt Package object�SupportzR_pkg_get_support %s: package has no Support header, cannot determine support levelNzY_pkg_get_support %s: package has invalid Support %sheader, cannot determine support level)�PB�NFB�LTSB�Legacyr")r�rr�r�r�r6s&&    r�_pkg_get_supportr2�s������	�*�H��*�*�3�/�I��$�$�Y�/�G��N�N�9�&�&�q�)�*���)�$���5�5��
�
�
5��H�H��		
���N��!
�n�%���
�
�`��H�H�	
���r%c�<�V^8�dQhR\R\R\/#)rr��verr?�r/r)rs"rrrs!��!�!�s�!��!��!rc	��\P!RV4pV'gR#VP^4pVP^4pVR8wdR#RV,p\4p\	VR4;_uu_4p\\P!V4R,4pVF�pVR,V8XgKRVR	,9gK#VR
,PR4^,V8wdG\P!RVR
,PR4^,:R
V:24RRR4R#\P!RV,4RRR4R#	RRR4R# \d\P!R4L-i;i +'giR#;i \d"\P!RT,4R#i;i)zAalias: e.g. pci:v000010DEd000024BAsv0000103Csd000089C6bc03sc00i00zpci:v0000(.*)d0000(.*)sv(.*)Fr�z0x%sr�r�r��	runtimepm�featuresr�r�z!Candidate version does not match z != NzFound runtimepm supports on %s.Tz?_is_nv_allowing_runtimepm_supported(): unexpected json detectedz8_is_nv_allowing_runtimepm_supported(): unable to read %s)
rV�searchrZr�r�r�r�r�r�rTrUr�r�)	r�r4r�rr�r�r�r�r�s	&&       r�#_is_nv_allowing_runtimepm_supportedr:sw��
�Y�Y�5�u�
=�F���
�,�,�q�/�C�
�,�,�q�/�C�
�f�}��
�3�,�C�)�+�D�
�
�$��_�_��
��D�I�I�f�-�g�6�7���C��7�|�s�*�{�c�*�o�/M��x�=�.�.�s�3�A�6�#�=�#�M�M�#&�x�=�#6�#6�s�#;�A�#>�#>��!E��$)��_� ���%F��%L�M�#��_� ��*���
��
�
�U���	
���_�*���
��
�
�P�SW�W�X���
�ss�!F�5F�76E �2E �A E �"F�,E �
F�E �F� !F�F�F�F�F	�F�F�(G�Gc�p�V^8�dQhR\PR\PR\R\/#)rr�rr�r?)rxr�r�r/r)rs"rrr>s4��
�
��}�}�
�#*�?�?�
�;>�
�	�
rc��a�\P!V4pVPV4p\P!V4pVP	VP
^,4\P!VP4pVPPR4^,pVR,pVPR4^8wdR#W�PR4^,VPR4p	V	PR4p
\SV4'dR#\;QJdV3R	lV
4F'gKR#	R#!V3R	lV
44# \\\3dR#i;i)
z>Check if the package supports runtimepm for the given modaliasr��	PmAliasesznvidia(Fr�r�r�Tc3�<"�TF8p\P!SP4VP44x�K:	R#5ira)r�r)�.0�regexr�s& �r�	<genexpr>�*_is_runtimepm_supported.<locals>.<genexpr>Ts.����
�GQ�e�G�O�O�E�K�K�M�5�;�;�=�9�9�z�s�AA)rxr�r�r�r�r��
TagSection�record�ver_strr�r[r:�anyr�r�r�)r�rr�r�r�r��sectionr4r��n�
modaliasess&&f        r�_is_runtimepm_supportedrJ>s0���
��#�#�I�.���.�.�s�3�	��(�(��3�����y�*�*�1�-�.��$�$�W�^�^�4�����%�%�c�*�1�-���K� ��
�6�6�)���!��
�f�f�S�k�A�o����s��,���W�W�T�]�
�.�u�c�:�:���s�
�GQ�
�s�s�	
�s�	
�s�
�GQ�
�
�	
��
�n�&8�9����s�B*E
�
E'�&E'c�$�V^8�dQhR\/#r_r)rs"rrrYs����D�rc��\PPRR4R8H;'g"\PPR4RJ#)z*Check if the current session in on Wayland�XDG_SESSION_TYPEr:�wayland�WAYLAND_DISPLAYN)r��environr�rrr�is_wayland_sessionrQYsA��	�
�
���)�2�.�)�;�	9�	9�
�:�:�>�>�+�,�D�8�rc�d�V^8�dQhR\PR\PR\/#rr�)rs"rrras)��(�(�'�-�-�(�g�o�o�(�$�(rc���VP'dR#VPPR4'dRpM/VPPR4'dRpM\W4pV'gR#\P
!RV.\P\PR7pVP4VP^8Xd%\P!RVPV4R#\P!R
TPT4R# \\\P3d,p\P!R\T44R	p?R#R	p?ii;i)zIDetermine if the kernel module from an apt.Package is manually installed.FrR�fglrx�modinfo)�stdout�stderrzJ_is_manual_install %s: builds module %s which is available, manual installTz_is_manual_install failed: %sNzQ_is_manual_install %s: builds module %s which is not available, no manual install)�current_verrPr�r*�
subprocess�Popen�PIPE�communicate�
returncoderTrU�OSError�FileNotFoundError�CalledProcessErrorr/)r�rr�rUr�s&&   r�_is_manual_installraas��������x�x���8�$�$���	���	�	�W�	%�	%��� ��0������"�"�
���
���
���
��	����
����"��M�M�\�����
�
�
#��M�M�[������
��#
�&�
�(E�(E�F���
�
�5�s�1�v�>����s�3AD� E�4 E�Ec	��V^8�dQhR\R\R\\\,\\,3,/#)rr4r�r?�r/rr)rs"rrr�s3����#��c��e�H�S�M�8�C�=�4P�.Q�rc	��\P!RRV.RR7p\P
!RT4RpRpTP4F+pTPR^4wrxR	T9dTpR
T9gK)TpK-	\P
!RYYE4YE3# \\P3d.p\P
!RY\
T44RuRp?#Rp?ii;i)
zLReturn (vendor, model) names for given device.

Values are None if unknown.
zsystemd-hwdb�queryT��universal_newlinesz-_get_db_name(%s, %s): systemd-hwdb failed: %sNz_get_db_name: output
%s
r��_VENDOR�_MODELz-_get_db_name(%s, %s): vendor "%s", model "%s"�NN)	rY�check_outputr^r`rTrUr/�
splitlinesr�)	r4r��outr�r+r,r��k�vs	&&       r�_get_db_namerp�s���
��%�%�
�W�e�,��
���M�M�.��4�
�F��E���� �����C��#�����>��F��q�=��E�!��M�M�7����
�?���)
�Z�2�2�3���
�
�;�W�S�QR�V�	
����	�s�B�C�-"C�C�Cc�d�V^8�dQhR\PR\PR\/#rr�)rs"rrr�s)��������W�_�_���rc��VPPR4'gR#\W4pVfO\VP4pVP	4R8�d$\
P!RVP4R#M*VR8Xd$\
P!RVP4R#\
P!RVP4R#)�nvidia-Fi0z_is_open_prefered(%s): TrueTr z_is_open_prefered(%s): False)rPr�r$r<rorTrU)r�rr#�nvidia_infos&&  r�_is_open_preferedru�s����8�8���y�)�)��)�)�9�J���'����1���(�(�*�c�1��M�M�7����B��2�
�v�	��
�
�3�S�X�X�>���M�M�0�#�(�(�;�rc�(�V^8�dQhR\RR/#)r�valuer?Nr)rs"rrr�s��
�
�$�
�4�
rc�v�RpRV,p\VR4pVPV4VP4R#)zSet KMS on or off for NVIDIAz/lib/modprobe.d/nvidia-kms.confz�# This file was generated by ubuntu-drivers
# Set value to 1 to enable modesetting, 0 to disable it
options nvidia-drm modeset=%d
�wN)r��write�close)rw�nvidia_kms_file�kms_text�kms_fds&   r�set_nvidia_kmsr�s;��7�O�#�	��H�
�/�3�
'�F�
�L�L���
�L�L�Nrc��V^8�dQhR\\P,R\\,R\R\R\
\\3,/#)rr�r|�freeonly�include_oemr?�rrxr�r/rrr2)rs"rrr�sX��c�c���
�
�&�c��s�m�c��c��	c�

�#�{�
��crc�V�\V4pV'g\P!R4p/p\
V4pVP4F�wr�\WVR7F�p
V'd\W
4'gKV'g*\P!V
PR4'dKORVRV	R\W
4R\W
4R\W
4R	\W
V4R
\W
4/WjP&\!W�4wr�VeW�V
P,R&VfK�W�V
P,R&K�	K�	VU
u.uFq�P#R
4'gKV
NK	p
p
V
'd�VP4F'wr�VP#R
4'gKV\$V&K)	V
P'\(P*!\,4R7V
R,pV
Fp
V
V8HWj,R&K	\/V4P4F6wppVF*p
W
,pR\VV4R\VV4RV/Wj&K,	K8	V# \d#p\P
!T4/uRp?#Rp?ii;iuup
i \0d"\P2!RT
,4K�i;i)uqGet driver packages that are available for the system.

This calls system_modaliases() to determine the system's hardware and then
queries apt about which packages provide drivers for those. It also adds
available packages from detect_plugin_packages().

If you already have an apt_pkg.Cache() object, you should pass it as an
argument for efficiency. If not given, this function creates a temporary
one by itself.

If freeonly is set to True, only free packages (from main and universe) are
considered

Return a dictionary which maps package names to information about them:

  driver_package → {'modalias': 'pci:...', ...}

Available information keys are:
  'modalias':    Modalias for the device that needs this driver (not for
                 drivers from detect plugins)
  'syspath':     sysfs directory for the device that needs this driver
                 (not for drivers from detect plugins)
  'plugin':      Name of plugin that detected this package (only for
                 drivers from detect plugins)
  'free':        Boolean flag whether driver is free, i. e. in the "main"
                 or "universe" component.
  'from_distro': Boolean flag whether the driver is shipped by the distro;
                 if not, it comes from a (potentially less tested/trusted)
                 third party source.
  'vendor':      Human readable vendor name, if available.
  'model':       Human readable product name, if available.
  'recommended': Some drivers (nvidia, fglrx) come in multiple variants and
                 versions; these have this flag, where exactly one has
                 recommended == True, and all others False.
N�r��
oem-*-metar*r4rrr6r7r7r+r,rs��keyrr5z*Package %s plugin not available. Skipping.rC)r�rxr�r�rTr�r�r�rrr�rPrr2rJrurpr��lookup_cache�sort�	functoolsr	�_cmp_gfx_alternatives�detect_plugin_packagesr�rU)r�r|r�r�rI�exr�r�r�r4rr+r,�nvidia_packagesr�rwrr5r�apt_ps&&&&                r�system_driver_packagesr��s^��R#�8�,�J��	��
�
�d�+�I�
�H�)�)�4�L�$�*�*�,���&�y�l�S�A�� 0�� >� >���7�?�?�1�6�6�<�#H�#H���E��7��(��6��6�y�D��+�I�9��4�Y�5�I� �"3�I�"A� �H�V�V��+�7�:�O�V��!�-3���� ��*�� �,1���� ��)�%T�-�,#+�F�(�Q�l�l�9�.E�q�q�(�O�F��#�.�.�*�J�C��~�~�i�(�(�$)��S�!�+�	����!5�!5�6K�!L��M�%�b�)�� �A�)*�k�)9�H�K�
�&�!�/�y�9�?�?�A�����A�
P�!����,�Y��>�!�#:�9�e�#L��f�����B��O��k�	��M�M�"���I��	��8G��,�
P��
�
�J�Q�N�O�
P�s;�I�I7�I7�&I<�I4�I/�)I4�/I4�<(J(�'J(c�~�V^8�dQhR\R\\\,\\,3,/#)rr�r?rc)rs"rrr1s,�������h�s�m�X�c�]�6R�0S�rc���\P!R4pVPV4pV'd1VP^4R,VP^4R,3#R#)z$(.+):v(.+)d(.+)sv(.+)sd(.+)bc(.+)i.*:�NNrj)rVrWrXrZ)r��modalias_pattern�detailss&  rrr1sR���z�z�"H�I���$�$�U�+�G���
�
�a� ��$�g�m�m�A�&6�r�&:�;�;��rc�f�V^8�dQhR\PR\R\\,/#)rr�r>r?)rxr�r/r)rs"rrr<s*����g�m�m��s��x�PS�}�rc��VfQhRp\P!V4p\V4pVP'g \P
!RV,4V#VP
4'd \P
!RV,4V#VP4pRV,pW,pVPV4pV'dVPR\439dTpV# \dT#i;i)N�)Unsupported driver detected: %s. Skipping�%Legacy driver detected: %s. Skipping.znvidia-driver-lrm-%sr�)rxr�r<rJrTrUrcrsr��archrzr�)	r�r>r8r�rt�candidate_flavourr�r��package_candidates	&&       r�get_userspace_lrm_metar�<s�������!%�K�����	�*�H�#�H�-�K������
�
�A�H�L�M����+�+�-�-��
�
�=��H�I���#�/�/�1��&�*;�<�I�
��&��%�6�6�w�?���*�/�/�E�<�>�3J�J�#�K�����
����
�s�+>C+�+C:�9C:c�z�V^8�dQhR\PR\PR\\,/#)rrr�r?)rxr�r�rr/)rs"rrr^s0��#�#�	���#�%,�]�]�#�
�c�]�#rc��VfQhRp\P!V4pVPp\V4pVP'g \
P!RV,4V#VP4'd \
P!RV,4V#VP4pRV,pW,pVPV4p	V'dV	PR\439dTpV# \dT#i;i)Nr�r�znvidia-headless-no-dkms-%sr�)
rxr�rPr<rJrTrUrcrsr�r�rzr�)
rr�r8r�rPrtr�r�r�r�s
&&        r�!_get_headless_no_dkms_metapackager�^s���?��?�!%�K��
���	�*�H��8�8�D�#�D�)�K������
�
�A�D�H�I����+�+�-�-��
�
�=��D�E���#�/�/�1��,�0A�B�I�
��&��%�6�6�w�?���*�/�/�E�<�>�3J�J�#�K�����
����
�s�7>C7�7D�Dc
��V^8�dQhR\\P,R\\,R\R\
\\3,/#)rr�r|r�r?r�)rs"rrr�sM��B�B���
�
�&�B��s�m�B��B�
�#�{�
��	Brc�b�V'g/#\V4pV'g\P!R4p/p\
V4pVP4F�wrx\WVR7F�p	\P!V	PR4'g*\P!V	PR4'gKSRVRVR\W	4R\W	4R	R
R\W	4R\W	4/WYP&K�	K�	V# \d#p\P
!T4/uRp?#Rp?ii;i)
uxGet device specific metapackages for this system

This calls system_modaliases() to determine the system's hardware and then
queries apt about which packages provide hardware enablement support for
those.

If you already have an apt_pkg.Cache() object, you should pass it as an
argument for efficiency. If not given, this function creates a temporary
one by itself.

Return a dictionary which maps package names to information about them:

  driver_package → {'modalias': 'pci:...', ...}

Available information keys are:
  'modalias':    Modalias for the device that needs this driver (not for
                 drivers from detect plugins)
  'syspath':     sysfs directory for the device that needs this driver
                 (not for drivers from detect plugins)
  'plugin':      Name of plugin that detected this package (only for
                 drivers from detect plugins)
  'free':        Boolean flag whether driver is free, i. e. in the "main"
                 or "universe" component.
  'from_distro': Boolean flag whether the driver is shipped by the distro;
                 if not, it comes from a (potentially less tested/trusted)
                 third party source.
  'vendor':      Human readable vendor name, if available.
  'model':       Human readable product name, if available.
  'recommended': Always True; we always recommend you install these
                 packages.
Nr�r��
hwe-*-metar*r4rrrTr6r7)r�rxr�r�rTr�r�r�rr�rPrrr2ru)
r�r|r�rIr�r�r�r�r4rs
&&&       r�#system_device_specific_metapackagesr��s
��H��	�"�8�,�J��	��
�
�d�+�I�
�H�)�)�4�L�$�*�*�,���&�y�l�S�A��?�?�1�6�6�<�8�8��������B�B���E��7��(��6��6�y�D��t��+�I�9� �"3�I�"A� �H�V�V��T�-� �O��-�	��M�M�"���I��	�s�D�D.�D)�#D.�)D.c��V^8�dQhR\\P,R\\,R\\\
3,/#)rr�r|r?)rrxr�r/rr2)rs"rrr�s@��R�R���
�
�&�R�9A�#��R�	�#�{�
��Rrc�F�R.p\V4pV'g\P!R4p/p\
V4pVP4F�wrx\WVR7F�p	\W�4wr�\V4wr�VfK#VP4V9gK:RVRVR\W	4R\W	4R\W	4R	\W	4/WYP &V
eW�V	P ,R
&VeW�V	P ,R&\#W�4pVfK�W�V	P ,R&K�	K�	VU	u.uFq�P%R
4'gKV	NK	pp	V'd�VP4F(wppVP%R
4'gKV\&V&K*	VP)\*P,!\.4R7VR,pVFp	V	V8HWY,R&K	V# \d#p\P
!T4/uRp?#Rp?ii;iuup	i)uNGet driver packages, for gpgpu purposes, that are available for the system.

This calls system_modaliases() to determine the system's hardware and then
queries apt about which packages provide drivers for those. Finally, it looks
for the correct metapackage, by calling _get_headless_no_dkms_metapackage().

If you already have an apt_pkg.Cache() object, you should pass it as an
argument for efficiency. If not given, this function creates a temporary
one by itself.

Return a dictionary which maps package names to information about them:

  driver_package → {'modalias': 'pci:...', ...}

Available information keys are:
  'modalias':    Modalias for the device that needs this driver (not for
                 drivers from detect plugins)
  'syspath':     sysfs directory for the device that needs this driver
                 (not for drivers from detect plugins)
  'plugin':      Name of plugin that detected this package (only for
                 drivers from detect plugins)
  'free':        Boolean flag whether driver is free, i. e. in the "main"
                 or "universe" component.
  'from_distro': Boolean flag whether the driver is shipped by the distro;
                 if not, it comes from a (potentially less tested/trusted)
                 third party source.
  'vendor':      Human readable vendor name, if available.
  'model':       Human readable product name, if available.
  'recommended': Some drivers (nvidia, fglrx) come in multiple variants and
                 versions; these have this flag, where exactly one has
                 recommended == True, and all others False.
�10deNr�r*r4rrr6r7r+r,r8rsr�rrC)r�rxr�r�rTr�r�r�rrprrrrr2rurPr�r�r�r�r�r	�_cmp_gfx_alternatives_gpgpu)r�r|�vendors_whitelistrIr�r�r�r�r4rr+r,�	vendor_id�model_idr8r�r�rwrs&&                 r�system_gpgpu_driver_packagesr��s���F ���"�8�,�J��	��
�
�d�+�I�
�H�)�)�4�L�$�*�*�,���&�y�l�S�A�*�7�:�O�V�">�u�"E��I��%�I�O�O�,=�AR�,R����w��,�Y�:�!�#:�9�#H��/�	�=�$�&7�	�&E�
$���� ��%�17�Q�V�V�$�X�.��$�05�Q�V�V�$�W�-�?��M���*�6A�Q�V�V�$�]�3�'T�-�.#+�F�(�Q�l�l�9�.E�q�q�(�O�F��#�.�.�*�J�C���~�~�i�(�(�$)��S�!�+�	����!5�!5�6Q�!R��S�%�b�)�� �A�)*�k�)9�H�K�
�&�!��O��S�	��M�M�"���I��	��:Gs)�G.�9H�H�.H�9H�H�Hc
��V^8�dQhR\\P,R\\,R\R\
\\3,/#)rr�r|r�r?)rrxr�r/rrr()rs"rrrsL��^�^���
�
�&�^��s�m�^��^�
�#�z�/��	^rc���/pV'g\P!R4p\WVR7P
4F�wrVRV9dVR,pM	VR,pVPV/4RFpW�9gKWh,W7,V&K	W7,PR/4p	RVR,RVR,/W�&RV9gK�VR,W�,R&K�	VP
4F5wr�VR,Fp\WV,4'dKK.	R	VR
&K7	\V4V# \d#p\P!T4/uRp?#Rp?ii;i)um
Get by-device driver packages that are available for the system.

This calls system_modaliases() to determine the system's hardware and then
queries apt about which packages provide drivers for each of those. It also
adds available packages from detect_plugin_packages(), using the name of
the detction plugin as device name.

If you already have an apt_pkg.Cache() object, you should pass it as an
argument for efficiency. If not given, this function creates a temporary
one by itself.

If freeonly is set to True, only free packages (from main and universe) are
considered

Return a dictionary which maps devices to available drivers:

  device_name →  {'modalias': 'pci:...', <device info>,
                  'drivers': {'pkgname': {<driver package info>}}

A key (device name) is either the sysfs path (for drivers detected through
modaliases) or the detect plugin name (without the full path).

Available keys in <device info>:
  'modalias':    Modalias for the device that needs this driver (not for
                 drivers from detect plugins)
  'vendor':      Human readable vendor name, if available.
  'model':       Human readable product name, if available.
  'drivers':     Driver package map for this device, see below. Installing any
                 of the drivers in that map will make this particular
                 device work. The keys are the package names of the driver
                 packages; note that this can be an already installed
                 default package such as xserver-xorg-video-nouveau which
                 provides a free alternative to the proprietary NVidia
                 driver; these will have the 'builtin' flag set.
  'manual_install':
                 None of the driver packages are installed, but the kernel
                 module that it provides is available; this usually means
                 that the user manually installed the driver from upstream.

Aavailable keys in <driver package info>:
  'builtin':     The package is shipped by default in Ubuntu and MUST
                 NOT be uninstalled. This usually applies to free
                 drivers like xserver-xorg-video-nouveau.
  'free':        Boolean flag whether driver is free, i. e. in the "main"
                 or "universe" component.
  'from_distro': Boolean flag whether the driver is shipped by the distro;
                 if not, it comes from a (potentially less tested/trusted)
                 third party source.
  'recommended': Some drivers (nvidia, fglrx) come in multiple variants and
                 versions; these have this flag, where exactly one has
                 recommended == True, and all others False.
N)r�r4r5r-rrrTr.)r*r+r,)
rxr�r�rTr�r�r�r�ra�
_add_builtins)r�r|r�r�r�r�pkginfo�device_name�opt_keyr-r�r�s&&&         r�system_device_driversr�sQ��r%'�F��	��
�
�d�+�I�/��h���e�g�������!�)�,�K�!�(�+�K����+�r�*�6�G��!�/6�/?��#�G�,�7��%�0�0��B�?��������
�@V�W����G�#�*1�-�*@�G�L��'��$�������	�?�?�C�%�i�3��@�@��#�&*�D�!�"�'��&���M��C�	��M�M�"���I��	�s�D3�3E �>E�E �E c�f�V^8�dQhR\PR\R\\,/#)rr��glob_patternr?)rxr�r/r)rs"rrrs,��&�&��}�}�&�,/�&�	�#�Y�&rc���.pVPFRpVPpVP'gK#\P!WA4'gKAVP	V4KT	\V4#)a(Query apt-cache for installed packages matching a specific glob pattern.

Args:
    apt_cache: The apt cache object
    glob_pattern: Glob pattern to match package names (e.g., "nvidia-driver-*")

Returns:
    List of strings containing the names of all installed packages that match the pattern
)r�rPrXr��append�sorted)r�r��installed_packagesr��package_names&&   r�get_installed_packages_by_globr�sY�����%�%���|�|������7�?�?�<�#N�#N��%�%�l�3�&�
�$�%�%rc��V^8�dQhR\PR\\,R\R\R\R\R\
\,/#)rr�r|�	free_onlyr��
driver_string�include_dkmsr?)rxr�rr/rr)rs"rrr�sZ�����}�}���s�m�����	�
���
�
�#�Y�rc�|�\WW#R7p\WWdRR7pV'g\P!R4V#V#)z4Return the list of packages that should be installed)r�r�F)�get_recommendedz"No drivers found for installation.)r��auto_install_filterrTrU)r�r|r�r�r�r�r��
to_installs&&&&&&  r�get_desktop_package_listr��sD��&��i��H�%���%��J���
�
�:�;����rc�>�V^8�dQhR\\,RR/#)rr�r?N)rr/)rs"rrr�s����T�#�Y��4�rc�t�VF1p\V4pVP4R8�gK%\R4R#	R#)zHApplies changes that need to happen before installing the NVIDIA driversi�TN)r<ror)r�r�rts&  r�$nvidia_desktop_pre_installation_hookr��s4��#��'��5���(�(�*�c�1��4� ��	#rc��V^8�dQhRR/#)rr?Nr)rs"rrr�s��:�:�t�:rc�X�\PPR4'd`\P!R4\
P!RR.4\RR4;_uu_4pVPR4RRR4R#R# \dL?i;i +'giR#;i)�/run/nvidia_runtimepm_supportedz,Trying to select the on-demand PRIME profilez/usr/bin/prime-selectz	on-demandz$/etc/u-d-c-nvidia-runtimepm-overrideryz!# File created by ubuntu-drivers
N)
r�r��isfilerTrUrY�callr_r�rz)r�s r�%nvidia_desktop_post_installation_hookr��s���
�w�w�~�~�7�8�8��
�
�D�E�	��O�O�4�k�B�C�
�8�#�
>�
>�!�
�G�G�8�9�?�
>�9��!�	��	��?�
>�
>�s�B�)B�B�B�B)	c�Ha�]tRtRtoRV3RlRlltV3RlRltRtVtR#)	�_GpgpuDriveri�Nc�J<�V^8�dQhRS[S[,RS[S[,RR/#)rr+�flavourr?N�rr/)rrs"�rr�_GpgpuDriver.__annotate__�s-������s�m��5=�c�]��	
�rc�,�RVnWnW nR#)rRN)rR)�_vendors_whitelistr+r�)rLr+r�s&&&rrM�_GpgpuDriver.__init__�s��#.������rc� <�V^8�dQhRS[/#r_r)rrs"�rrr��s���:�:�$�:rc���VP'd4\P!VPVP4'gR#VP'*;'dVP'*'*#�F)r+r��filterr�r�rbs&rrJ�_GpgpuDriver.is_valid�sG���;�;�;��>�>�$�"9�"9�4�;�;�G�G�����O�8�8�D�L�L�(8�9�9r)r�r�r+rj)rrrr rMrJr#r$r%s@rr�r��s������:�:rr�c�0�V^8�dQhR\R\/#)r�stringr?)r/r�)rs"rrr�s�� � �3� �<� rc���\4p\P!R4pVPV4pV'd5RVnVP^4:VP^4:2VnV#\P!R4p\P!R4p\P!R4pVPV4pVPV4pVPV4p	V'dDVP^4VnVP^4:VP^4:2VnV#V'd	WnV#V	'd,V	P^4:V	P^4:2VnV#)zReturns a _GpgpuDriver objectrSrRz(.+):([0-9]+)(.*)z([a-z]+)z([0-9]+)(.*))r�rVrWrXr+rZr�)
r�r��metapackage_pattern�metapackage_match�full_pattern�vendor_only_pattern�series_only_pattern�
full_match�vendor_match�series_matchs
&         r�_process_driver_stringr��s:��
�^�F��*�*�%A�B��+�1�1�&�9��� ��
��#�#�A�&��#�#�A�&�
����
��:�:�1�2�L��*�*�Z�0���*�*�^�4���#�#�F�+�J�&�,�,�V�4�L�&�,�,�V�4�L��"�(�(��+��
�#-�#3�#3�A�#6�
�8H�8H��8K�L����M�
��
��M�
�#/�#5�#5�a�#8�,�:L�:L�Q�:O�P����Mrc	��V^8�dQhR\\\3,R\R\\
\\3,,/#)rr��gpgpur?)rr/r2rrr)rs"rrr�s=�����3��#�$��-1��	�%��[� �
!�"�rc�~a�V'd\M\o\VP4\	V3Rl4RR7#)a�
Sort packages by preference based on desktop or GPGPU mode.

Args:
    packages: Dict of package candidates to sort.
        Typically originates from system_driver_packages() or system_gpgpu_driver_packages(),
        and is filtered depending on the mode (desktop vs gpgpu) and user preferences.
    gpgpu: Boolean flag indicating whether to use GPGPU (server) sorting preferences.

Returns:
    List of (package_name, package_info) tuples sorted by preference (most preferred first).
c�2<�S!V^,V^,4#)�r)�left�right�
comparators&&�r�<lambda>�._sort_packages_by_preference.<locals>.<lambda>s���:�d�1�g�u�Q�x�+HrT)r��reverse)r�r�r�r�r	)r�r�r�s&&@r�_sort_packages_by_preferencer��s3���16�,�;P�J�������H�I���rc��V^8�dQhR\PR\\\\
3,,R\R\R\\,/#)r�cache�sorted_packagesr�r�r?)rxr�rrr/r2r)rs"rrrsX��[�[��=�=�[��%��[� 0�1�2�[��[��	[�

�#�Y�[rc�n�\P!V4p.pRpVEFwrx\P!R\	V4,4VPR4'gV'dKMV'g�VP
W,4p	\P!V4p
V
PV	P^,4V
R,'d/\RR4pVPR4VP4VPR4pVPR	4'd>\;QJdR
V4F'gKRM	RM
!R
V44'dEKFV'dCW,P 'd.pRpEKmVP#V4VP#V4M7\P!R\	V4,4VP#V4\P!R
\	V4,4\%W4p
\P!V
4V
'gEKW
,P 'dEK4V'g9RV
9d2Wu9dVP'V4W�9dVP'V4EKtWu9dV'dVP'V4VP#V
4\)W4pV'dIW,P 'g1VP#V4Wu9dV'dVP'V4RpEK	V# \dEL5i;i)a�
Build the list of packages to install including metapackages and modules.

Args:
    cache: The apt cache object used to check installed packages.
    sorted_packages: List of (package_name, package_info) tuples sorted by preference.
    include_dkms: Boolean indicating whether to include DKMS packages.
    gpgpu: Boolean flag indicating whether to use GPGPU (server) mode.

Returns:
    List of package names to install including metapackages and module packages.
FzProcessing package: zhwe-r7r�ry�
r8r�c3�B"�TFqPR4x�K	R#5i�r�N�r��r?rs& rrA�+_build_installation_list.<locals>.<genexpr>Bs���J�z��>�>�"2�3�3�z���Tz#No candidate metapackage found for zCandidate: �dkms)rxr�rTrUr/r�r�r�r�r�r�rzr{�PermissionErrorr�rFrXr��get_linux_modules_metapackage�remover�)r�r�r�r�r�r��driver_foundr�pkg_info�
candidate_verr��pm_fdr��modules_package�lrm_metas&&&&           r�_build_installation_listr
sd��$����&�H��J��L�&���	�
�
�,�s�1�v�5�6��|�|�F�#�#����$�6�6�u�x�@�M��,�,�U�3�G��N�N�=�2�2�1�5�6��{�#�#�� �!B�C�H�E��K�K��%��K�K�M��L�L��/�	��<�<�(�)�)��s�J�z�J�s�s�s�J�z�J�J�J�����+�+�+��
�#����!�!�!�$��!�!�)�,��M�M�?�#�a�&�H�I����a� ��
�
�m�c�)�n�4�5�7��A���
�
�o�&��?�5�#9�#E�#E�#E��F�o�$=��?��%�%�a�(��*��%�%�i�0����5��!�!�!�$����o�.�-�e�7�H���� ;� ;� ;��!�!�(�+��?�u��%�%�a�(��L��G'�J���e'����s�-L%�%L4�3L4c��V^8�dQhR\\P,R\\,R\\,/#)rr�r�r?)rrxr�rr/)rs"rrros5�����G�M�M�"��.2�3�i��	�#�Y�rc���.p\VRR7FSpV'd8W,P'd \P!RV,4KBVP	V4KU	V#)z�
Filter out packages that are already installed.

Args:
    cache: The apt cache object used to check installed packages.
    packages: List of package names to filter.

Returns:
    List of package names that are not yet installed.
T)r�z4Removing already-installed package from to_install: )r�rXrTrUr�)r�r��filteredrs&&  r�_remove_already_installedrosP���H�
�H�d�
+���U�X�)�)�)��M�M�P�ST�T�U��O�O�A��	,�
�Orc��V^8�dQhR\\P,R\\\
3,R\R\R\\,/#)rr�r�r�r�r?)rrxr�rr/r2rr)rs"rrr�sQ��8�8��G�M�M�"�8��3��#�$�8��8��	8�

�#�Y�8rc��V'g.p\W4pVFiwrgVPR4'd=\;QJdRV4F'gKRM	RM
!RV44'dKXVPV4Kk	V#\W4p\	WW#4p\W4p\P!R\V4,4V#)a�
Sort driver branch to install according to preference, then select
most appropriate modules package and filter out already installed packages.

Args:
    cache: The apt cache object used to check installed packages.
    packages: Dict of package candidates to consider for installation.
        Typically originates from system_driver_packages() or system_gpgpu_driver_packages(),
        and is filtered depending on the mode (desktop vs gpgpu) and user preferences.
    include_dkms: Boolean indicating whether to include DKMS packages.
    gpgpu: Boolean flag indicating whether to use GPGPU (server) sorting preferences.

Takes a list of packages of this format:
{'modalias': 'pci:v000010DEd000010C3sv00003842sd00002670bc03sc03i00',
 'syspath': '/tmp/umockdev.8CRPA3/sys/devices/graphics', 'free': False,
 'from_distro': False, 'support': None, 'open_preferred': False,
 'vendor': 'NVIDIA Corporation', 'model': 'GT218 [GeForce 8400 GS Rev. 3]',
 'metapackage': 'nvidia-headless-no-dkms-410', 'recommended': True}
checks to see if the requested packages are already installed, then filters
them out if so.

Returns:
    A simplified list of just the package names for apt to install, of the form:
    ['nvidia-driver-410', 'nvidia-headless-no-dkms-410']
r�c3�B"�TFqPR4x�K	R#5ir�r�r�s& rrA�+already_installed_filter.<locals>.<genexpr>�s���N�:�C�~�~�&6�7�7�:�r�TFzto_install_final:  )	r�r�rFr�r
rrTrUr/)r�r�r�r�r�r�rrs&&&&    r�already_installed_filterr�s���F� "�
�6�x�G��#�D�A��|�|�,�-�-��3�N�:�N�3�3�3�N�:�N�N�N�����a� �$���3�8�C�O�*�%�,�V�J�+�5�=�J��M�M�'�#�j�/�9�:��rc���V^8�dQhR\\P,R\R\\
\3,R\
R\R\R\\
,/#�rr�r�r��drivers_strr�r�r?�rrxr�rrr/r2r)rs"rrr�sw��}H�}H��G�M�M�"�}H��}H��3��#�$�}H��	}H�
�}H��
}H�
�#�Y�}Hrc��.p.p/pV'g\VP44#V'dXVPR4FAp	\V	4p
V
'gKV
P	4'gK0VPV
4KC	M\
4p
VPV
4\V4^8d.#^pVF+p
V
P'gRWk,nV^,
pK-	^p.pVFMp
V
Pp
W�9d\P!R4.u#V
eVPV
4V^,
pKO	^pVF=p
V
P'g V
P'gRWk,nV^,
pK?	VFkp
V
P'dV
P:RV
P:2pMRV
P,pVP\P!W.44Km	VF�pVF~p
VPV
P4'gK&V
P'dW/,W�&M:V'd)W/,P!R4'dW/,W�&M
W/,W�&K�	K�	\#WW4#)r�rRz0Multiple nvidia versions passed at the same time�*z%s*r)r�r�r�r�rJr�r��lenr+rTrUr��extendr�r��__contains__r�r)r�r�r�rr�r�r-�allowr��itemr��it�vendors_tempr+r\rs&&&&&&          r�gpgpu_install_filterr!�s��#%�G��E�%'�F�"�F��F�K�K�M�"�"�� �%�%�c�*�D�+�D�1�F��v�&�/�/�+�+����v�&�+�������v��
�7�|�a���	�
�B����}�}�}�!)�G�K��
�a����
�B� �L��������!��M�M�L�M��I�������'�
�a����
�B����~�~�~�f�m�m�m�!)�G�K��
�a�������>�>�>�!'������?�G��v�}�}�-�G�
���W�^�^�H�6�7�����F��~�~�f�m�m�,�,��>�>�>� (��F�I�'�#�;�?�?�=�9�9�(0��F�I��$,�K��	���� $�E�<�G�Grc���V^8�dQhR\\P,R\R\\
\3,R\
R\R\R\\
,/#rr)rs"rrr@sn��:H�:H��G�M�M�"�:H��:H��3��#�$�:H��	:H�
�:H��
:H�
�#�Y�:Hrc�L�.ROpV'd\WW#RV4pV#.pVF(p	VP\P!W)44K*	/p
VFEpV'd1RW+,9gW+,R,'d
W+,W�&K9K;W+,W�&KG	\	W
W4#)a
Get packages which are appropriate for automatic installation.

Args:
    cache: The apt cache object used to check installed packages.
    include_dkms: Boolean indicating whether to include DKMS packages.
    packages: Dict of package candidates to consider for installation.
        Typically originates from system_driver_packages() or system_gpgpu_driver_packages(),
        and is filtered depending on the mode (desktop vs gpgpu) and user preferences.
    drivers_str: String specifying driver(s) and version(s) to filter for (optional).
    get_recommended: Boolean, if True only recommended packages are considered.
    gpgpu: Boolean flag indicating whether to use GPGPU (server) sorting preferences.

Returns:
    The subset of the given list of packages which are appropriate for
    automatic installation by the installer as a list. This applies to e.g. the Broadcom
    Wifi driver (as there is no alternative), but not to the FGLRX proprietary
    graphics driver (as the free driver works well and FGLRX does not provide
    KMS).
Tr)zbcmwl*z	pvr-omap*zvirtualbox-guest*znvidia-*zopen-vm-tools*r�r�zbroadcom-sta-dkms)r!rr�r�r)r�r�r�rr�r��	whitelist�resultsrr\r�rs&&&&&&      rr�r�@s���:	�I��&����e�
�����E���
���W�^�^�H�6�7���F�
����H�K�/�8�;�}�3M�3M�$�K��	�4N�!��F�I��$�E�<�G�Grc��V^8�dQhR\\P,R\\\
\,3,/#r�)rrxr�rr/r)rs"rrr}s6��D�D���
�
�&�D�	�#�t�C�y�.��Drc
�$�/p\PPRR4p\PP	V4'g\
P!RV4V#Vf\P!R4p\P!V4EFYpVPR4'gK\PPW$4p\
P!RV4/p\V4;_uu_4p\\!VP#4VR4V4VR,!V4p\
P!R	WX4TfRRR4K�\'T4\(\*39d.\
P!RT\'T44RRR4EKTF@p	Y	,p
\-Y
4'd$TP/T.4P1T	4K@KB	RRR4EK\	V# \d#p\
P!T4/uRp?#Rp?ii;i \d%\
P$!R
T4RRR4EK�i;i \2d\
P!RY�4K�i;i +'giEK�;i)
a9Get driver packages from custom detection plugins.

Some driver packages cannot be identified by modaliases, but need some
custom code for determining whether they apply to the system. Read all *.py
files in /usr/share/ubuntu-drivers-common/detect/ or
$UBUNTU_DRIVERS_DETECT_DIR and call detect(apt_cache) on them. Filter the
returned lists for packages which are available for installation, and
return the joined results.

If you already have an existing apt_pkg.Cache() object, you can pass it as an
argument for efficiency.

Return pluginname -> [package, ...] map.
�UBUNTU_DRIVERS_DETECT_DIRz(/usr/share/ubuntu-drivers-common/detect/z3Custom detection plugin directory %s does not existNz.pyz"Loading custom detection plugin %s�exec�detectzplugin %s return value: %szplugin %s failed:z6plugin %s returned a bad type %s (must be list or set)z.Ignoring unavailable package %s from plugin %s)r�rPr�r��isdirrTrUrxr�r�r��listdir�endswithr�r�r)rWr��	exception�typer�r�r�r�r�r�)r�r��	plugindirr��fnamer5�symbr�r�rr�s&          rr�r�}s��"&(�H��
�
���#�%O��I��7�7�=�=��#�#��
�
�K�Y�W�����	��
�
�d�+�I�
���I�&���~�~�e�$�$�������i�/���
�
�:�F�C�!��
�&�\�\�Q�
��W�Q�V�V�X�v�v�6��=��h��	�2���
�
�:�F�K�
�~���\��F�|�D�#�;�.��
�
�L����L��
�#�\�&���'�n�G�.�y�B�B� �+�+�E�2�6�=�=�c�B�C��'�\�'�H�O��Q�	��M�M�"���I��	�� �
��!�!�"5�v�>���\�

��& ���M�M�H�#����1�\�\�s�&G2�:I=�<AH"�I=�<I=�I=�#:I�I=�2H�=H�H�H�""I	�I=�I	�I=�"I:�6I=�9I:�:I=�=Jc�F�V^8�dQhR\R\\,/#�rr�r?r�)rs"rrr�s����s��x��}�rc��\PV4'd%\PV4PR4#R#)z5Look up driver package and return their support levelr6N�r�r��r�s&r�_pkg_support_from_cacher8�s2������������"�&�&�y�1�1�rc�0�V^8�dQhR\R\/#r4r5)rs"rrr�s����c��d�rc��\PV4'd%\PV4PR4#R#)z6Look up driver and return if open package is preferredr7Fr6r7s&r�_pkg_open_preferred_from_cacher;�s3������������"�&�&�'7�8�8�rc�0�V^8�dQhR\R\/#r4�r/rY)rs"rrr�s��
�
�c�
�c�
rc��\V4'd�\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#^#\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#^#)z4decide how well the package fits desktop environment�
(\d{3})-open$�(\d{3})$�(\d{3})-server-open$�(\d{3})-server$�r;rVr9r7s&r�_get_fit_levelrD�s���&�a�(�(�
�9�9�%�q�)�)��
�9�9�[�!�$�$��
�9�9�,�a�0�0��
�9�9�'��+�+��,�
��9�9�[�!�$�$��
�9�9�'��+�+��
�9�9�%�q�)�)��
�9�9�,�a�0�0��rc�0�V^8�dQhR\R\/#r4r=)rs"rrr�s��
�
�C�
�C�
rc��\V4'd�\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#^#\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#\P!RV4'd^#^#)z3decide how well the package fits server environmentrArBr?r@rCr7s&r�_get_fit_level_gpgpurG�s���&�a�(�(�
�9�9�,�a�0�0��
�9�9�'��+�+��
�9�9�%�q�)�)��
�9�9�[�!�$�$��%�
��9�9�'��+�+��
�9�9�[�!�$�$��
�9�9�,�a�0�0��
�9�9�%�q�)�)��rc�<�V^8�dQhR\R\R\/#�rr��yr?r=)rs"rrrs&��T
�T
�S�T
�S�T
�S�T
rc��VPR4'EdVPR4'Ed\V4\V48�d^#\V4\V48dR#RR.p^p^p\V4p\V4pWR9d
V^d,
pWb9d
V^d,
pW8�dV^,
pMW8d
V^,
pV^d8�gV^d8�dW48�d^#W48dR#\V4R8Xd\V4R8wd^#\V4R8wd\V4R8XdR#\V4R8Xd\V4R8wd^#\V4R8wd\V4R8XdR#\V4R8Xd\V4R8wdR#\V4R8wd\V4R8Xd^#\V4R8Xd\V4R8wdR#\V4R8wd\V4R8Xd^#\V4R8Xd\V4R8wdR#\V4R8wd\V4R8Xd^#W8dR#W8�d^#W8XgQh^#)a(Compare two graphics driver names in terms of preference. (desktop)

-open by default sorts after non-open, unless a driver preferes open variant
-server always sorts after non-server.
LTSB (Long Term Support Branch) always sorts before NFB (New Feature Branch).
Legacy always sorts before Beta.
rsr.r0r/r1�BetarC)r�rDr8)r�rJ�preferred_support�x_score�y_score�	x_support�	y_supports&&     rr�r�s��	�|�|�I���1�<�<�	�#:�#:��!��~�a�0�0���!��~�a�0�0��I�!�6�N������+�A�.�	�+�A�.�	��)��s�N�G��)��s�N�G��5��q�L�G�
�U��q�L�G��s�N��3��� ���"��	�"�1�%��-�2I�!�2L�PT�2T��"�1�%��-�2I�!�2L�PT�2T��I�#�A�&�&�0�'��*�f�4��#�A�&�&�0�'��*�f�4��I�"�1�%��.�3J�1�3M�QV�3V��I�"�1�%��.�3J�1�3M�QV�3V��#�A�&�(�2�'��*�h�6��I�#�A�&�(�2�'��*�h�6��#�A�&�&�0�'��*�f�4��I�#�A�&�&�0�'��*�f�4���u��	��u���6�M�6�rc�<�V^8�dQhR\R\R\/#rIr=)rs"rrrks!��<
�<
�3�<
�3�<
�3�<
rc��VPR4'Ed�VPR4'Ed�\V4\V48�d^#\V4\V48dR#\V4R8Xd\V4R8wd^#\V4R8wd\V4R8XdR#\V4R8Xd\V4R8wd^#\V4R8wd\V4R8XdR#\V4R8Xd\V4R8wdR#\V4R8wd\V4R8Xd^#\V4R8Xd\V4R8wdR#\V4R8wd\V4R8Xd^#\V4R8Xd\V4R8wdR#\V4R8wd\V4R8Xd^#W8dR#W8�d^#W8XgQh^#)a]Compare two graphics driver names in terms of preference. (server)

-open by default sorts after non-open, unless a driver preferes open variant
-server always sorts before non-server.
non server package always sorts after server package
LTSB (Long Term Support Branch) always sorts before NFB (New Feature Branch).
Legacy always sorts before Beta.
rsr.r0r1r/rLrC)r�rGr8)r�rJs&&rr�r�ks���	�|�|�I���1�<�<�	�#:�#:���"�%9�!�%<�<����"�%9�!�%<�<��I�"�1�%��-�2I�!�2L�PT�2T��"�1�%��-�2I�!�2L�PT�2T��I�#�A�&�&�0�'��*�f�4��#�A�&�&�0�'��*�f�4��I�#�A�&�(�2�'��*�h�6��I�#�A�&�(�2�'��*�h�6��"�1�%��.�3J�1�3M�QV�3V��I�"�1�%��.�3J�1�3M�QV�3V��#�A�&�&�0�'��*�f�4��I�#�A�&�&�0�'��*�f�4���u��	��u���6�M�6�rc�J�V^8�dQhR\\\3,RR/#)rr-r?N)rr/r()rs"rrr�s#����4��Z��0��T�rc
�V�VP4F�wrVR,F�pVPR4'dRRRRRRRR/VR,R	&K?VPR
4'gKJVR,FpRVR,V,R&K	RRRRRRRR/VR,R&K�	K�	R#)
zAdd builtin driver alternativesr-rRrTrrrFzxserver-xorg-video-nouveaurTzxserver-xorg-video-atiN)r�r�)r-�devicer�r�ds&    rr�r��s��� �
�
�����	�?�?�C��~�~�h�'�'��D��t�!�4�!�5�	A��Y�� <�=���~�~�g�&�&��i���A�8=�D��O�A�&�}�5�)��D��t�!�4�!�4�	=��Y�� 8�9��/#�(rc�D�V^8�dQhR\PR\/#r��rxr�r/)rs"rrr�s��<�<����<�3�<rc�N�\P!V4pVP4#)z0Return the linux headers for the system's kernel)r
�KernelDetection�get_linux_headers_metapackage�r��kernel_detections& r�get_linux_headersr_�s"��&�6�6�y�A���9�9�;�;rc�D�V^8�dQhR\PR\/#r�rY)rs"rrr�s��:�:�w�}�}�:��:rc�N�\P!V4pVP4#�z.Return the linux image for the system's kernel)r
r[�get_linux_image_metapackager]s& r�get_linux_imagerd�s"��&�6�6�y�A���7�7�9�9rc�Z�V^8�dQhR\PR\\,/#r�)rxr�rr/)rs"rrr�s"��0�0����0�8�C�=�0rc�N�\P!V4pVP4#rb)r
r[�get_linux_versionr]s& rrgrg�s"��&�6�6�y�A���-�-�/�/rc�D�V^8�dQhR\PR\/#r�rY)rs"rrr�s��4�4����4�3�4rc�N�\P!V4pVP4#)z4Return the linux metapackage for the system's kernel)r
r[�get_linux_metapackager]s& r�	get_linuxrk�s"��&�6�6�y�A���1�1�3�3rc�F�V^8�dQhR\R\\,/#)rrr?r�)rs"rrr�s����c��h�s�m�rc���\P!V4pVPW,4pTPPR4F,pTF#wrVpTPR4'gKTuu#	K.	R# \d"\P
!RT,4R#i;i \\3d"\P
!RT,4R#i;i)zNo candidate for %s foundNr��linux-image-z+Could not check dependencies for %s package)
rxr�r�r�rTrUr�r�r�r�)r�rr�r�r�r�r�r�s&&      r�get_linux_image_from_metaro�s������	�*�H���.�.�y�~�>�	�
M�!�2�2�6�6�y�A�H�-5�)��6��&�&�~�6�6�#�O�.6�B�&��1���
�
�1�C�7�8����
�i� �M��
�
�C�s�K�L��M�s.�A=�:B,�/B,�5B,�=(B)�(B)�,.C�Cc�F�V^8�dQhR\R\\,/#)rr�r?r�)rs"rrrs"��n�n��n���
�nrc��VfQhRpRpRp\P!V4p\V4pVP'g \P
!RV,4V#VP
4'd \P
!RV,4V#\V4p\W4pV'dVPRR4pM\P
!RV,4V#VP4p	RV	:RV:2p
W
,pVPV4pV'd�VPR	\439d�\V4p
RV	:RV
:2p\P
!R
V,4W,pVPV4pV'd;VPR	\439d \P
!RV,4T
pT'd�Y,P Uu.uFFpTP"P$P'R4'gK0TP"P$NKH	ppRp\T4PRR4pTR
8XdRpRT	:RT:2pTFpTT8XgKTpK	T'dTpT#RT	,p\P
!RT,4TT,pTPT4pT'dTPR	\439dTpT# \d\P
!RT
4ELGi;iuupi \d\P(!RT4T#i;i)zDReturn the linux-modules-$driver metapackage for the system's kernelNr:zNNon NVIDIA linux-modules packages are not supported at this time: %s. Skippingr�rnz-No linux-image can be found for %s. Skipping.zlinux-modules-nvidia-�-r�zlinux_modules_abi_candidate: %szFound ABI compatible %szNo "%s" can be found.�virtual�genericznvidia-dkms-%szFalling back to %s)rxr�r<rJrTrUrcrdror�rsr�r�rzrgr�r�r�rPr�r�)r�r�r8�
linux_flavour�linux_modules_matchr�rt�linux_image_meta�linux_imager��linux_modules_candidater�r��
linux_version�linux_modules_abi_candidate�abi_specific�abi_specific_candidater��reverse_deps�pick�candidate_suffix�modules_candidate�dkms_packages&&                     rrrs��� � � ��K��M������	�*�H�#�I�.�K������
�
�\��
�	
����+�+�-�-��
�
�=�	�I�J���&�y�1��+�I�H�K��#�+�+�N�B�?�
��
�
�E�	�Q�R���#�/�/�1������

��4��$�6�6�w�?���!2�!7�!7�E�<�>�;R�!R�-�i�8�M�!��+�'�
�M�M�1�5P�Q�
�%�A�L�%-�%?�%?��%M�"�%�*@�*E�*E����J�+��
�
�7�;V�W�X�&=�#��
!�5�F�F�
�F���~�~�"�"�-�-�.E�F�
 �C�N�N���F�	�
���*�9�5�=�=�n�b�Q���y�(�(�����
��
 �C��'�'��� ���K���$�&7�7�L��M�M�&�,�7�8�	
��L�)��$�6�6�w�?���!2�!7�!7�E�<�>�;R�!R�&�K�
���_�
��
�
�-�/F�G��
��
��D�
��
�
�-�|�<����	
�s7�?C	K*�$-L�L�)!L�L�*"L�L�"L>�=L>c�F�V^8�dQhR\R\\,/#)r�
grub_cfg_pathr?r�)rs"rrrqs����#��(�3�-�rc�v�\PPV4'g\P!RV4R#\VR4;_uu_4pVP
4uuRRR4# +'giR#;i \\3d%p\P!RT24Rp?R#Rp?ii;i)z�Load grub configuration file content.

Args:
    grub_cfg_path: Path to grub.cfg file (default: /boot/grub/grub.cfg)

Returns:
    String content of grub.cfg, or None if file doesn't exist or can't be read
z%Could not read %s in _load_grub_cfg()Nr�zError loading grub.cfg: $)	r�r��existsrTrUr�r�r^r�)r�r�r�s&  r�_load_grub_cfgr�qs~��	��w�w�~�~�m�,�,��M�M�A�=�Q��
�-��
%�
%���6�6�8�&�
%�
%�
%���W����
�
�1�!��5�6����s@�$B�B�B�A/�$
B�/B	�:B�B�B8�B3�3B8c�h�V^8�dQhR\\,R\R\\,/#)r�grub_content�	entry_numr?r�)rs"rrr�s1��Y�Y��3�-�Y�,/�Y�
�c�]�Yrc��V'gR#RpVPR4pRpVP4'Egr.pVEFpVP4PR4'd|RV,R,VP49gGRV,R,VP49g$RV,R,VP49dVP4pK�VP4PR4'gK�V'gK�\P
!W&4pV'd!VP
VP^44RpEK	\V4^8Xd
V^,#\V4^8�d\R	\V4,4R#\R
4R#.pVF�pVP4PR4'dVP4pK:VP4PR4'gKaV'gKk\P
!W&4pV'd!VP
VP^44RpK�	\V4p	^T	u;8:d\V48dMMW�,#\P!R4R# \\3d%p
\P!RT
24Rp
?
R#Rp
?
ii;i)
aParse grub configuration content to find kernel version for given entry.

Args:
    grub_content: Content of grub.cfg file as string
    entry_num: Entry identifier - either numeric index (as string) or entry ID

Returns:
    Kernel version string, or None if not found
Nzlinux\s+.*vmlinuz-([^\s]+)r��	menuentry� �'�"�linuxzCCould not determine which of the following kernels will boot next: zHCould not determine which kernel will boot next from /boot/grub/grub.cfgz:Could not determine kernel in _parse_grub_cfg_for_kernel()z'Error in _parse_grub_cfg_for_kernel() $)r��isdigitr�r�rVr9r�rZr�printr/rYrTrUr��
IndexError)r�r��vmlinuz_entry_regex�lines�
current_entry�matchesr�rX�menu_entries�	entry_idxr�s&&         r�_parse_grub_cfg_for_kernelr��s%����7��I��"�"�4�(���
�� � �"�"��G����:�:�<�*�*�;�7�7��9�_�s�*�t�z�z�|�;��i��#�-�$�*�*�,�>��i��#�-�$�*�*�,�>�$(�J�J�L�M��Z�Z�\�,�,�W�5�5�-�-��I�I�&9�@�E�����u�{�{�1�~�6�$(�M��"�7�|�q� ��q�z�!��W���!��Y��'�l�#����^������D��z�z�|�&�&�{�3�3� $�
�
��
�����(�(��1�1�m�m��	�	�"5�<��� �'�'����A��7� $�
���	�N�	��	�-�C��-�-��*�*��
�
�R�S����
�#���
�
�?��s�C�D����sP�)J"�C
J"�J"�AJ"�/+J"�J"�)A J"�J"�A1J"�
J"�"K�3K�Kc�F�V^8�dQhR\R\\,/#)rr�r?r�)rs"rrr�s��?�?�3�?�8�C�=�?rc�8�\4pVfR#\W4#)z�Convert grub entry number to kernel version by parsing grub.cfg.

Args:
    entry_num: Entry identifier - either numeric index (as string) or entry ID

Returns:
    Kernel version string, or None if not found
N)r�r�)r�r�s& r�_get_kernel_from_grub_entryr��s ��"�#�L����%�l�>�>rc�:�V^8�dQhR\\,/#r_r�)rs"rrr�s��1�1�(�3�-�1rc
�4�Rp\PPV4'g\P!R4R#\VR4;_uu_4pVEF�pVP
R4'gKVPR^4^,P4PR4pVP4'd\V4uuuRRR4#VR8Xd�R	p\PPV4'd�\VR4;_uu_4pVF�pVP
R
4'gKVPR^4^,P4pRV9d(VPR^4^,P4p\V4uuuRRR4uuuRRR4#	RRR4M\M[RV9d>\P!R
V4pV'dVP^4uuuRRR4#M\V4uuuRRR4#M	RRR4\P!R4R# +'giL4;i +'giL;;i \\3d%p	\P!RT	24Rp	?	R#Rp	?	ii;i)z@Get the actual grub default entry by checking grub configurationz/etc/default/grubz>Could not read /etc/default/grub in _get_actual_grub_default()Nr�z
GRUB_DEFAULT=r�z"'�savedz/boot/grub/grubenvzsaved_entry=�>zvmlinuz-zvmlinuz-([^\s]+)z%Error in _get_actual_grub_default() $)r�r�r�rTrUr�r�r�r�r�r�rVr9rZr^r�)
�grub_default_pathr�r��default_val�grubenv_path�f2�env_liner�rXr�s
          r�_get_actual_grub_defaultr��s��/�/���w�w�~�~�/�0�0��M�M�P�
��
�#�S�
)�
)�Q����?�?�?�3�3�"&�*�*�S�!�"4�Q�"7�"=�"=�"?�"E�"E�e�"L�K�"�*�*�,�,�:�;�G�G�*�
)�%��/�';���7�7�>�>�,�7�7�!%�l�C�!8�!8�B�02�H�'/�':�':�>�'J�'J�4<�N�N�3��4J�1�4M�4S�4S�4U�	�,/�)�+;�8@���s�A�8N�01�9.�.3�e�g�-6�0K�9�/U�(U�"9�!8�*�
)�13�"9�!8�8�$�{�2� "�	�	�*=�{� K�� �#(�;�;�q�>�1�7*�
)�4!� ;�;�G�G�=*�
)�>�=�*�B	�
�
�V�W��-"9�!8��*�
)��H
�W����
�
�=�a�S�A�B����s��&I"�I"�I"�I�5AI�I�
I"�-I�I�H<�9A!H<�I�&
I"�1H<�3/I�#I�5
I"�
I�
I"�I�I"�<I�I�I	�I"�"J�3J�Jc�\�V^8�dQhR\\,R\\,/#)r�kernel_versionr?r�)rs"rrr%	s$�� � ��S�M� �
�c�]� rc���V'g\P!R4R#RV2p\PP	V4'g\P!RVR24R#\
P!RVRRR	R
.R\
PR7pVP4PR
4pV'dV^,'d
V^,#\P!R4R#)z�Return the path to the NVIDIA kernel module for a given kernel version, if present.

Uses find to search for nvidia.ko* files in the kernel modules directory.
zGKernel not known, giving up on _resolve_nvidia_module_path_for_kernel()Nz
/lib/modules/zModule directory z does not existr[z-namez
nvidia.ko*z-typer�T)rgrWr�z6_resolve_nvidia_module_path_for_kernel() returned None)
rTrUr�r�r�rYrk�DEVNULLr�r�)r��modules_dirr�r�s&   r�&_resolve_nvidia_module_path_for_kernelr�%	s�����
�
�U�	
��!�.�!1�2�K�
�7�7�>�>�+�&�&��
�
�)�+��o�F�G���
$�
$�	��g�|�W�c�B���!�!��F��l�l�n�"�"�4�(�G��7�1�:�:��q�z���M�M�J�K�rc�F�V^8�dQhR\\\3,/#r_�rr/r)rs"rrrH	s��L�L�D��c��N�Lrc�P�RRRRRRRRRRRR/p\P!R	.R
R7pRVR&VP4F2pVP4pV'gKV^,R8XgK-R
VR&M	VR,'dw\P!RR.R
R7pVP4FFpVPR4'gKVPR^4^,P4VR&M	\4VR&VR,'gRVR&RVR&RVR&V#\P!4Pp\VR,;'d
VR,V8g4VR&\VR,4pV'dWpR&V#R
VR&RVR,/VR&V# \P\
3d%p\P!R
T24Rp?ELiRp?ii;i \P\
3d%p\P!RT24Rp?EL&Rp?ii;i)aBCheck NVIDIA module status and kernel compatibility.

Returns:
    dict: Contains information about NVIDIA module status:
        - 'loaded': bool - Whether nvidia module is currently loaded
        - 'current_module_path': str or None - Path to current nvidia module
        - 'next_boot_kernel': str or None - Next boot kernel version
        - 'next_boot_module_path': str or None - Path to nvidia module for next boot kernel
        - 'needs_reboot': bool - Whether a reboot is needed
        - 'module_missing': bool - Whether nvidia module is missing for next boot kernel
�loadedF�current_module_pathN�next_boot_kernel�next_boot_module_path�needs_reboot�module_missing�lsmodTrfrRz#Exception in loaded module check: $rUz	filename:r�z!Exception in module path check: $�checked_kernel�
debug_info)rYrkrlr�r`r_rTrUr�r�r�r��uname�releaserr�)r��lsmod_outputr��partsr��modinfo_output�current_kernel�	next_paths        r�check_nvidia_module_statusr�H	s5��	�%��t��D������%�
�F�

�!�.�.��y�T�R�� ��x�� �+�+�-�D��J�J�L�E��u��q��X�-�#'��x� ��
.��h���
	�'�4�4��H�%�$��N�'�1�1�3���?�?�;�/�/�48�J�J�s�A�4F�q�4I�4O�4O�4Q�F�0�1��4�":�!;�F����$�%�%�!&��~��#(��� �*.��&�'��
��X�X�Z�'�'�N�!��!�"�S�S�v�.@�'A�^�'S��F�>��
7�v�>P�7Q�R�I��*3�&�'��M�	$(��� � 0�&�9K�2L�M��|���M��U
�)�)�+<�=�
��
�
�;�A�3�?�@���
���-�-�/@�A�	��M�M�=�a�S�A�B���	�sO�AF$�F$�+F$�2F$�AG&�+G&�7G&�$G#�?G�G#�&H%�H � H%c�F�V^8�dQhR\\\3,/#r_r�)rs"rrr�	s��,�,�$�s�C�x�.�,rc
���RRR.R.RRRR/p\P!4\P!4\P!R4p\
TR4;'g
\
TR4TR&\
TR	4TR&TR,'d\4TR&T#T# \dp\T4TR&TuRp?#Rp?ii;i \dp\T4TR&Rp?T#Rp?ii;i)
a�Gather data for the welcome page.

Returns:
    dict: A dictionary containing:
        - cache_error: Error message if cache couldn't be loaded, or None
        - nvidia_drivers: List of installed NVIDIA driver packages
        - oem_packages: List of installed OEM packages
        - nvidia_status: NVIDIA module status dict, or None if not applicable
        - nvidia_status_error: Error message if status check failed, or None
�cache_errorN�nvidia_drivers�oem_packages�
nvidia_status�nvidia_status_errorznvidia-driver-*zlinux-modules-nvidia-*r�)rx�init_config�init_systemr�r�r/r�r�)�datar�r�r�s    r�gather_welcome_page_datar��	s��	�t��"������t��D�����������
�
�d�#��<�
� ��I�I�	'��/G�	H�	�	��
:�%��N�D�������	1�$>�$@�D��!��K�4�K��'��!�"�g��]������� �	1�*-�a�&�D�&�'��K��	1�s5�B!�
C	�!C�,C�;C�C�	C-�C(�(C-ra)NNFT)NNTrj)NNF)NFTr:Fr�)TT)r:TF)z/boot/grub/grub.cfg)Wr!r�rTr�rYr�rVr��typingrrrrrrrr	rx�
UbuntuDriversr
rr(r2rwr�r��objectr<rzr�r�r�r�r�rrrr$r*r2r:rJrQrarprurr�rr�r�r�r�r�r�r�r�r�r�r�r�r
rrr!r�r�r8r;rDrGr�r�r�r_rdrgrkrorr�r�r�r�r�r�r�rrr�<module>r�s���M�
�����	��C�C�C� ��)���%����%��
�)�5�
� ����>��J��J�Z�-�`E�P;�|&��>'(�T�:	��<�8�:!�H
�6�(�V�@�$
�c�L��D#�LB�JR�j^�B&�,�.�:�:�6�:�" �F�.[�|�,8�v}H�@:H�zD�N��
�B
�BT
�n<
�~�<<�:�0�4��@n�b�*Y�x?�1�h �FL�^,r

Youez - 2016 - github.com/yon3zu
LinuXploit