7ec@sddlZddlZddlZddlTddlZejjZeZej jZ da dZ ejdZdZdZdZdZed kre ndS( iN(t*cCspdtjd}y#tjtjdd\}}Wn;tjk rq}t|dt|tjdnXx)|D]!\}}|dkry|aqyqyWt stddks| rtd t|tjdnd}xv|D]n}tjj |rt |r[d}q[qtjj |rFt|d d}qt |rd}qqWtj|dS( Ns0usage: %s -i /interpreter file-or-directory ... iisi:s is-it/s'-i option or file-or-directory missing s": will not process symbolic links ( tsystargvtgetoptterrorterrtexittnew_interpretertostpathtisdirt recursedowntislinktfix(tusagetoptstargstmsgtotatbadtarg((s-/usr/lib64/python2.7/Tools/scripts/pathfix.pytmain"s4#         s^[a-zA-Z0-9_]+\.py$cCstj|dkS(Ni(t ispythonprogtmatch(tname((s-/usr/lib64/python2.7/Tools/scripts/pathfix.pytispython?scCs1td|fd}ytj|}Wn+tjk rW}td||fdSX|jg}x|D]}|tjtjfkrqontjj ||}tjj |rqotjj |r|j |qot |rot|rd}qqoqoWx#|D]}t|rd}qqW|S(Nsrecursedown(%r) is%s: cannot list directory: %r i(tdbgR tlistdirRRtsorttcurdirtpardirR tjoinR R tappendRRR (tdirnameRtnamesRtsubdirsRtfullname((s-/usr/lib64/python2.7/Tools/scripts/pathfix.pyR Bs0      c Cs<yt|d}Wn(tk r=}td||fdSX|j}t|}||kr~t|d|jdStjj |\}}tjj |d|}yt|d}Wn2tk r}|jtd||fdSXt|d|j |d} x*|j | } | s4Pn|j | qW|j|jy+tj |} tj|| td @Wn*tjk r}td ||fnXytj||d Wn*tjk r}td||fnXytj||Wn+tjk r7}td||fdSXdS(Ntrs%s: cannot open: %r is : no change t@tws%s: cannot create: %r s : updating iiis%s: warning: chmod failed (%r) t~s %s: warning: backup failed (%r) s%s: rename failed (%r) ii (topentIOErrorRtreadlinetfixlinetreptcloseR R tsplitR!twritetreadtstattchmodtST_MODERtrename( tfilenametfRtlinetfixedtheadttailttempnametgtBUFSIZEtbuftstatbuf((s-/usr/lib64/python2.7/Tools/scripts/pathfix.pyRXsX        cCs+|jds|Sd|kr#|SdtS(Ns#!tpythons#! %s (t startswithR(R:((s-/usr/lib64/python2.7/Tools/scripts/pathfix.pyR.s  t__main__(RtreR R4RtstderrR2RRtstdoutR/tNoneRRtcompileRRR RR.t__name__(((s-/usr/lib64/python2.7/Tools/scripts/pathfix.pyts           5