Viewing File: /usr/lib/python2.7/site-packages/sos/utilities.pyo

ó
ŃKjc
@€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-
Back to Directory File Manager