Ñò
K<Ì]c @€ sS d d k l Z d d k Z d d k Z d d k Z d d k l Z l Z l Z d d k Z d d k
Z
d d k Z d d k Z d d k
Z
d d k Z d d k Z d d k l Z d d k l Z d „ Z d d „ Z d d d d d „ Z d d d „ Z d „ Z d „ Z d d d „ Z d d „ Z d d d „ Z d e f d „ ƒ YZ d S( iÿÿÿÿ( t with_statementN( t Popent PIPEt STDOUT( t closing( t StringIOc C€ sh t | d ƒ i i ƒ } zE | ~ } t i | ƒ i | j o | i | d ƒ n | i ƒ SWd QXd S( s, Returns the last number_of_bytes of filenamet rbi N( t opent __exit__t __enter__t ost statt st_sizet seekt read( t filenamet number_of_bytest _[1]t f( ( s1 /usr/lib/python2.6/site-packages/sos/utilities.pyt tail" s &t rc C€ sg t | t ƒ oI y t | | ƒ SWqc t i d ƒ } | i d | ƒ t t ƒ ƒ SXn t | ƒ Sd S( s@ Returns a file-like object that can be used as a context managert soss fileobj: %s could not be openedN( t
isinstancet
basestringR t loggingt getLoggert debugR R ( t path_or_filet modet log( ( s1 /usr/lib/python2.6/site-packages/sos/utilities.pyt fileobj* s i i
i i i( c C€ s€ t | ƒ } | | j o
d | | S| | j o
d | | S| | j o
d | | S| | j o
d | | Sd | Sd S( sC Converts a number of bytes to a shorter, more human friendly formats %.1fTs %.1fGs %.1fMs %.1fKs %dN( t float( t bytes_t Kt Mt Gt Tt fn( ( s1 /usr/lib/python2.6/site-packages/sos/utilities.pyt
convert_bytes7 s
c c€ sÛ | o/ t i i | ƒ i t i i ƒ } | | 7} n xž t i | ƒ D] \ } } } | o$ | i t i i ƒ | j o | 2n | o t i | | ƒ o qF n x. t i | | ƒ D] } t i i | | ƒ Vqµ WqF Wd S( sŽ generator function to find files recursively. Usage:
for filename in find("*.properties", "/var/log/foobar"):
print filename
N( R
t patht dirnamet countt sept walkt fnmatcht filtert join( t file_patternt top_dirt max_deptht path_patternt
base_depthR' t dirlistt filelistt name( ( s1 /usr/lib/python2.6/site-packages/sos/utilities.pyt findF s ! # c € sa g } xT | D]L } t | ƒ i i ƒ } z* | ~ } | i ‡ f d † | Dƒ ƒ Wd QXq
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 linec 3€ s0 x) | ]" } t i ˆ | ƒ o | Vq q Wd S( N( t ret match( t .0t line( t pattern( s1 /usr/lib/python2.6/site-packages/sos/utilities.pys