%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/utils/find.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZyddlZddlZWnek
r�nXddlmZddlZddlZddlZddlZddlZddlmZeje�ZdZdZ d	Z!iej"d
6ej#d6ej$d6ej%d
6ej&d6ej'd6ej(d6d
ej"6dej#6dej$6d
ej%6dej&6dej'6dej(6Z)ej*ddej+�Z,ej-j.ej-j/ej-j0fZ1d�Z2d�Z3de4fd��YZ5de5fd��YZ6de5fd��YZ7de5fd��YZ8de5fd��YZ9de5fd ��YZ:d!e5fd"��YZ;d#e5fd$��YZ<d%e5fd&��YZ=d'e5fd(��YZ>d)e5fd*��YZ?d+e5fd,��YZ@d-e:fd.��YZAd/e5fd0��YZBd1e4fd2��YZCd3�ZDd4�ZEd5�ZFed6kr�eF�ndS(7u�	
Approximate the Unix find(1) command and return a list of paths that
meet the specified criteria.

The options include match criteria:
    name    = file-glob                 # case sensitive
    iname   = file-glob                 # case insensitive
    regex   = file-regex                # case sensitive
    iregex  = file-regex                # case insensitive
    type    = file-types                # match any listed type
    user    = users                     # match any listed user
    group   = groups                    # match any listed group
    size    = [+-]number[size-unit]     # default unit = byte
    mtime   = interval                  # modified since date
    grep    = regex                     # search file contents
and/or actions:
    delete [= file-types]               # default type = 'f'
    exec    = command [arg ...]         # where {} is replaced by pathname
    print  [= print-opts]
and/or depth criteria:
   maxdepth = maximum depth to transverse in path
   mindepth = minimum depth to transverse before checking files or directories

The default action is 'print=path'.

file-glob:
    *                = match zero or more chars
    ?                = match any char
    [abc]            = match a, b, or c
    [!abc] or [^abc] = match anything except a, b, and c
    [x-y]            = match chars x through y
    [!x-y] or [^x-y] = match anything except chars x through y
    {a,b,c}          = match a or b or c

file-regex:
    a Python re (regular expression) pattern

file-types: a string of one or more of the following:
    a: all file types
    b: block device
    c: character device
    d: directory
    p: FIFO (named pipe)
    f: plain file
    l: symlink
    s: socket

users:
    a space and/or comma separated list of user names and/or uids

groups:
    a space and/or comma separated list of group names and/or gids

size-unit:
    b: bytes
    k: kilobytes
    m: megabytes
    g: gigabytes
    t: terabytes

interval:
    [<num>w] [<num>[d]] [<num>h] [<num>m] [<num>s]

    where:
        w: week
        d: day
        h: hour
        m: minute
        s: second

print-opts: a comma and/or space separated list of one or more of
the following:

    group: group name
    md5:   MD5 digest of file contents
    mode:  file permissions (as as integer)
    mtime: last modification time (as time_t)
    name:  file basename
    path:  file absolute path
    size:  file size in bytes
    type:  file type
    user:  user name
i(tabsolute_importtprint_functiontunicode_literalsN(tPopentPIPE(tsix(tBufferedReaderiiiubucudufulupusu
                             ^\s*
                             (?P<modifier>[+-]?)
                             (?: (?P<week>   \d+ (?:\.\d*)? ) \s* [wW]  )? \s*
                             (?: (?P<day>    \d+ (?:\.\d*)? ) \s* [dD]  )? \s*
                             (?: (?P<hour>   \d+ (?:\.\d*)? ) \s* [hH]  )? \s*
                             (?: (?P<minute> \d+ (?:\.\d*)? ) \s* [mM]  )? \s*
                             (?: (?P<second> \d+ (?:\.\d*)? ) \s* [sS]  )? \s*
                             $
                             tflagscC@s�tjtj|��}|d
kr<tdj|���nd}d
}xddddfddfd
dfgD]V\}}|j|�d
k	rp|t|j|��|7}|d
kr�|}q�qpqpW|||jd�fS(u

    Convert an interval string like 1w3d6h into the number of seconds, time
    resolution (1 unit of the smallest specified time unit) and the modifier(
    '+', '-', or '').
        w = week
        d = day
        h = hour
        m = minute
        s = second
    uinvalid time interval: '{0}'iusecondiuminutei<uhourudayiuweekiumodifierN(usecondi(uminutei<iii�Qii�Qi�:	(	t_INTERVAL_REGEXtmatchRt	text_typetNonet
ValueErrortformattgrouptfloat(tvalueR	tresultt
resolutiontnamet
multiplier((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyt_parse_interval�s		cC@sp|j�}|jd�r2|d}|d}nd}t|�dkr�idd6dd	6dd6dd
6dd6j|dj��}|r�|d j�}q�d}nd}yt|�|}WnTtk
rytt|�|�}Wqtk
rtdj|���qXnX|dkr4d}|}n2|dkrR|}t	j
}n|}||d}||fS(Nu-u+iiu=iubi
ukiumiugi(uti����uinvalid size: "{0}"(u-u+iiii@I(tstript
startswithtlentgettlowertintRRR
RtMAXSIZE(RtscalartstyleRtnumtmin_sizetmax_size((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyt_parse_size�s>


	

	tOptioncB@seZdZd�ZRS(u3
    Abstract base class for all find options.
    cC@stS(N(t_REQUIRES_PATH(tself((s3/usr/lib/python2.7/site-packages/salt/utils/find.pytrequires�s(t__name__t
__module__t__doc__R&(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR#�st
NameOptioncB@s eZdZd�Zd�ZRS(u�
    Match files with a case-sensitive glob filename pattern.
    Note: this is the 'basename' portion of a pathname.
    The option name is 'name', e.g. {'name' : '*.txt'}.
    cC@s>tj|jdd�jdd�jdd�d�|_dS(Nu.u\.u?u.?u*u.*u$(tretcompiletreplacetregex(R%tkeyR((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyt__init__�scC@s|jj|�S(N(R.R	(R%tdirnametfilenametfstat((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	�s(R'R(R)R0R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR*�s	tInameOptioncB@s eZdZd�Zd�ZRS(u�
    Match files with a case-insensitive glob filename pattern.
    Note: this is the 'basename' portion of a pathname.
    The option name is 'iname', e.g. {'iname' : '*.TXT'}.
    cC@sDtj|jdd�jdd�jdd�dtj�|_dS(Nu.u\.u?u.?u*u.*u$(R+R,R-t
IGNORECASER.(R%R/R((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0�s
cC@s|jj|�S(N(R.R	(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	s(R'R(R)R0R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR4�s	tRegexOptioncB@s eZdZd�Zd�ZRS(u�
    Match files with a case-sensitive regular expression.
    Note: this is the 'basename' portion of a pathname.
    The option name is 'regex', e.g. {'regex' : '.*\.txt'}.
    cC@sFytj|�|_Wn)tjk
rAtdj|���nXdS(Nu!invalid regular expression: "{0}"(R+R,R.terrorRR
(R%R/R((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0scC@s|jj|�S(N(R.R	(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	s(R'R(R)R0R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR6s	tIregexOptioncB@s eZdZd�Zd�ZRS(u�
    Match files with a case-insensitive regular expression.
    Note: this is the 'basename' portion of a pathname.
    The option name is 'iregex', e.g. {'iregex' : '.*\.txt'}.
    cC@sLytj|tj�|_Wn)tjk
rGtdj|���nXdS(Nu!invalid regular expression: "{0}"(R+R,R5R.R7RR
(R%R/R((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0scC@s|jj|�S(N(R.R	(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	$s(R'R(R)R0R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR8s	t
TypeOptioncB@s)eZdZd�Zd�Zd�ZRS(u�
    Match files by their file type(s).
    The file type(s) are specified as an optionally comma and/or space
    separated list of letters.
        b = block device
        c = character device
        d = directory
        f = regular (plain) file
        l = symbolic link
        p = FIFO (named pipe)
        s = socket
    The option name is 'type', e.g. {'type' : 'd'} or {'type' : 'bc'}.
    cC@s�dj|j�jdd�j��}t�|_xO|D]G}y|jjt|�Wq:tk
r�t	dj
|���q:Xq:WdS(Nuu,uinvalid file type "{0}"(tjoinRR-tsplittsettftypestaddt_FILE_TYPEStKeyErrorRR
(R%R/Rtftype((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR06s'

cC@stS(N(t_REQUIRES_STAT(R%((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR&@scC@stj|tj�|jkS(N(tstattS_IFMTtST_MODER=(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	Cs(R'R(R)R0R&R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR9(s
	
	tOwnerOptioncB@s)eZdZd�Zd�Zd�ZRS(u
    Match files by their owner name(s) and/or uid(s), e.g. 'root'.
    The names are a space and/or comma separated list of names and/or integers.
    A match occurs when the file's uid matches any user specified.
    The option name is 'owner', e.g. {'owner' : 'root'}.
    cC@s�t�|_x�|jdd�j�D]t}|j�rP|jjt|��q%y |jjtj|�j	�Wq%t
k
r�tdj|���q%Xq%WdS(Nu,u uno such user "{0}"(
R<tuidsR-R;tisdigitR>Rtpwdtgetpwnamtpw_uidR@RR
(R%R/RR((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0Ns 
cC@stS(N(RB(R%((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR&YscC@s|tj|jkS(N(RCtST_UIDRG(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	\s(R'R(R)R0R&R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyRFGs		tGroupOptioncB@s)eZdZd�Zd�Zd�ZRS(u
    Match files by their group name(s) and/or uid(s), e.g. 'admin'.
    The names are a space and/or comma separated list of names and/or integers.
    A match occurs when the file's gid matches any group specified.
    The option name is 'group', e.g. {'group' : 'admin'}.
    cC@s�t�|_x�|jdd�j�D]t}|j�rP|jjt|��q%y |jjtj|�j	�Wq%t
k
r�tdj|���q%Xq%WdS(Nu,u uno such group "{0}"(
R<tgidsR-R;RHR>Rtgrptgetgrnamtgr_gidR@RR
(R%R/RR((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0gs 
cC@stS(N(RB(R%((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR&rscC@s|tj|jkS(N(RCtST_GIDRN(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	us(R'R(R)R0R&R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyRM`s		t
SizeOptioncB@s)eZdZd�Zd�Zd�ZRS(u�
    Match files by their size.
    Prefix the size with '-' to find files the specified size and smaller.
    Prefix the size with '+' to find files the specified size and larger.
    Without the +/- prefix, match the exact file size.
    The size can be suffixed with (case-insensitive) suffixes:
        b = bytes
        k = kilobytes
        m = megabytes
        g = gigabytes
        t = terabytes
    The option name is 'size', e.g. {'size' : '+1G'}.
    cC@st|�\|_|_dS(N(R"R R!(R%R/R((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0�scC@stS(N(RB(R%((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR&�scC@s%|j|tjko"|jkSS(N(R RCtST_SIZER!(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	�s(R'R(R)R0R&R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyRSys
		tMtimeOptioncB@s)eZdZd�Zd�Zd�ZRS(u�
    Match files modified since the specified time.
    The option name is 'mtime', e.g. {'mtime' : '3d'}.
    The value format is [<num>w] [<num>[d]] [<num>h] [<num>m] [<num>s]
    where num is an integer or float and the case-insensitive suffixes are:
        w = week
        d = day
        h = hour
        m = minute
        s = second
    Whitespace is ignored in the value.
    cC@sCt|�\}}}tj�t||�||_||_dS(N(RttimeRtmtimetmodifier(R%R/RtsecsRRX((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0�s!cC@stS(N(RB(R%((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR&�scC@s;|jdkr#|tj|jkS|tj|jkSdS(Nu-(RXRCtST_MTIMERW(R%R1R2R3((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	�s(R'R(R)R0R&R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyRU�s		t
GrepOptioncB@s)eZdZd�Zd�Zd�ZRS(uuMatch files when a pattern occurs within the file.
    The option name is 'grep', e.g. {'grep' : '(foo)|(bar}'}.
    cC@sFytj|�|_Wn)tjk
rAtdj|���nXdS(Nu!invalid regular expression: "{0}"(R+R,R.R7RR
(R%R/R((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0�scC@sttBS(N(t_REQUIRES_CONTENTSRB(R%((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR&�scC@sutj|tj�sdStjj||�}t|dd��.}x$|D]}|jj	|�rK|SqKWWdQXdS(Ntmodeurb(
RCtS_ISREGRERtostpathR:RR.tsearch(R%R1R2R3t	dfilenametbreadtchunk((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR	�s
(R'R(R)R0R&R	(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR[�s		tPrintOptioncB@s,eZdZd�Zd�Zed�ZRS(u�
    Return information about a matched file.
    Print options are specified as a comma and/or space separated list of
    one or more of the following:
        group  = group name
        md5    = MD5 digest of file contents
        mode   = file mode (as integer)
        mtime  = last modification time (as time_t)
        name   = file basename
        path   = file absolute path
        size   = file size in bytes
        type   = file type
        user   = user name
    cC@s�t|_t|_g|_xH|jdd�j�D].}|jj|�|dkr4t|_q4q4Wt|j�dkr�|jjd�ndS(Nu,u unameupathi(unameupath(	tFalset	need_stattprint_titletfmtR-R;tappendtTrueR(R%R/Rtarg((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0�s			cC@s|jr
tStS(N(RgRBR$(R%((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR&�sc	C@sBg}x|jD]}|dkr2|j|�q|dkrZ|jtjj|��q|dkr}|j|tj�q|dkr�|jtjtj	|tj
�d��q|dkr�|jtt|tj
�dd��q|d	kr|j|tj
�q|d
krh|tj}y|jtj|�j�Wqtk
rd|j|�qXq|dkr�|tj}y|jtj|�j�Wqtk
r�|j|�qXq|dkrtj|tj
�rtjjj|d�}|j|�q|jd
�qqWt|�dkr:|dS|SdS(Nupathunameusizeutypeu?umodei����iumtimeuuserugroupumd5uii(RiRjR_R`tbasenameRCRTR?RRDRERtoctRZRLRItgetpwuidtpw_nameR@RRROtgetgrgidtgr_nameR^tsalttutilst	hashutilstget_hashR(	R%tfullpathR3ttestRRltuidtgidt	md5digest((s3/usr/lib/python2.7/site-packages/salt/utils/find.pytexecute�sF&*



(R'R(R)R0R&RfR|(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyRe�s		tDeleteOptioncB@s#eZdZd�Zed�ZRS(u
    Deletes matched file.
    Delete options are one or more of the following:
        a: all file types
        b: block device
        c: character device
        d: directory
        p: FIFO (named pipe)
        f: plain file
        l: symlink
        s: socket
    cC@s5d|krd}nt|j|�j||�dS(Nuaubcdpfls(tsupert	__class__R0(R%R/R((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0s	cC@s�|r
|SyZtjj|�s1tjj|�rAtj|�n"tjj|�rctj|�nWntt	fk
r�}dSX|S(N(R_R`tisfiletislinktremovetisdirtshutiltrmtreetOSErrortIOErrorR(R%RwR3Rxtexc((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR|s$(R'R(R)R0RfR|(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR}
s	t
ExecOptioncB@s#eZdZd�Zed�ZRS(ut
    Execute the given command, {} replaced by filename.
    Quote the {} if commands might include whitespace.
    cC@s
||_dS(N(tcommand(R%R/R((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR01sc	C@s�y�|jjd|�}ttjjj|��ttjjj|�dtdt�}|j	�\}}|r�t
jd|tjjj
|��ndj|tjjj
|��SWn0tk
r�}t
jd||�dj|�SXdS(Nu{}tstdouttstderruError running command: %s

%su	{0}:
{1}
u+Exception while executing command "%s":

%su{0}: Failed(R�R-tprintRsRttargstshlex_splitRRtcommunicatetlogR7tstringutilstto_strR
t	Exception(	R%RwR3RxR�tptoutterrte((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR|4s&	#(R'R(R)R0RfR|(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR�,s	tFindercB@s2eZd�Zd�Zdd�Zdd�ZRS(cC@sNg|_d|_d|_t|_it�t6t�t6t�t	6}d|krk|d|_|d=nd|kr�|d|_|d=nd|kr�|d|_|d=nxHt
j|�D]7\}}|jd�r�q�n|dkst
t|��dkrtdj|���ny$t�|j�d||�}Wn&tk
rjtdj|���nXt|d	�r�|j�}|t	@r�|t	j|�q�|t@r�|tj|�q�|tj|�nt|d
�r�|jj|�q�q�Wt
|j�dkr-|jjtdd��n|t|t|t	|_dS(
Niumindepthumaxdepthutestu_umissing value for "{0}" optionuOptionuinvalid option "{0}"umatchuexecuteuprintu(tactionsRtmaxdepthtmindepthRfRxtlistR$RBR\Rt	iteritemsRRtstrRR
tglobalsttitleR@thasattrR&RjRetcriteria(R%toptionsR�R/RtobjR&((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR0LsL				








$$


cc@s�|jdkrstjj|�\}}|j|||�\}}|rsx%|j|d|�D]}|Vq^Wqsnxtjjj|�D]�\}}}tjj	||�}	t
|	�d}
|
|jkr`|jdks�|j|
kr`xs||D]d}tjj
||�}|j|||�\}}|r�x%|j|d|�D]}|VqGWq�q�Wn|jdk	r�|
|jkr�g|(q�q�WdS(u�
        Generate filenames in path that satisfy criteria specified in
        the constructor.
        This method is a generator and should be repeatedly called
        until there are no more results.
        iR3N(R�R_R`R;t_check_criteriat_perform_actionsRsRttos_walktrelpatht
path_depthR�RR:(R%R`tdirpathRR	R3RtdirstfilesR�tdepthRw((s3/usr/lib/python2.7/site-packages/salt/utils/find.pytfindxs$%-cC@s�t}x�|jD]z}|dkrk|j�t@rkytj|�}Wqktk
rgtj|�}qkXn|j	|||�st
}PqqW||fS(N(RkR�RR&RBR_RCR�tlstatR	Rf(R%R�RRwR3R	t	criterion((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR��s
cc@s�x�|jD]�}|dkre|j�t@reytj|�}Wqetk
ratj|�}qeXn|j||d|j	�}|dk	r
|Vq
q
WdS(NRx(
R�RR&RBR_RCR�R�R|Rx(R%RwR3tactionR((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR��s
N(R'R(R0R�RR�R�(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR�Ks	,	
cC@srd}|}x_trmtjj|�\}}|rK|sG|tkrKPn|r|tkr|d7}qqW|S(Nii(RkR_R`R;t_PATH_DEPTH_IGNORED(R`R�theadttail((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR��s	cc@s/t|�}x|j|�D]}|VqWdS(u
    WRITEME
    N(R�R�(R`R�tfinder((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyR��scC@sttj�dkrNtjjdjtjd��tjtjj	j
�ntjd}i}x4tjdD]%}|jd�\}}|||<qoWyt|�}WnBt
k
r�}tjjdj|��tjtjj	j�nXx!|j|�D]}t|�q�WdS(Niuusage: {0} path [options]
iiu=uerror: {0}
(RtsystargvR�twriteR
texitRstdefaultst	exitcodestEX_USAGER;R�Rt
EX_GENERICR�R�(R`R�RlR/RR�texR((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyt_main�s 
u__main__(GR)t
__future__RRRtloggingR_R+RCR�R�RVt
subprocessRRRORItImportErrortsalt.extRtsalt.utils.argsRstsalt.utils.hashutilstsalt.utils.pathtsalt.utils.stringutilstsalt.defaults.exitcodestsalt.utils.filebufferRt	getLoggerR'R�R$RBR\tS_IFBLKtS_IFCHRtS_IFDIRtS_IFREGtS_IFLNKtS_IFIFOtS_IFSOCKR?R,tVERBOSERR`tseptcurdirtpardirR�RR"tobjectR#R*R4R6R8R9RFRMRSRUR[ReR}R�R�R�R�R�(((s3/usr/lib/python2.7/site-packages/salt/utils/find.pyt<module>Ts�














	!		+Hb				

Zerion Mini Shell 1.0