Current File : //lib/python2.7/site-packages/sos/utilities.pyo
�
u��ec
@�s�ddlmZddlZddlZddlZddlmZmZmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddlZd�Zdd�Zddddd�Zddd�Zd�Zd�Zdedddeeddd�	Zdd�Zdddd�Zdej fd��YZ!de"fd��YZ#de$fd��YZ%dS( i����(twith_statementN(tPopentPIPEtSTDOUT(tclosing(tdequecC�sRt|d��=}tj|�j|kr>|j|d�n|j�SWdQXdS(s,Returns the last number_of_bytes of filenametrbiN(topentoststattst_sizetseektread(tfilenametnumber_of_bytestf((s1/usr/lib/python2.7/site-packages/sos/utilities.pyttailstrcC�sut|tj�rgyt||�SWqqtk
rctjd�}|jd|�ttj	��SXn
t|�SdS(s@Returns a file-like object that can be used as a context managertsossfileobj: %s could not be openedN(
t
isinstancetsixtstring_typesRtIOErrortloggingt	getLoggertdebugRtStringIO(tpath_or_filetmodetlog((s1/usr/lib/python2.7/site-packages/sos/utilities.pytfileobj&s
ii
iii(cC�sxt|�}||kr$d||S||kr<d||S||krTd||S||krld||Sd|SdS(sCConverts a number of bytes to a shorter, more human friendly formats%.1fTs%.1fGs%.1fMs%.1fKs%dN(tfloat(tbytes_tKtMtGtTtfn((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt
convert_bytes3sc	c�s�|r4tjj|�jtjj�}||7}nx�tj|�D]�\}}}|r{|jtjj�|kr{|2n|r�tj||�r�qDnx.tj||�D]}tjj||�Vq�WqDWdS(s�Generator function to find files recursively.
    Usage::

        for filename in find("*.properties", "/var/log/foobar"):
            print filename
    N(	Rtpathtdirnametcounttseptwalktfnmatchtfiltertjoin(	tfile_patternttop_dirt	max_depthtpath_patternt
base_depthR'tdirlisttfilelisttname((s1/usr/lib/python2.7/site-packages/sos/utilities.pytfindBs!
!c�sMg}x@|D]8}t|��$}|j�fd�|D��WdQXq
W|S(s�Returns lines matched in fnames, where fnames can either be pathnames to
    files to grep through or open file objects to grep through line by linec3�s'|]}tj�|�r|VqdS(N(tretmatch(t.0tline(tpattern(s1/usr/lib/python2.7/site-packages/sos/utilities.pys	<genexpr>_sN(Rtextend(R<tfiles_or_pathstmatchestfoptfo((R<s1/usr/lib/python2.7/site-packages/sos/utilities.pytgrepXs

'cC�sgtjjdd�jtjj�}|gg|D]}tjj||�^q1}td�|D��S(s6Returns if a command matches an executable on the PATHtPATHtcs�s$|]}tj|tj�VqdS(N(RtaccesstX_OK(R:R'((s1/usr/lib/python2.7/site-packages/sos/utilities.pys	<genexpr>is(RtenvirontgettsplitR'tpathsepR.tany(tcommandtpathstpt
candidates((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt
is_executableds$/i,c
�se��fd�}
tjj�}d|d<|rtx@|j�D]/\}}
|
r]|
||<q>|j|d�q>Wn|r�td�r�d|r�dnd||f}ntjs�|j	dd	�}nt
j|�}g}x@|D]8}tj|�}|r
|j
|�q�|j|�q�Wy�t|d
tdtd|rBtntd
dd|dtd|
�}t|j||�}|	r�x9|jr�|	�r�|j�t�ntjd�q�Wn|j�}x|j�dkr�q�WWn=tk
r}|jtjkridd6dd6S|�nX|j dks>|j dkrPtj!d�}ni|j d6|d6S(s�Execute a command and return a dictionary of status and output,
    optionally changing root or current working directory before
    executing command.
    c�s0�rtj��n�r,tj��ndS(N(Rtchroottchdir((RRRQ(s1/usr/lib/python2.7/site-packages/sos/utilities.pyt_child_prep_fnvstCtLC_ALLttimeoutstimeout %s %ds %ss--foregroundRDsutf-8tignoretshelltstdouttstderrtbufsizei����tenvt	close_fdst
preexec_fng{�G�z�?itstatustoutputi~N("RRGtcopytitemstpoptNoneRPRtPY3tencodetshlexRItglobR=tappendRtFalseRRtTruetAsyncReaderRYtrunningt	terminatetSoSTimeoutErrorttimetsleeptget_contentstpolltOSErrorterrnotENOENTt
returncodetbinary_type(RLRVRZRQRRR\t
foregroundtbinaryt	sizelimittpollerRStcmd_envtkeytvaluetargst
expanded_argstargtexpanded_argRNtreaderRYte((RRRQs1/usr/lib/python2.7/site-packages/sos/utilities.pytsos_get_command_outputls\



	
		
	

cC�s�|jd�d}t|t�t�|g�}gtj|tj�D]!\}}|j|krG|^qG}|r�g|D]}t||�r{|^q{}n|S(sImports the module module_fqname and returns a list of defined classes
    from that module. If superclasses is defined then the classes returned will
    be subclasses of the specified superclass or superclasses. If superclasses
    is plural it must be a tuple of classes.t.i����(	t
rpartitiont
__import__tglobalstlocalstinspectt
getmemberstisclasst
__module__t
issubclass(t
module_fqnametsuperclassestmodule_nametmoduletcnametclass_tmodulestm((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt
import_module�s+cC�s t|d|d|d|�dS(seShell out to an external command and return the output or the empty
    string in case of error.
    RVRQRRR`(R�(tcmdRVRQtrunat((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt	shell_out�sRlcB�s)eZdZd�Zd�Zd�ZRS(s�Used to limit command output to a given size without deadlocking
    sos.

    Takes a sizelimit value in MB, and will compile stdout from Popen into a
    string that is limited to the given sizelimit.
    cC�s�tt|�j�||_||_d|_d}|rZ|d}t||j�}ntd|�|_t	|_
|j�dS(Niitmaxlen(tsuperRlt__init__tchanRzt	chunksizeRdtintRRkRmtstart(tselftchannelR{Rztslots((s1/usr/lib/python2.7/site-packages/sos/utilities.pyR��s			
	cC�sgy@x9tr>|jj|j�}|s+Pn|jj|�qWWnttfk
rYnXt|_	dS(slReads from the channel (pipe) that is the output pipe for a
        called Popen. As we are reading from the pipe, the output is added
        to a deque. After the size of the deque exceeds the sizelimit
        earlier (older) entries are removed.

        This means the returned output is chunksize-sensitive, but is not
        really byte-sensitive.
        N(
RkR�RR�RRit
ValueErrorRRjRm(R�R;((s1/usr/lib/python2.7/site-packages/sos/utilities.pytrun�s		cC�s^x|jrtjd�qW|js@djd�|jD��Sdjd�|jD��SdS(s-Returns the contents of the deque as a stringg{�G�z�?RDcs�s!|]}|jdd�VqdS(sutf-8RWN(tdecode(R:tln((s1/usr/lib/python2.7/site-packages/sos/utilities.pys	<genexpr>scs�s|]}|VqdS(N((R:R�((s1/usr/lib/python2.7/site-packages/sos/utilities.pys	<genexpr>sN(RmRpRqRzR.R(R�((s1/usr/lib/python2.7/site-packages/sos/utilities.pyRr�s
	(t__name__R�t__doc__R�R�Rr(((s1/usr/lib/python2.7/site-packages/sos/utilities.pyRl�s	
	tImporterHelpercB�s;eZdZd�Zd�Zd�Zd�Zd�ZRS(s�Provides a list of modules that can be imported in a package.
    Importable modules are located along the module __path__ list and modules
    are files that end in .py.
    cC�s
||_dS(sopackage is a package module
        import my.package.module
        helper = ImporterHelper(my.package.module)N(tpackage(R�R�((s1/usr/lib/python2.7/site-packages/sos/utilities.pyR�scC�s.tjj|�}tjj|�\}}|S(s-Returns the plugin module name given the path(RR'tbasenametsplitext(R�R'tbaseR6text((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt_plugin_namescC�sKg|D]0}d|kr|jd�r|j|�^q}|j�|S(NR�s.py(tendswithR�tsort(R�tlist_tplugintplugins((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt_get_plugins_from_lists

0
cC�sKtjj|�rGttd|��}|j|�}|r@|SgSndS(Ns*.py(RR'texiststlistR7R�(R�R'tpy_filestpnames((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt_find_plugins_in_dir!scC�sLg}x?|jjD]1}tjj|�r|j|j|��qqW|S(sQReturns the list of importable modules in the configured python
        package. (R�t__path__RR'tisdirR=R�(R�R�R'((s1/usr/lib/python2.7/site-packages/sos/utilities.pytget_modules*s
(R�R�R�R�R�R�R�R�(((s1/usr/lib/python2.7/site-packages/sos/utilities.pyR�s					RocB�seZRS((R�R�(((s1/usr/lib/python2.7/site-packages/sos/utilities.pyRo5siii@l(&t
__future__RRR8R�t
subprocessRRRRR,RuRgRht	threadingRpt
contextlibRtcollectionsRRRRR&RdR7RBRPRjR�R�R�tThreadRltobjectR�RtRo(((s1/usr/lib/python2.7/site-packages/sos/utilities.pyt<module>	s8	
		L6-