MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyc
�
d�bc@s�dZddlZddlZddlZddlZddlZddlZddljj	Z	ddl
jjjZddl
mZejejejejejejejdgZeedd�Zeded�Zedd�Zd	�Zd
�Zddd�Zd�Zd
�Z d�Z!d�Z"d�Z#ed�Z$d�Z%d�Z&d�Z'd�Z(d�Z)dd�Z*dS(s
File operation util functions
i����N(tustriysutf-8cCsvd}t||��[}|j�}|dkr4dS|r>|S|rVtj|�}nt|d|�}|SWdQXdS(s1
    Read and return contents of 'filepath'.
    trbtencodingN(topentreadtNonettextutilt
remove_bomR(tfilepathtasbinRRtmodetin_filetdata((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyt	read_file0scCsY|rdnd}|}|s0|j|�}nt||��}|j|�WdQXdS(s)
    Write 'contents' to 'filepath'.
    tabtwbN(tencodeRtwrite(RtcontentsR	RtappendR
Rtout_file((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyt
write_fileDsc	Cs#t||d|d|dt�dS(s*
    Append 'contents' to 'filepath'.
    R	RRN(RtTrue(RRR	R((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytappend_filePscCstjj|�\}}|S(N(tostpathtsplit(Rtheadttail((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyt	base_nameWscCs7x0t|�jd�D]}|j|�r|SqWdS(sE
    Return line from 'filepath' if the line startswith 'prefix'
    s
N(R
Rt
startswithR(tprefixRtline((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytget_line_startingwith\scCs^tjj|�s"tj|�n|dk	r>t||�n|dk	rZt||�ndS(N(RRtisdirtmakedirsRtchmodtchowner(tdirpathR
towner((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytmkdirfscCsYtjj|�s+tjdj|��n*tj|�}tj||d|d�dS(NsPath does not exist: {0}ii(	RRtexiststloggerterrortformattpwdtgetpwnamtchown(RR't
owner_info((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyR%oscCs?tjj|�s+tjdj|��ntj||�dS(NsPath does not exist: {0}(RRR)R*R+R,R$(RR
((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyR$wscGsQxJ|D]B}x9tj|�D](}tjj|�rtj|�qqWqWdS(N(tglobRRtisfiletremove(targstpathsR((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytrm_files~s
cGs�x�|D]�}tjj|�s%qnx�tj|�D]�}tjj||�}tjj|�rrtj|�q5tjj|�r�tj|�q5tjj|�r5t	j
|�q5q5WqWdS(s/
    Remove the contents of each directory
    N(RRR"tlistdirtjoinR2R3tislinktunlinktshutiltrmtree(R4tptppR((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytrm_dirs�s
cCs@|jd�sd|}n|j|�r<|j|�dS|S(Nt.i(RtendswithR(Rtext((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyttrim_ext�s
cCs�g}tjj|�r7|r7tdj|���nt|�jd�}g|D]:}|dk	rSt|�dkrS|j	|�rS|^qS}|j
|�t|dj|�d�dS(NsCan't find config file:{0}s
i(
RRR2tIOErrorR,R
RRtlenRRRR8(Rt
line_starttvaltchk_errtconftx((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytupdate_conf_file�s
:
cCsWxPtj|�D]?\}}}x-|D]%}||kr&tjj||�Sq&WqWdS(N(RtwalkRR8R(ttarget_dir_namettarget_file_nametroottdirstfilest	file_name((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytsearch_file�s

cCsWxPtj|�D]?\}}}x-|D]%}tjtjj||�|�q&WqWdS(N(RRLR$RR8(RR
RORPRQRR((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyt
chmod_tree�s
cCsayIt|d��4}x*|j�D]}||j�kr"tSq"WWdQXWntk
r\nXtS(sh
    Return True if the line is in the file; False otherwise.
    (Trailing whitespace is ignored.)
    trN(Rt	readlinestrstripRt	ExceptiontFalse(t	file_pathtline_strtfhR ((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytfindstr_in_file�s
cCsly^t|d��I}tj|�}x0|j�D]"}tj||�}|r1|Sq1WWdQXWnnXdS(s/
    Return match object if found in file.
    RUN(RtretcompileRVtsearchR(RZtline_reR\tpatternR tmatch((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pytfindre_in_file�scCs\g}xOtj|�D]>\}}}|jg|D]}tjj||�^q2�qW|S(s2
    Find all files under the given root path
    (RRLtextendRR8(t	root_pathtresultRORPRQtfile((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyt
get_all_files�s3cCs�|dkrg}nt|t�r�|jtkr�xp|D]e}|dkrRq:ny9tjj|�r}tj	|dt
�n
tj|�Wq:tk
r�q:Xq:WndS(s�
    Clean-up possibly bad files and directories after an IO error.
    The code ignores *all* errors since disk state may be unhealthy.
    t
ignore_errorsN(
Rt
isinstanceRDterrnotKNOWN_IOERRORSRRR"R;R<RR3RX(teR5R((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyt
clean_ioerror�s	

(+t__doc__RlR1RR-R^R;tazurelinuxagent.common.loggertcommonR*t%azurelinuxagent.common.utils.textutiltutilsRtazurelinuxagent.common.futureRtEIOtENOMEMtENFILEtEMFILEtENOSPCtENAMETOOLONGtELOOPRmRYR
RRRR!RR(R%R$R6R?RCRKRSRTR]RdRiRo(((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/fileutil.pyt<module>sF