Ñò K<Ì]c@€sSddklZddkZddkZddkZddklZlZlZddk Z ddk Z ddk Z ddk Z ddk Z ddkZddkZddklZddklZd„Zdd„Zddddd„Zddd„Zd„Zd„Zddd„Zdd„Zd dd„Zdefd„ƒYZdS(iÿÿÿÿ(twith_statementN(tPopentPIPEtSTDOUT(tclosing(tStringIOcC€sht|dƒiiƒ}zE|~}ti|ƒi|jo|i| dƒn|iƒSWdQXdS(s,Returns the last number_of_bytes of filenametrbiN(topent__exit__t __enter__toststattst_sizetseektread(tfilenametnumber_of_bytest_[1]tf((s1/usr/lib/python2.6/site-packages/sos/utilities.pyttail"s&trcC€sgt|tƒoIyt||ƒSWqctidƒ}|id|ƒttƒƒSXn t|ƒSdS(s@Returns a file-like object that can be used as a context managertsossfileobj: %s could not be openedN(t isinstancet basestringRtloggingt getLoggertdebugRR(t path_or_filetmodetlog((s1/usr/lib/python2.6/site-packages/sos/utilities.pytfileobj*sii iii(cC€s€t|ƒ}||jo d||S||jo d||S||jo d||S||jo d||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.6/site-packages/sos/utilities.pyt convert_bytes7s         c c€sÛ|o/tii|ƒitiiƒ}||7}nxžti|ƒD]\}}}|o$|itiiƒ|jo|2n|oti||ƒ oqFnx.ti||ƒD]}tii||ƒVqµWqFWdS(sŽgenerator function to find files recursively. Usage: for filename in find("*.properties", "/var/log/foobar"): print filename N( R tpathtdirnametcounttseptwalktfnmatchtfiltertjoin( t file_patternttop_dirt max_deptht path_patternt base_depthR'tdirlisttfilelisttname((s1/usr/lib/python2.6/site-packages/sos/utilities.pytfindFs!#c €sag}xT|D]L}t|ƒiiƒ}z*|~}|i‡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€s0x)|]"}tiˆ|ƒo |VqqWdS(N(tretmatch(t.0tline(tpattern(s1/usr/lib/python2.6/site-packages/sos/utilities.pys bs N(RRR textend(R<tfiles_or_pathstmatchestfopRtfo((R<s1/usr/lib/python2.6/site-packages/sos/utilities.pytgrep[s #'cC€sotiiddƒitiiƒ}|gg}|D]}|tii||ƒq5~}td„|DƒƒS(s6Returns if a command matches an executable on the PATHtPATHtcs€s(x!|]}ti|tiƒVqWdS(N(R taccesstX_OK(R:R'((s1/usr/lib/python2.6/site-packages/sos/utilities.pys ls (R tenvirontgettsplitR'tpathsepR.tany(tcommandtpathsRtpt candidates((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt is_executablegs$7i,c €s‘‡fd†}ti}d|d<|o!tdƒod||f}n|iddƒ}ti|ƒ}g}xB|D]:}ti|ƒ}|o|i|ƒqx|i|ƒqxWy:t |dt d t d t d d d |dt d|ƒ} WnAtj o5} | itijohdd6dd6S| ‚nX| iƒ\} } | idjp| idjo d} nh| id6| iddƒd6S(s‹Execute a command through the system shell. First checks to see if the requested command is executable. Returns (returncode, stdout, 0)c€s;ˆo0ytiˆƒWq7tidˆƒq7XndS(Nsfailed to chdir to '%s'(R tchdirtselft log_error((trunat(s1/usr/lib/python2.6/site-packages/sos/utilities.pyt _child_chdirrs tCtLC_ALLttimeoutstimeout %ds %ssutf-8tignoretshelltstdouttstderrtbufsizeiÿÿÿÿtenvt close_fdst preexec_fnitstatusRDtoutputi~(R RGRPtencodetshlexRItglobR=tappendRtFalseRRtTruetOSErrorterrnotENOENTt communicatet returncodetdecode( RLRXRTRUtcmd_envtargst expanded_argstargt expanded_argRNteR[R\((RTs1/usr/lib/python2.6/site-packages/sos/utilities.pytsos_get_command_outputos8       c C€s¿|idƒd}t|tƒtƒ|gƒ}g}ti|tiƒD]'\}}|i|jo ||qKqK~}|o9g}|D]!} t| |ƒo || qq~}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 superclassest module_nametmoduleRtcnametclass_tmodulest_[2]tm((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt import_module¡s$9cC€st|d|d|ƒdS(seShell out to an external command and return the output or the empty string in case of error. RXRTRb(Ru(tcmdRXRT((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt shell_out±stImporterHelpercB€sPeZdZd„Zd„Zd„Zd„Zdd„Zd„Z d„Z RS( sProvides 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. This class will read from PKZip archives as well for listing out jar and egg contents.cC€s ||_dS(sopackage is a package module import my.package.module helper = ImporterHelper(my.package.module)N(tpackage(RRR((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt__init__¾scC€s.tii|ƒ}tii|ƒ\}}|S(s-Returns the plugin module name given the path(R R'tbasenametsplitext(RRR'tbaseR6text((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt _plugin_nameÄscC€sYg}|D]7}d|jo$|idƒo||i|ƒq q ~}|iƒ|S(NRŽs.py(tendswithR“tsort(RRtlist_Rtplugintplugins((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt_get_plugins_from_listÊs   - cC€sOtii|ƒo8ttd|ƒƒ}|i|ƒ}|o|SgSndS(Ns*.py(R R'texiststlistR7R™(RRR'tpy_filestpnames((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt_find_plugins_in_dirÒs cC€s”|p dg}n|idƒo|tii|ŒfStii|ƒ\}}|id|ƒ||jotdƒ‚n|i||ƒSdS(NRDs.jars.zips.eggisnot a zip file(s.jars.zips.egg(R”R R'R.RItinsertt Exceptiont_get_path_to_zip(RRR't tail_listtheadR((s1/usr/lib/python2.6/site-packages/sos/utilities.pyR¡Ûs  c C€sÂy¡|i|ƒ\}}ti|ƒ}|itiidƒ}g}|iƒD]}||jo ||qPqP~}|i|ƒ}|i ƒ|o|SgSWnt t fj ogSXdS(Nt/( R¡tzipfiletZipFiletreplaceR R'R*tnamelistR™tclosetIOErrorR ( RRR't path_to_zipRtzfRR6t root_namesRO((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt_find_plugins_in_zipfileês8 cC€sqg}xd|iiD]V}tii|ƒp |djo|i|i|ƒƒq|i|i|ƒƒqW|S(sQReturns the list of importable modules in the configured python package. RD(Rt__path__R R'tisdirR=RžR®(RRR˜R'((s1/usr/lib/python2.6/site-packages/sos/utilities.pyt get_modulesûs  N( t__name__R~t__doc__RŽR“R™RžtNoneR¡R®R±(((s1/usr/lib/python2.6/site-packages/sos/utilities.pyRŒ¸s     iii@l(t __future__RR R8R{t subprocessRRRR¥thashlibRR,RjRdRet contextlibRRRRR&R´R7RBRPRuR‰R‹tobjectRŒ(((s1/usr/lib/python2.6/site-packages/sos/utilities.pyts.             2