
    Zuf                     n   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ZefdZedk(  r ej                         d k(  s e
d        e j                  d       de j                  d <    ej                  ej                  d	d
        ej                  de j                  d    z         ej                   j#                  e      s$ ej                  d        e j                  d        ej                   j%                  e      d k(  r6 ej                  d        ej&                  e        e j                  d        edz    ej(                  d      z   Z ej,                  dez          ej.                  ee       dZ	  ed      D  cg c]  } | j5                         d     c} ZeD ]  Zedk(  s	dZ n esA ee      5 Zdej?                         v r ej                  dez          ed       ddd       yyyc c} w # e$ r'  ej                  d        e j                  d        Y w xY w# 1 sw Y   yxY w)    Nz/etc/X11/xorg.confc           
         t         j                  j                  |      st        j                  d|z         yg }t        |      5 }|D ]  }|j                  d      d   j                         }|j                         j                  d      re|j                  d| z        rQt        j                  d|j                         z         d|z  }t        j                  d	|j                         z         |j                  |        	 ddd       t        |      5 }|j                         |k7  rpt        j                  d
|d| d|d       t        |dz   d      5 }|j!                  dj#                  |             ddd       t        j$                  |dz   |       ddd       y# 1 sw Y   xY w# 1 sw Y   7xY w# 1 sw Y   yxY w)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'saving new z (z -> )	.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_files           B/usr/lib/python3/dist-packages/DistUpgrade/xorg_fix_proprietary.pyreplace_driver_from_xorgr,      s   
 77>>$+d23G	d 
!y 		!D

3"((*A	$$X.JJv
23/$++-?@)J63dkkmCDNN4 		!
! 
d 0y G+LL
J8 9d[(#. 6-##BGGG$456IId[($/0 0
! 
! 6 6	0 0s2   B?F&AF>!F2<!F>&F/2F;	7F>>Gc                    t         j                  j                  |      st        j                  d|z         yg }t        |      5 }|D ]  }|j                  d      d   j                         }|j                         j                  d      re|j                  d| z        rQt        j                  d|j                         z         d|z  }t        j                  d	|j                         z         |j                  |        	 ddd       t        |      5 }|j                         |k7  rmt        j                  d
|d| d       t        |dz   d      5 }|j!                  dj#                  |             ddd       t        j$                  |dz   |       ddd       y# 1 sw Y   xY w# 1 sw Y   7xY w# 1 sw Y   yxY w)z3
    this comments out a driver from xorg.conf
    r   Nr   r   r   r   r   z#%sr	   r
   z (commenting r   r   r   r   r   )r#   r%   r&   r'   r(   r)   r*   s          r+   comment_out_driver_from_xorgr.   .   s|    77>>$+d23G	d 
!y 		!D

3"((*A	$$X.JJv
23/$++-?@t|3dkkmCDNN4 		!
! 
d 0y G+LL
, -d[(#. 6-##BGGG$456IId[($/0 0
! 
! 6 6	0 0s1   B?F#?F;!F/9!F;#F,/F8	4F;;G__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'Fz/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   copyr4   r   r   modsIOErrormxorg_conf_fileread)r(   s   0r+   <module>rJ      s5    	    !	 ;D 0< 3< 0: z299;!#$ 0CHHQK Ggmm!G!$& GLL+,77>>)$,- 
wwy!Q&78		) ))MDMM,,GGFGMM(612FKK	6"F,0,ABD

QB  =F
 )_ 	7>..006BC,X6	7 	7 U B C /0	7 	7s0   ;
G< G7G< <0H+7G< <)H('H(+H4