%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlmZddlmZyddlmZWn!ek
rddlmZnXddlmZeje�Z d�Z!d	�Z"dd
�Z#d�Z$d�Z%d
�Z&d�Z'd�Z(d�Z)d�Z*e+dd�Z,de-fd��YZ.de-fd��YZ/dS(u=
File server pluggable modules and generic backend functions
i(tabsolute_importtprint_functiontunicode_literalsN(tget_function_argspec(tensure_unicode_args(tSequence(tsixcC@s�tjj|�sdSyHtjj|�r;tj|�n"tjj|�r]tj|�nWn,ttfk
r�}t	j
d||�nXdS(u)
    Unlock a FS file/dir based lock
    NuError removing lockfile %s: %s(tostpathtexiststisdirtrmdirtisfiletunlinktOSErrortIOErrortlogttrace(tw_locktexc((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt
_unlock_cache'scC@sXytj|�Wn,tk
r?}|jtjkr;�ntSXtjd|�tSdS(NuLockfile %s created(	RtmkdirRterrnotEEXISTtFalseRRtTrue(RR((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt_lock_cache6scC@sGtjj|�stStjj|�sXtjd�tjj|�sXt|�tSnd}|rwtj�|}nd}tj	|�j
}x�trBtjd�tjj|�s�tStj	|�j
}||kr|d7}|dkrt|�tSn|}|r�tj�|kr?tdj
|||���q?q�q�WtS(u�
    If the write lock is there, check to see if the file is actually being
    written. If there is no change in the file size after a short sleep,
    remove the lock and move forward.
    iiiu)Timeout({0}s) for {1} (lock: {2}) elapsedN(RRR	RttimetsleepRRtNonetstattst_sizeRt
ValueErrortformat(tlk_fntdesttwait_timeoutttimeoutts_countts_sizetsize((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt	wait_lockBs:

	


c
C@sOt}t}tjj|�}t||d�tjj|�rVt	|�rVt}n�d}x�|dkr&y�tjj
|�r�t||d�ntjj
|�r
tj|�}tt
j
��}	t|j�}
|
|	krtjd||	|
�d}q#|	|
}n|jdd�d	}|dkr?tjd
�nd|kob|jdd�knr�tjjj|d��Z}tjd||jdd�|�tjjj|j|�j|g��ttfSWd
QXnt	|�r�t}PnWq_tk
r"t
jd�|d	7}q_q_Xq_W|dkrBt}t}nd
||fS(u�
    Checks the cache file to see if there is a new enough file list cache, and
    returns the match (if found, along with booleans used by the fileserver
    backend to determine if the cache needs to be refreshed/written).
    ii<iiiuUCache file modified time is in the future, ignoring. file=%s mtime=%s current_time=%sufileserver_list_cache_timeiiu.The file list_cache was created in the future!urbu7Returning file list from cache: age=%s cache_time=%s %sNg�������?i
i,i�(RRtsalttpayloadtSerialR)RRRRR	RtintRtst_mtimeRtdebugtgettwarningtutilstfilestfopentdatatdecodetloadt	ExceptionRR(
toptstformt
list_cacheRt
refresh_cachet
save_cachetserialtattemptt
cache_stattcurrent_timet
file_mtimetagetfp_((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytcheck_file_list_cachepsR	
	
(:


	cC@sgtjj|�}tjjj|d��7}|j|j|��t|�t	j
d|�WdQXdS(u�
    Checks the cache file to see if there is a new enough file list cache, and
    returns the match (if found, along with booleans used by the fileserver
    backend to determine if the cache needs to be refreshed/written).
    uw+buLockfile %s removedN(R*R+R,R2R3R4twritetdumpsRRR(R9R5R;RR>RD((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytwrite_file_list_cache�s

cC@s�tjj|�sdSyctjjj|d��E}tj	d|�tj
j|�}tjjj
|j|��SWdQXWnttfk
r�nXdS(uG
    Returns cached env names, if present. Otherwise returns None.
    urbu Returning env cache data from %sN(RRRRR*R2R3R4RRR+R,R5R6R7RR(R9t	env_cacheRDR>((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytcheck_env_cache�s&c
C@s�i}x�tj|�D]�\}}x�|D]�}x�tjjj|�D]�\}}}x|D]w}	yDtjj||	�}
t||
�r�w[ntjj	|
�||
<Wq[t
tfk
r�tj
d|
�q[q[Xq[WqEWq)WqW|S(u.
    Generate a dict of filename -> mtime
    u,Failed to get mtime on %s, dangling symlink?(Rt	iteritemsR*R2Rtos_walkRtjointis_file_ignoredtgetmtimeRRRtinfo(R9tpath_maptfile_maptsaltenvt	path_listRt	directoryt_t	filenamestitemt	file_path((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytgenerate_mtime_map�s 
%
cC@sTt|�t|�krtSx1tj|�D] \}}|||kr,tSq,WtS(u>
    Is there a change to the mtime map? return a boolean
    (tsortedRRRKR(tmap1tmap2tfilenametmtime((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytdiff_mtime_map�sc	C@sUxNtj|�D]=}tjj||�}xtjjj|�D]\}}}|r�|r�tj�tjj|�dkrAtj	|�qAqAnx�|D]�}tjj||�}tjj
||�}	y|	jdd�\}
}}Wn$tk
rt
jd|�q�nX||
d|�}
|
ddkr�tj|�q�q�WqAWqWdS(	u�
    Remove unused cache items assuming the cache directory follows a directory
    convention:

    cache_base -> saltenv -> relpath
    i<u.iuDFound invalid hash file [%s] when attempting to reap cache directoryRSupathuN(RtlistdirRRMR*R2RLRtgetctimeRtrelpathtrsplitR RR1R
(t
cache_baset	find_funcRStenv_basetroottdirsR3tfile_RYt
file_rel_pathR^RVt	hash_typetret((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytreap_fileserver_cache_dir�s(%"

cC@s�|drHx;|dD],}tj||�rtjd|�tSqWn|dr�x;|dD],}tj||�r]tjd|�tSq]WntS(u�
    If file_ignore_regex or file_ignore_glob were given in config,
    compare the given file path against all of them and return True
    on the first match.
    ufile_ignore_regexu-File matching file_ignore_regex. Skipping: %sufile_ignore_globu,File matching file_ignore_glob. Skipping: %s(tretsearchRR/RtfnmatchR(R9tfnametregextglob((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyRNs

uupdatecC@sNdj||�}|r.|dj|�7}ntj|�|d|d|�S(u�
    Function to allow non-fileserver functions to clear update locks

    clear_func
        A function reference. This function will be run (with the ``remote``
        param as an argument) to clear the lock, and must return a 2-tuple of
        lists, one containing messages describing successfully cleared locks,
        and one containing messages describing errors encountered.

    role
        What type of lock is being cleared (gitfs, git_pillar, etc.). Used
        solely for logging purposes.

    remote
        Optional string which should be used in ``func`` to pattern match so
        that a subset of remotes can be targeted.

    lock_type : update
        Which type of lock to clear

    Returns the return data from ``clear_func``.
    u!Clearing {0} lock for {1} remotesu
 matching {0}tremotet	lock_type(R!RR/(t
clear_functroleRuRvtmsg((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt
clear_lock9s

t
FileservercB@s%eZdZd�Zdd�Zd�Zd�Zdd�Zddd�Z	ddd�Z
dd�Zdd	�Zde
d
�Zdd�Zdd�Zd
�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zed��Zed��Zed��Zed��ZRS(u�
    Create a fileserver wrapper object that wraps the fileserver functions and
    iterates over them to execute the desired function within the scope of the
    desired fileserver backend.
    cC@s)||_tjj||d�|_dS(Nufileserver_backend(R9R*tloadert
fileservertservers(tselfR9((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt__init__]s	cC@s�|s|jd}nQt|t�sgy|jd�}Wqgtk
rctj|�jd�}qgXnt|t�r�t|�}ng}t|t�s�|S|jj	�}yt
d�|D��}Wntk
r�n�X|rc|jd}xn|D]f}dj|d�|kr(|j|d�q�dj|dd!�|kr�|j|dd!�q�q�W|Sx`|D]X}dj|�|kr�|j
|�qjdj|d �|krj|j
|d �qjqjW|S(u)
        Return the backend list
        ufileserver_backendu,cs@s|]}|jd�VqdS(u-N(t
startswith(t.0tx((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pys	<genexpr>~su{0}.envsii����(R9t
isinstancetlisttsplittAttributeErrorRt	text_typeRR~tkeystallR!tremovetappend(RtbackRmtserver_funcst
subtract_onlytsub((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytbackendsas>




cC@s|jS(u&
        Simplify master opts
        (R9(RR7((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytmaster_opts�scC@sex^|jj�D]M\}}y-d|jkrH|jdj|j�nWqtk
r\qXqWdS(Nu__opts__(R~titemst__globals__tupdateR9R�(Rtnametfunc((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytupdate_opts�s
cC@s�|j|�}g}g}x{|D]s}dj|�}||jkr"tjd|�|j|�}|r||j|�q�|jdj|��q"q"W||fS(u�
        Clear the cache of all of the fileserver backends that support the
        clear_cache function or the named backend(s) only.
        u{0}.clear_cacheuClearing %s fileserver cacheu1The {0} fileserver cache was successfully cleared(R�R!R~RR/textendR�(RR�tclearedterrorstfsbtfstrtfailed((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytclear_cache�s
c
C@s�|j|�}g}g}x�|D]�}dj|�}||jkr"dj|�}|r�t|tj�s�|jdj|��q"q�|dj|�7}ntj|�|j|d|�\}}	|j	|�|j	|	�q"q"W||fS(u�
        ``remote`` can either be a dictionary containing repo configuration
        information, or a pattern. If the latter, then remotes for which the URL
        matches the pattern will be locked.
        u{0}.locku#Setting update lock for {0} remotesu$Badly formatted remote pattern '{0}'u
 matching {0}Ru(
R�R!R~R�Rtstring_typesR�RR/R�(
RR�RutlockedR�R�R�Rytgoodtbad((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytlock�s&



c	C@s�|j|�}g}g}xk|D]c}dj|�}||jkr"t|j||d|�\}}|j|�|j|�q"q"W||fS(ui
        Clear the update lock for the enabled fileserver backends

        back
            Only clear the update lock for the specified backend(s). The
            default is to clear the lock for all enabled backends

        remote
            If specified, then any remotes which contain the passed string will
            have their lock cleared.
        u{0}.clear_lockRu(R�R!R~RzR�(	RR�RuR�R�R�R�R�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyRz�s


cC@sc|j|�}xM|D]E}dj|�}||jkrtjd|�|j|�qqWdS(um
        Update all of the enabled fileserver backends which support the update
        function, or
        u
{0}.updateuUpdating %s fileserver cacheN(R�R!R~RR/(RR�R�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyR��s
cC@s_|j|�}i}xC|D];}dj|�}||jkr|j|�||<qqW|S(u�
        Return the update intervals for all of the enabled fileserver backends
        which support variable update intervals.
        u{0}.update_intervals(R�R!R~(RR�RmR�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytupdate_intervals�s
cC@s�|j|�}t�}|r'i}nx�|D]�}dj|�}dt|j|�jkr|jddkritd6ni}|r�|j||�||<q.|j|j||��q.W|r�|St	|�S(uO
        Return the environments for the named backend or all backends
        u{0}.envsuignore_cacheu__roleuminion(
R�tsetR!t_argspecR~targsR9RR�R�(RR�tsourcesRmR�R�tkwargs((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytenvss		
 cC@s2|dkri}n|jdd�|j|�S(uS
        Return environments for all backends for requests from fileclient
        ucmdN(RtpopR�(RR7((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt	file_envss	cC@sS|j|�}x=|D]5}dj|�}||jkr|j|�qqWdS(uX
        Initialize the backend, only do so if the fs supports an init function
        u{0}.initN(R�R!R~(RR�R�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytinit%s

cC@sI|jd�}|s'idd6dd6S|jdd�}|j||�S(uL
        Convenience function for calls made using the RemoteClient
        upathuurelusaltenvubase(R0t	find_file(RR7Rttgt_env((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt
_find_file/s
cC@sI|jd�}|s'idd6dd6S|jdd�}|j||�S(uK
        Convenience function for calls made using the LocalClient
        upathuurelusaltenvubase(R0R�(RR7RR�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt	file_find:s
cC@s�tjjj|�}tjjj|�}|j|�}i}idd6dd6}tjj|�ri|Sd|kry|Stjjj	|�r�tjjj
|�}n�d|kr(|jd�}|d}|djd�}xG|D]<}d	|kr�q�n|jd	d�}	|	d||	d<q�Wnd
|krD|jd
�nd|krb|jd�}nt
|tj�s�tj|�}nxe|D]]}
dj|
�}||jkr�|j||||�}|jd�r�|
|d
<|Sq�q�W|S(u{
        Find the path and return the fnd structure, this structure is passed
        to other backend interfaces.
        uupathurelu../u?iiu&u=uenvusaltenvu
{0}.find_fileuback(R*R2tstringutilst
to_unicodeR�RRtisabsturlt
is_escapedtunescapeR�R�R�RR�R�R!R~R0(RRRSR�R�tfndthcompstcompstcompR�R�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyR�EsF





cC@s�idd6dd6}d|kr0|jd�nd|ksTd|ksTd|krX|St|dtj�s�tj|d�|d<n|j|d|d�}|jd�s�|Sd	j|d�}||jkr�|j|||�S|S(
u,
        Serve up a chunk of a file
        uudataudestuenvupathulocusaltenvubacku{0}.serve_file(	R�R�RR�R�R�R0R!R~(RR7RmR�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt
serve_fileus

$cC@s�d|kr|jd�nd|ks4d|kr8d	St|dtj�shtj|d�|d<n|jtjj	j
|d�|d�}|jd�s�d
S|jdd�}dj|d�}||j
kr�|j
|||�|fSdS(u;
        Common code for hashing and stating files
        uenvupathusaltenvuubackustatu
{0}.file_hashN(uN(uN(uN(R�RR�RR�R�R�R*R2R�R�R0R!R~(RR7R�tstat_resultR�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt__file_hash_and_stat�s
cC@s4y|j|�dSWnttfk
r/dSXdS(u1
        Return the hash of a given file
        iuN(t_Fileserver__file_hash_and_statt
IndexErrort	TypeError(RR7((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt	file_hash�scC@s0y|j|�SWnttfk
r+dSXdS(uA
        Return the hash and stat result of a given file
        uN(uN(R�R�R�R(RR7((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytfile_hash_and_stat�sc	C@s<d|kr|jd�n|jdg�}|dk	rt|t�s�y,g|jd�D]}|j�^q\}Wq�tk
r�gtj	|�jd�D]}|j�^q�}q�XnxEt
|�D]4\}}t|tj�s�tj	|�||<q�q�Wni}|j|jdd��}t
jj|jdd�}yt
j|�}	WnFtk
r�}
|
jtjkr�tjd�iStjd|
�nXx�|	D]�}tjd	d
|�}y"t
jt
jj||��}
Wn)tk
r
}
tjd||
�q�nXx#|
D]}y|jdd
�\}}Wntk
rMqnX|dkr`qn=||ks�|dk	r�||kr�tjd||�qny#t
jt
jj|||��WnAtk
r}
|
jtjkr0tjd|
j|
j�q0qX|j|g�j |�tjd||�qWq�W|S(u4
        Deletes the file_lists cache files
        uenvusaltenvu,u	fsbackenducachediru
file_listsuNo file list caches founduMFailed to get list of saltenvs for which the master has cached file lists: %sufs$uu4Failed to find file list caches for saltenv '%s': %su.iupu,Skipping %s file list cache for saltenv '%s'uFailed to remove %s: %su+Removed %s file list cache for saltenv '%s'N(!R�R0RR�R�R�tstripR�RR�t	enumerateR�R�RRRMR9RaRRtENOENTRR/terrorRoR�RdR R�R^tstrerrort
setdefaultR�(RR7RSR�tidxtvalRmR�t
list_cachedirtfile_list_backendsRR�tback_virtualnametcache_filest
cache_filet
cache_saltenvt	extension((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytclear_file_list_cache�sr,
8

"



#	cC@s"d|kr|jd�nt�}d|kr5gSt|dtj�setj|d�|d<nx^|j|jdd��D]A}dj|�}||j	kr�|j
|j	||��q�q�W|jdd�jd�}|dkrg|D]}|j
|�r�|^q�}nt|�S(	uF
        Return a list of files from the dominant environment
        uenvusaltenvu	fsbackendu
{0}.file_listuprefixuu/N(R�R�R�RR�R�R�RR!R~R�R0R�R�R[(RR7RmR�R�tprefixtf((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt	file_lists	"!+cC@sd|kr|jd�nt�}d|kr5gSt|dtj�setj|d�|d<nxR|jd�D]A}dj|�}||j	kru|j
|j	||��ququW|jdd�jd�}|dkrg|D]}|j
|�r�|^q�}nt|�S(u=
        List all emptydirs in the given environment
        uenvusaltenvu{0}.file_list_emptydirsuprefixuu/N(R�R�R�RR�R�R�RR!R~R�R0R�R�R[(RR7RmR�R�R�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytfile_list_emptydirss	!+cC@s"d|kr|jd�nt�}d|kr5gSt|dtj�setj|d�|d<nx^|j|jdd��D]A}dj|�}||j	kr�|j
|j	||��q�q�W|jdd�jd�}|dkrg|D]}|j
|�r�|^q�}nt|�S(	u?
        List all directories in the given environment
        uenvusaltenvu	fsbackendu{0}.dir_listuprefixuu/N(R�R�R�RR�R�R�RR!R~R�R0R�R�R[(RR7RmR�R�R�R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytdir_list5s	"!+cC@s-d|kr|jd�ni}d|kr2iSt|dtj�sbtj|d�|d<nxW|j|jdd��D]:}dj|�}||jkr~|j||�}q~q~W|j	dd�j
d�}|dkr)tgtj|�D]'\}}|j
|�r�||f^q��}n|S(	u;
        Return a list of symlinked files and dirs
        uenvusaltenvu	fsbackendu{0}.symlink_listuprefixuu/N(R�R�RR�R�R�RR!R~R0R�tdictRKR�(RR7RmR�tsymlstrR�R�ty((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytsymlink_listNs "CN(t__name__t
__module__t__doc__R�RR�R�R�R�R�RzR�R�RR�R�R�R�R�R�R�R�R�R�R�RR�R�R�R�(((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyR{Ws2	2			
	
		0							MtFSChancB@s2eZdZd�Zdded�Zd�ZRS(u}
    A class that mimics the transport channels allowing for local access to
    to the fileserver class class structure
    cK@s�||_||_t|j�|_|jj�|jjdd�dkr{d|jkr�|jj�t|jd<q�n
|jj�iid6id6|_dS(Nufile_clienturemoteulocalu__fs_updateumaster_topsu	ext_nodes(	R9R�R{tfsR�R0R�Rtcmd_stub(RR9R�((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyR�os		



cC@s�d|kr tjd|�iS|djd�}||jkrM|j|St|j|�sstjd|�iSt|j|�|�S(uU
        Emulate the channel send method, the tries and timeout are not used
        ucmduMalformed request, no cmd: %su_u"Malformed request, invalid cmd: %s(RR�tlstripR�thasattrR�tgetattr(RR7ttriesR%trawtcmd((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytsend}scC@sdS(N((R((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pytclose�sN(R�R�R�R�RRR�R�(((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyR�js	(0R�t
__future__RRRRRqtloggingRRotsysRtsalt.loaderR*tsalt.utils.datatsalt.utils.filestsalt.utils.pathtsalt.utils.urltsalt.utils.versionstsalt.utils.argsRR�tsalt.utils.decoratorsRtcollections.abcRtImportErrortcollectionstsalt.extRt	getLoggerR�RRRR)RERHRJRZR`RnRNRRztobjectR{R�(((s</usr/lib/python2.7/site-packages/salt/fileserver/__init__.pyt<module>sJ
		.	@	
				&	��

Zerion Mini Shell 1.0