o
    过h                     @   s  d dl Z d dlZd dlZd dlZd dlZdZefddZefddZedkre	 d ks5e
d e d	 d
e jd < ejejddd ede jd    ejes]ed e d  ejed krted ee e d  ed ed Zede  eee dZzdd edD ZW n ey   ed e d  Y nw eD ]
ZedkrdZ nqesee"Zde v rede  ed W d   dS W d   dS 1 sw   Y  dS dS dS )    Nz/etc/X11/xorg.confc              	   C   sd  t j|std|  dS g }t|?}|D ]4}|dd  }| 	drG|
d|  rGtd|   d| }td	|   || qW d   n1 sWw   Y  t|H}| |krtd
|| |f  t|d d}|d| W d   n1 sw   Y  t |d | W d   dS W d   dS 1 sw   Y  dS )zf
    this removes old_driver driver from the xorg.conf and substitutes it with
    the new_driver
    file %s not foundN#r   driver"%s"line '%s' foundz	Driver	"%s"
replacing with '%s'zsaving new %s (%s -> %s)	.xorg_fixw ospathexistsloggingwarningopensplitstriplower
startswithendswithdebugrstripappend	readlinesinfowritejoinrename)
old_driver
new_driverxorgcontent	xorg_filelinesxorg_fix_file r'   B/usr/lib/python3/dist-packages/DistUpgrade/xorg_fix_proprietary.pyreplace_driver_from_xorg   s8   

"r)   c              	   C   sb  t j|std|  dS g }t|?}|D ]4}|dd  }| 	drG|
d|  rGtd|   d| }td	|   || qW d   n1 sWw   Y  t|G}| |krtd
|| f  t|d d}|d| W d   n1 sw   Y  t |d | W d   dS W d   dS 1 sw   Y  dS )z3
    this comments out a driver from xorg.conf
    r   Nr   r   r   r   r   z#%sr   zsaving new %s (commenting %s)r   r	   r
   r   )r   r!   r"   r#   r$   r%   r&   r'   r'   r(   comment_out_driver_from_xorg.   s8   

"r*   __main__zNeed to run as root   z/usr/bin/do-release-upgradez$/var/log/dist-upgrade/xorg_fixup.logr	   )levelfilenamefilemodez
%s runningzNo xorg.conf, exitingz xorg.conf is zero size, removingz.dist-upgrade-z
%Y%m%d%H%Mzcreating backup '%s'Fc                 C   s   g | ]}|  d  qS )r   )r   ).0r$   r'   r'   r(   
<listcomp>l   s    r1   z/proc/moduleszCan't read /proc/modulesnvidiaTzRemoving nvidia from %s)sysr   r   timeshutil	XORG_CONFr)   r*   __name__getuidprintexitargvbasicConfigDEBUGr   r   r   getsizeremovestrftimebackupr   copyr2   r   modsIOErrormxorg_conf_filereadr'   r'   r'   r(   <module>   sd   









"*