????

Your IP : 216.73.216.152


Current Path : /proc/self/root/proc/self/root/lib/python2.7/site-packages/sos/plugins/
Upload File :
Current File : //proc/self/root/proc/self/root/lib/python2.7/site-packages/sos/plugins/__init__.pyc

�
Dr^c@�s$dZddlmZddlmZmZmZmZmZm	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlZddlZddlZddlZddlmZmZyeWnek
r�eZnXd�Zd�Zd	�Zd
�Zd�Zd�Zd
efd��YZ defd��YZ!defd��YZ"de"fd��YZ#de"fd��YZ$de"fd��YZ%defd��YZ&defd��YZ'defd��YZ(defd ��YZ)d!efd"��YZ*e+d#�Z,dS($s; This exports methods available for use by plugins for sos i����(twith_statement(tsos_get_command_outputt
import_moduletgreptfileobjttailt
is_executableN(ttime(tziptfiltercC�sDt|tj�s@|jd�r.|d7}ntj|�}n|S(Ns\t (t
isinstancetsixt	text_typetendswithtu(ts((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_to_u%s

cC�sNy5t|��#}tj||j�tj�SWdQXWntk
rIgSXdS(s=Return a list of all non overlapping matches in the string(s)N(Rtretfindalltreadt	MULTILINEtAttributeError(tregextfnametf((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
regex_findall0s
&
cC�sYtjdd|�}tjdd|�}tjdd|�jd�}|d|!}|S(	Ns^/(usr/|)(bin|sbin)/ts[^\w\-\.\/]+t_t/t.s ._-i(Rtsubtstrip(tcommandtname_maxtmangledname((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_mangle_command9s

c�st�fd�|D��S(Nc3�s|]}|�kVqdS(N((t.0tp(tpath(s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pys	<genexpr>Bs(tany(R't	path_list((R's8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_path_in_path_listAscC�sftjdftjdftjdftjdfg}x)|D]!}|d|j�r=|dSq=WdS(s� return a string indicating the type of special node represented by
    the stat buffer st (block, character, fifo, socket).
    sblock devicescharacter devices
named pipetsocketiiN(tstattS_ISBLKtS_ISCHRtS_ISFIFOtS_ISSOCKtst_mode(tstt_typestt((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
_node_typeEs
cC�s
|jd�S(s�Check if a file appears to be compressed

    Return True if the file specified by path appears to be compressed,
    or False otherwise by testing the file name extension against a
    list of known file compression extentions.
    s.gzs.xzs.bzs.bz2(s.gzs.xzs.bzs.bz2(R(R'((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_file_is_compressedTstSoSPredicatecB�seeZdZdZeZgZgZeddd�Z	d�Z
d�Zd�Zeggd�Z
RS(s�A class to implement collection predicates.

        A predicate gates the collection of data by an sos plugin. For any
        `add_cmd_output()`, `add_copy_spec()` or `add_journal()` call, the
        passed predicate will be evaulated and collection will proceed if
        the result is `True`, and not otherwise.

        Predicates may be used to control conditional data collection
        without the need for explicit conditional blocks in plugins.
    Rc
C�s�d}d|j}|j}|r?g|D]}||^q)n|}|ddj|�7}|j}|r�g|D]}	||	^qrn|}|ddj|�7}|||S(sxReturn a string representation of this SoSPredicate with
            optional prefix, suffix and value quoting.
        s"%s"sdry_run=%s, skmods=[%s], t,s
services=[%s](t_dry_runt_kmodstjoint	_services(
tselftquotetprefixtsuffixtquotestpstrtkmodstktservicesR((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt__strus
	)	)cC�s
|j�S(sqReturn a string representation of this SoSPredicate.

            "dry_run=False, kmods=[], services=[]"
        (t_SoSPredicate__str(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt__str__�scC�s|jdtdddd�S(s�Return a machine readable string representation of this
            SoSPredicate.

            "SoSPredicate(dry_run=False, kmods=[], services=[])"
        R>R?s
SoSPredicate(R@t)(RGtTrue(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt__repr__�scC�s�t}x'|jD]}||jj|�O}qWx'|jD]}||jj|�O}q:Wt|j|j|jg�s|tS|o�|jS(s#Predicate evaluation hook.
        (	tFalseR:t_ownertis_module_loadedR<tservice_is_runningR(R9RJ(R=tpvalueRDR((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt__nonzero__�scC�sE||_t|�|_t|�|_||jjdjB|_dS(s.Initialise a new SoSPredicate object.
        tcmdlineoptsN(RMtlistR:R<tcommonstdry_runR9(R=townerRURCRE((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt__init__�s	N(t__name__t
__module__t__doc__tNoneRMRLR9R:R<RGRHRKRQRW(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR7^s
			tPluginc
B�s�eZdZdOZeZdZdPZdQZ	dRZ
dSZdTZdOZ
dUZdZdZeZdOZdOZd�Zed��Zd�Zed��Zd�Zd	�Zd
�Zd�Zd�Zd
�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+edOd�Z,edOd�Z-d�Z.d�Z/d�Z0d�Z1d�Z2d �Z3d!�Z4d"�Z5d#�Z6d$�Z7dOd%�Z8d&�Z9d'�Z:d(�Z;d)d*�Z<d+dOd,�Z=d-�Z>dOedOd.�Z?deedOdOedOd/�Z@deedOd0�ZAd1�ZBdOdOdeedOdOedOdOd2�
ZCdOdOdeedOdOedOdOd3�
ZDdOed4�ZEd5�ZFd6�ZGd7�ZHdOd8�ZIdOedeedOdOedOd9�	ZJdOedeedOdOedOdOd:�
ZKd;�ZLd<�ZMd=�ZNdOdOdOdOdOedOdOdOdOdOdOd>�ZOed?�ZPd@�ZQdA�ZRdB�ZSdC�ZTdD�ZUdE�ZVdF�ZWdG�ZXdH�ZYdI�ZZdJ�Z[dK�Z\dL�Z]dM�Z^dN�Z_RS(VsA This is the base class for sosreport plugins. Plugins should subclass
    this and set the class variables where applicable.

    plugin_name is a string returned by plugin.name(). If this is set to None
    (the default) class\_.__name__.tolower() will be returned. Be sure to set
    this if you are defining multiple plugins that do the same thing on
    different platforms.

    requires_root is a boolean that specifies whether or not sosreport should
    execute this plugin as a super user.

    version is a string representing the version of the plugin. This can be
    useful for post-collection tooling.

    packages (files) is an iterable of the names of packages (the paths
    of files) to check for before running this plugin. If any of these packages
    or files is found on the system, the default implementation of
    check_enabled will return True.

    profiles is an iterable of profile names that this plugin belongs to.
    Whenever any of the profiles is selected on the command line the plugin
    will be enabled (subject to normal check_enabled tests).
    tunversionedRi,cC�sLt|dt�sg|_ng|_g|_g|_d|_g|_g|_||_	g|_
t�|_g|_
g|_|d|_|d|_d|j	kr�|j	dntjd�|_|jjd�xV|jD]K}|jj|d�|jji|dd
6|dd6|dd6�q�W|jt|��dS(Ntoption_listRtsysroottpolicytsoslogtsosttimeoutstimeout in seconds for plugintfasti����iitdescitspeeditenabled(stimeoutstimeout in seconds for pluginRdi����(tgetattrRLR^tcopied_filestexecuted_commandstalertstcustom_textt	opt_namest	opt_parmsRTtforbidden_pathstsett
copy_pathstcopy_stringstcollect_cmdsR_R`tloggingt	getLoggerRatappendt
set_predicateR7(R=RTtopt((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyRW�s0										

	"cC�s�d}y�|jd�}t|jd��}|dkrB|}nL|dk	ri|dkrit|�}n%|dk	r�|dkr�|}ndSWntk
r�|jSX|dk	r�|dkr�|S|jS(s�Returns either the default plugin timeout value, the value as
        provided on the commandline via -k plugin.timeout=value, or the value
        of the global --plugin-timeout option.
        tplugin_timeoutRci����N(R[t
get_optiontintt
ValueErrorRy(R=t_timeouttopt_timeouttown_timeout((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyRc�s 		
cC�s|jS(sV
        Checks to see if the plugin has hit its timeout.

        This is set when the sos.collect_plugin() method hits a timeout and
        terminates the thread. From there, a Popen() call can still continue to
        run, and we need to manually terminate it. Thus, check_timeout() should
        only be called in sos_get_command_output().

        Since sos_get_command_output() is not plugin aware, this method is
        handed to that call to use as a polling method, to avoid passing the
        entire plugin object.

        Returns True if timeout has been hit, else False.

        (t_timeout_hit(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
check_timeoutscC�s|jr|jS|jj�S(s^Returns the plugin's name as a string. This should return a
        lowercase string.
        (tplugin_nameRXtlower(tcls((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytname%s	cC�sd|j�|fS(Ns[plugin:%s] %s(R�(R=tmsg((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_format_msg.scC�s|jj|j|��dS(N(RaterrorR�(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
_log_error1scC�s|jj|j|��dS(N(RatwarningR�(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt	_log_warn4scC�s|jj|j|��dS(N(RatinfoR�(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt	_log_info7scC�s|jj|j|��dS(N(RatdebugR�(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
_log_debug:scC�s6|dtjkr |d}ntjj|j|�S(Nii(tostsepR'R;R_(R=R'((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytjoin_sysroot=s
cC�s7|j�s|S|j|j�r3|t|j�S|S(N(tuse_sysroott
startswithR_tlen(R=R'((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
strip_sysrootBs
cC�s|jtjjtj�kS(N(R_R�R'tabspathR�(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�IscC�s1|j|jj�g}tjj|�|jkS(N(R_tarchivetget_tmp_dirR�R'tcommonprefix(R=tpaths((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyttmp_in_sysrootLscC�s|jj|�dk	S(s'Is the package $package_name installed?N(R`tpkg_by_nameR[(R=tpackage_name((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytis_installedPscC�s|jjj|�S(s+Does the service $name exist on the system?(R`tinit_systemt
is_service(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�TscC�s|jjj|�S(sIs the service $name enabled?(R`R�t
is_enabled(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytservice_is_enabledXscC�s|jjj|�S(sIs the service $name disabled?(R`R�tis_disabled(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytservice_is_disabled\scC�s|jjj|�S(s'Is the service $name currently running?(R`R�t
is_running(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyRO`scC�s|jjj|�dS(s,Return the reported status for service $nametstatus(R`R�tget_service_status(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�dscC�s
||_dS(s<Set or clear the default predicate for this plugin.
        N(t	predicate(R=tpred((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyRwhscC�s
||_dS(s�Set or clear the default predicate for command collection
            for this plugin. If set, this predecate takes precedence
            over the `Plugin` default predicate for command and journal
            data collection.
        N(t
cmd_predicate(R=R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytset_cmd_predicatemscC�s3|dk	r|S|r,|jdk	r,|jS|jS(sqGet the current default `Plugin` or command predicate. If the
            `cmd` argument is `True`, the current command predicate is
            returned if set, otherwise the default `Plugin` predicate
            will be returned (which may be `None`).

            If no default predicate is set and a `pred` value is passed
            it will be returned.
        N(R[R�R�(R=tcmdR�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
get_predicateus
	cC�s2|jd|d|�}|dk	r.t|�StS(s1Test the current predicate and return its value.

            :param cmd: ``True`` if the predicate is gating a command or
                        ``False`` otherwise.
            :param pred: An optional predicate to override the current
                         ``Plugin`` or command predicate.
        R�R�N(R�R[tboolRL(R=R�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyttest_predicate�s
cC�sfd|d}|jd|�|js,dSd
}y�x�|jD]�}|dd
kr[q?n|ddkr�|jd|d�q?ntj|d|�r?tjj|jd	|d�}|j	j
|�}tjd
tj
�}|jd|j��\}}|r |j	j||�q q?q?WWn:tk
ra}	d}
|j|
|d|	f�d
}nX|S(shRemove certificate and key output archived by sosreport. cmd
        is the command name from which output is collected (i.e. exlcuding
        parameters). Any matching instances are replaced with: '-----SCRUBBED'
        and this function does not take a regexp or substituting string.

        This function returns the number of replacements made.
        t*s1Scrubbing certs and keys for commands matching %sitfiletbinarytyess6Cannot apply regex substitution to binary output: '%s'texetcmddirs-----BEGIN.*?-----ENDs
-----SCRUBBEDs4Certificate/key scrubbing failed for '%s' with: '%s'N(R�RjR[R�tfnmatchR�R'R;RTR�t	open_fileRtcompiletDOTALLtsubnRt
add_stringt	ExceptionR�(R=R�tglobstrtreplacementstcalledR'treadablet	certmatchtresultteR�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytdo_cmd_private_sub�s6			 !
cC�snd|d}|jd|||f�|js5dSd}y�x�|jD]�}|ddkrdqHn|ddkr�|jd|d�qHntj|d|�rHtjj|jd	|d�}|jd
|�|j	j
|�}tj|||j
��\}	}|r(|j	j|	|�q(qHqHWWn:tk
ri}
d}|j||d|
f�d}nX|S(
s_Apply a regexp substitution to command output archived by sosreport.
        cmd is the command name from which output is collected (i.e. excluding
        parameters). The regexp can be a string or a compiled re object. The
        substitution string, subst, is a string that replaces each occurrence
        of regexp in each file collected from cmd. Internally 'cmd' is treated
        as a glob with a leading and trailing '*' and each matching file from
        the current module's command list is subjected to the replacement.

        This function returns the number of replacements made.
        R�s4substituting '%s' for '%s' in commands matching '%s'iR�R�R�s6Cannot apply regex substitution to binary output: '%s'R�R�sapplying substitution to '%s's-regex substitution failed for '%s' with: '%s'N(R�RjR[R�R�R�R'R;RTR�R�RR�RR�R�R�(R=R�tregexptsubstR�R�R�R'R�R�R�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytdo_cmd_output_sub�s6			 !
cC�s9y�|j|�}|jd|�|jd|||f�|sGdS|jj|�}|j�}t|tj�s�|jdd�}nt	j
|||�\}}|r�|jj||�nd}Wnhtt
fk
r4}	|	jtjkrd}
|j|
|�nd}
|j|
||	f�d}nX|S(sgApply a regexp substitution to a file archived by sosreport.
        srcpath is the path in the archive where the file can be found.  regexp
        can be a regexp string or a compiled re object.  subst is a string to
        replace each occurance of regexp in the content of srcpath.

        This function returns the number of replacements made.
        ssubstituting scrpath '%s's"substituting '%s' for '%s' in '%s'itutf8tignores-file '%s' not collected, substitution skippeds-regex substitution failed for '%s' with: '%s'(t_get_dest_for_srcpathR�R�R�RRRtstring_typestdecodeRR�R�tOSErrortIOErrorterrnotENOENTR�(R=tsrcpathR�R�R'R�tcontentR�R�R�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytdo_file_sub�s.	

cC�s�t|d�s!tj|�}n|j}g|jD]}||d�r4|^q4}x%|D]}|j|d||�q]WdS(szApply a regexp substituation to a set of files archived by
        sos. The set of files to be substituted is generated by matching
        collected file pathnames against pathexp which may be a regular
        expression string or compiled re object. The portion of the file
        to be replaced is specified via regexp and the replacement string
        is passed in subst.tmatchR�N(thasattrRR�R�RiR�(R=tpathexpR�R�R�Rt	file_listR�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytdo_path_regex_subs	,
cC�s
t||�S(N(R(R=RR((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytdo_regex_find_allsc	C�stj|�}tjjtjj|�|�}tjj|�}tjj|�r�tjjtjj|��}tjj|d|�}|j	�r�|t
tjtj�}n|j
d||f�n|}|j
d||tjj|�f�|j|�}|jj||�tjj|�rB|j
d|�dS|jji|d6|d6dd6|d	6�ytj|�Wn7tk
r�}|jd
kr�|j
d|�dSnX|j
d||f�||kr�|j|�n|j
d
|�dS(Ntstarts&made link target '%s' relative as '%s's0copying link '%s' pointing to '%s' with isdir=%ss%link '%s' is a directory, skipping...R�tdstpathR�tsymlinktpointstoi(s;link '%s' is part of a file system loop, skipping target...s#normalized link target '%s' as '%s's.link '%s' points to itself, skipping target...(R�treadlinkR'R;tdirnametnormpathtisabstrealpathtrelpathR�R�R�tpardirR�tisdirR�R�tadd_linkRiRvR,R�R�t
_do_copy_path(	R=R�tlinkdesttdesttabsdesttrealdirtreldestR�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
_copy_symlinksF!					cC�s�yWxPtj|�D]?}|jd||f�tjj||�}|j|�qWWnItk
r�}|jtjkr�d}|j	d||f�dS�nXdS(Ns!recursively adding '%s' from '%s's)Too many levels of symbolic links copyings_copy_dir: %s '%s'(
R�tlistdirR�R'R;R�R�R�tELOOPR�(R=R�R�R'R�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt	_copy_dirRs	cC�sN|j�r|j|�}nx)|jD]}||dkr(|dSq(WdS(NR�R�(R�R�RiR[(R=R�tcopied((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�`scC�st||j�S(N(R*Ro(R=R'((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_is_forbidden_pathhscC�sStj|j�}tj|j�}|j}|jj||tj||��dS(N(R�tmajortst_rdevtminorR1R�tadd_nodetmakedev(R=R'R2tdev_majtdev_mintmode((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
_copy_nodeks	cC�s�|jr
dS|j|�r1|jd|�dS|s@|}n|j�r^|j|�}nytj|�}Wn)ttfk
r�|j	d|�dSXt
j|j�r�|j
|�dSt
j|j�rtj|tj�rtj|�s
|jj|�dS|j|�dSt
j|j�p<t
j|j�svt|�}|jd||f�|j||�dS|jd||f�|jd@s�|jjd|�n|jj||�|jji|d6|d	6d
d6�dS(s�Copy file or directory to the destination tree. If a directory, then
        everything below it is recursively copied. A list of copied files are
        saved for use later in preparing a report.
        Nsskipping forbidden path '%s'Rsfailed to stat '%s's creating %s node at archive:'%s's!copying path '%s' to archive:'%s'i$R�R�tnoR�(R�R�R�R�R�R�tlstatR�R�R�R,tS_ISLNKR1R�tS_ISDIRtaccesstR_OKR�R�tadd_dirR�tS_ISREGR5R�R�tadd_fileRiRv(R=R�R�R2tntype((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�rsJ		
'
$	
cC�s�t|tj�r|g}n|j�rOg|D]}|j|�^q1}nxI|D]A}|jd|�x'tj|�D]}|jj|�q}WqVWdS(snSpecify a path, or list of paths, to not copy, even if it's
            part of a copy_specs[] entry.
        sadding forbidden path '%s'N(	RRR�R�R�R�tglobRoRv(R=t	forbiddenRtforbidR'((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytadd_forbidden_path�s%
cC�s|j|jfS(s%return a list of all options selected(RmRn(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytget_all_options�scC�s�x�t|j|j�D]i\}}||krt|d�}|t|�krq|td�krq||�}n||d<tSqWtSdS(smSet the named option to value. Ensure the original type
           of the option value is preserved.
        RgN(RRmRnttypeR[RJRL(R=t
optionnametvalueR�tparmstdefaulttype((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
set_option�s"$
icC�syd}||kr&t|jd|�SxLt|j|j�D]5\}}||kr<|d}|dk	rq|Sq<q<W|S(	sHReturns the first value that matches 'optionname' in parameters
        passed in via the command line or set via set_option or via the
        global_plugin_options dictionary, in that order.

        optionaname may be iterable, in which case the first option that
        matches any of the option names is returned.
        tverifytall_logstlog_sizeRyRRRg(Rsall_logsslog_sizesplugin_timeoutN(RhRTRRmRnR[(R=R
tdefaulttglobal_optionsR�Rtval((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyRz�s	"
R8cC�sg|j|�}y?g|j|�D]}|j�^q"}ttd|��SWntk
rb|SXdS(sTWill try to return the option as a list separated by the
        delimiter.
        N(RztsplitR RSR	R[R�(R=R
t	delimiterRtoptionRxtopt_list((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytget_option_as_list�s(
cC�s|jj|�dS(N(Rqtupdate(R=Rq((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_add_copy_paths�sc	C�s�|jd|�s9|jd||jd|�f�dS|dkrW|jd�}n|jd�rod}n|r�|d9}n|s�tSt|tj�r�|g}nx|D]}|o�t	|�s�tS|j
�r�|j|�}n|j|�}t	|�dkrq�nd�}|j
d	|d
t�d}t}	d}
x�|D]�}
|j|
�rv|jd|
�qJny|tj|
�tj7}Wn"tk
r�|jd|
�nX|r�||kr�t}	Pn|j|
g�qJW|	r�|r�t|
�r�|
}|dtjkr0|jtj�}n|jtjjd
�d}|jt|
|�|�tjjdtjj|
��}
tjj|
d|j �|�}|j!j"||
�q�q�WdS(s�Add a file or glob but limit it to sizelimit megabytes. If fname is
        a single file the file will be tailed to meet sizelimit. If the first
        file in a glob is too large it will be tailed to meet the sizelimit.
        R�s,skipped copy spec '%s' due to predicate (%s)NRRiicS�s-ytjj|�SWntk
r(dSXdS(Ni(R�R'tgetmtimeR�(R'((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyRs
tkeytreversesskipping forbidden path '%s'sfailed to stat '%s'Rs.tailedRtsos_stringsi(#R�R�R�R[RzRLRRR�R�R�R�t_expand_copy_spectsortRJR�R�R�R,tST_SIZER�RR6R�tlstriptreplaceR'tadd_string_as_fileRR�R�R;R�R�R�(R=t	copyspecst	sizelimitttailitR�tcopyspectfilesRtcurrent_sizet
limit_reachedt_filet	file_nametstrfiletrel_patht	link_path((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
add_copy_spec�sb		

	

!c	C�sS|jr
dS|s)|jdjdkr5|j}	nd}	t|d|d|d|	d|d|d|d	|d
|j�}
|
ddkr�|jd
||f�n|
ddks�|
ddkrO|	r;|	dkr;|jdjdkr;|jd|j	�d|	f�|j
|d|dtd|d|d|�Sn|jd|�n|
S(NRRtalwaysRctstderrtchroottchdirtenvR�R*tpollerR�i|s command '%s' timed out after %dsi~iRs5command '%s' not found in %s - re-trying in host rootitrunats%could not run '%s': command not found(
R�RTR8R_R[RR�R�R�Rtget_command_outputRLR�(R=tprogRcR7R8R<R:R�R*trootR�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR=Cs0		 	
c
C�s%|j|d|d|d|d|�S(s[Execute a command independantly of the output gathering part of
        sosreport.
        RcR7R8R<(R=(R=R>RcR7R8R<((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
call_ext_proggscC�s|j|�ddkS(s�Execute a command independently of the output gathering part of
        sosreport and check the return code. Return True for a return code of 0
        and False otherwise.
        R�i(R@(R=R>((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytcheck_ext_progosc
C�s�|||||||||	|
f
}d}
d|
}|j||�|jdtd|�r�|jj|�|jd|�n)|jd||jdtd|�f�dS(s?Internal helper to add a single command to the collection list.s:('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s', '%s', '%s')spacked command tuple: R�R�sadded cmd output '%s's-skipped cmd output '%s' due to predicate (%s)N(R�R�RJRsRvR�R�(R=R�tsuggest_filenametroot_symlinkRcR7R8R<R:R�R*R�tcmdtt	_tuplefmtt_logstr((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_add_cmd_outputvs	
	c
C�s�t|tj�r|g}nt|�dkrL|s<|rL|jd�n|
dkrj|jd�}
nxW|D]O}|j|d|d|d|d|d|d	|d
|d|	d|
d
|�
qqWdS(s:Run a program or a list of programs and collect the outputis.ambiguous filename or symlink for command listRRBRCRcR7R8R<R:R�R*R�N(RRR�R�R�R[RzRG(
R=tcmdsRBRCRcR7R8R<R:R�R*R�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytadd_cmd_output�s
cC�s_tjj|jj�d|j��}|rEtjj||�}n|r[tj|�n|S(s[Return a path into which this module should store collected
        command output
        tsos_commands(R�R'R;R�R�R�tmakedirs(R=R�tmaketcmd_output_path((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytget_cmd_output_path�scG�s
t||�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 line.
        (R(R=R�tfnames((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt	file_grep�scC�s|jj�}t||�S(N(R�R"R$(R=R�R"((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR$�scC�s�tjj|jd|j�|j|��}tjj|�r�d}xCtr�d||f}tjj|�s{|}Pn|d7}qIWn|S(s@The internal function to build up a filename based on a command.R�is%s_%di(R�R'R;RTR�R$texistsRJ(R=R�toutfntinctnewfn((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_make_command_filename�s	cC�s�|r|j�dnd}t|tj�sC|jdd�}n|jdtd|�s�|jd||jd|�f�dS|j	j
||f�|jd	||f�dS(
s6Add a string to the archive as a file named `filename`iRR�R�R�R�s,skipped string ...'%s' due to predicate (%s)Nsadded string ...'%s' as '%s'(t
splitlinesRRR�R�R�RLR�R�RrRvR�(R=R�tfilenameR�tsummary((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR(�s	cC�sY|jr
dSt�}|j|d|d|d|d|d|d|	d|
�}|jd	|j�d
t�|f�|r�|j|�}
n|j|�}
|
t|jd�d}|	r�|jj	|d
|
�n|jj
|d
|
�|r|jj|
|�n|jj
i|d6|d6|	r2dndd6�tjj|jj�|
�S(s]Execute a command and save the output to a file for inclusion in the
        report.
        NRcR7R8R<R:R�R*scollected output of '%s' in %siR�itoutputR�R�R�R�(R�RR=R�RRUR�RTR�t
add_binaryR�R�RjRvR�R'R;tget_archive_path(R=R�RBRCRcR7R8R<R:R�R*R�R�RRtoutfn_strip((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_get_cmd_output_now�s*				cC�s||jdtd|�sE|jd||jdtd|�f�dS|j|d|d|d|d|d|d	|	d
|
�S(s]Execute a command and save the output to a file for inclusion in the
        report.
        R�R�s-skipped cmd output '%s' due to predicate (%s)RcR7R8R<R:R�R*N(R�RJR�R�R[R](R=R�RBRCRcR7R8R<R:R�R*R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytget_cmd_output_now�s	 cC�s||jjkS(s?Return whether specified module as module_name is loaded or not(R`tkernel_mods(R=tmodule_name((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyRNscC�s|jj|�dS(spAdd an alert to the collection of alerts for this plugin. These
        will be displayed in the report
        N(RkRv(R=talertstring((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt	add_alertscC�s|j|7_dS(svAppend text to the custom text that is included in the report. This
        is freeform and can include html.
        N(Rl(R=ttext((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytadd_custom_textsc
	C�s�d}
d}d}d}d}d}d}d}d	}d
}|jd�}|p]|jd�}|sut||�nd
}t|tj�r�|g}n|r�x|D]}|
||7}
q�Wn|	r�|
||	7}
n|
r�|
|7}
n|r�|
d7}
n|r?|dkrd}n|dkr.d}n|
||7}
n|rV|
||7}
n|rm|
||7}
n|r�|
||7}
n|r�|
||7}
n|jd|
�|j|
d|d|d|�dS(s7Collect journald logs from one of more units.

        :param units: A string, or list of strings specifying the
                       systemd units for which journal entries will be
                       collected.

        :param boot: A string selecting a boot index using the
                      journalctl syntax. The special values 'this' and
                      'last' are also accepted.

        :param since: A string representation of the start time for
                       journal messages.

        :param until: A string representation of the end time for
                       journal messages.

        :param lines: The maximum number of lines to be collected.

        :param allfields: A bool. Include all journal fields
                           regardless of size or non-printable
                           characters.

        :param output: A journalctl output control string, for
                        example "verbose".

        :param timeout: An optional timeout in seconds.
        :param identifier: An optional message identifier.
        :param catalog: Bool. If True, augment lines with descriptions
                        from the system catalog.
        :param sizelimit: Limit to the size of output returned in MB.
                          Defaults to the value of --log-size.
        sjournalctl --no-pager s
 --unit %ss
 --boot %ss --since %ss --until %ss --lines %ss --output %ss --identifier %ss
 --catalogidRRis --alltthisRtlasts-1scollecting journal: %sRcR*R�N(RztmaxRRR�R�RG(R=tunitstboottsincetuntiltlinest	allfieldsRYRct
identifiertcatalogR*R�tjournal_cmdtunit_opttboot_optt	since_optt	until_optt	lines_optt
output_opttidentifier_opttcatalog_opttjournal_sizeRRtunit((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytadd_journalsR#


		cC�std}|r|d7}nt|tj�r7|g}nx6|D].}|jd|�|jd||f�q>WdS(sGCollect udevadm info output for a given device

        :param device: A string or list of strings of device names or sysfs
                       paths. E.G. either '/sys/class/scsi_host/host0' or
                       '/dev/sda' is valid.
        :param attrs: If True, run udevadm with the --attribute-walk option.
        sudevadm infos -ascollecting udev info for: %ss%s %sN(RRR�R�RG(R=tdevicetattrstudev_cmdtdev((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
add_udev_infoxs

cC�s
tj|�S(N(R(R=R,((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR#�scC�s6x/|jD]$}|jd|�|j|�q
WdS(Nscollecting path '%s'(RqR�R�(R=R'((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_collect_copy_specs�scC�s�x�t|j�D]�}|d\
}}}}}}}}	}
}|jddd|d�|jd|�|j|d|d|d|d	|d
|d|d|	d
|
d|�	qWdS(Nisunpacked command tuple: s.('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s',s'%s %s')scollecting output of '%s'RBRCRcR7R8R<R:R�R*(RRsR�R�R](R=tprogsR>RBRCRcR7R8R<R:R�R*((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_collect_cmd_output�s	(cC�s�x�|jD]�\}}|jr#dSd}|ri|j�d}t|tj�si|jdd�}qin|jd||f�y/|jj	|t
jjd|j
�|��Wq
tk
r�}|jd||f�q
Xq
WdS(NRiR�R�s!collecting string ...'%s' as '%s'R"scould not add string '%s': %s(RrR�RVRRR�R�R�R�R�R�R'R;R�R�R�(R=tstringR1R�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt_collect_strings�s$				cC�sUt�}|j�|j�|j�|j�t�|f}|jd|�dS(sCollect the data for a plugin.scollected plugin '%s' in %sN(RR�R�R�R�R�(R=R�tfields((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytcollect�s	


cC�s[yBt|d�r(|jr(|jj�St|j|�jj�SWntk
rVdSXdS(s9 This function will return the description for the pluginRZs<no description available>N(R�RZR tsupert	__class__R�(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytget_description�s

c
C�sUt|j|j|j|j|jg�r*t|jtj�rQ|jg|_nt|jtj�rx|jg|_nt|jtj�r�|jg|_nt|jtj�r�|jg|_nt|jtj�r�|jg|_nt|t	�rgt
|�_x�|j�D]�}g|jD]}|i|d6^q(}g|jD]}|i|d6^qO}g|jD]}|i|d6^qv}g|jD]}|i|d6^q�}	|j
||||	�rt
|�jj|�qqWtt
|�j�dkS|j
|j|j|j|j�St|t	�rQ|j�t
|�_ntS(s�This method will be used to verify that a plugin should execute
        given the condition of the underlying environment.

        The default implementation will return True if none of class.files,
        class.packages, nor class.commands is specified. If any of these is
        specified the plugin will check for the existence of any of the
        corresponding paths, packages or commands and return True if any
        are present.

        For SCLPlugin subclasses, it will check whether the plugin can be run
        for any of installed SCLs. If so, it will store names of these SCLs
        on the plugin class in addition to returning True.

        For plugins with more complex enablement checks this method may be
        overridden.
        tscl_namei(R(R-tpackagestcommandsR_RERRR�t	SCLPluginRt
_scls_matchedt	_get_sclst_check_plugin_triggersRvR�RJ(
R=tsclRR-R&R�tcR�RRE((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
check_enabled�s@''''		
c�s�td�|D��p�t�fd�|D��p�td�|D��p�t�fd��jD��p�t�fd�|D��S(Ncs�s!|]}tjj|�VqdS(N(R�R'RQ(R%R((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pys	<genexpr>sc3�s|]}�j|�VqdS(N(R�(R%tpkg(R=(s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pys	<genexpr>scs�s|]}t|�VqdS(N(R(R%R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pys	<genexpr>sc3�s|]}�j|�VqdS(N(RN(R%tmod(R=(s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pys	<genexpr>sc3�s|]}�j|�VqdS(N(R�(R%tsvc(R=(s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pys	<genexpr>s(R(R_(R=R-R�R�RE((R=s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�s
cC�stS(swThis decides whether a plugin should be automatically loaded or
        only if manually specified in the command line.(RJ(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytdefault_enabledscC�s|jt|j��dS(s�Collect the list of files declared by the plugin. This method
        may be overridden to add further copy_specs, forbidden_paths, and
        external programs if required.
        N(R5RSR-(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytsetupscC�s�t|d�s|jr_t|d�rX|jrXg|jD]}|d^q<|_q_dSn|jj}|j|j�}|r�|j|�ndS(Ntverify_packagesR�t$(R�R�R�R`tpackage_managertbuild_verify_commandRI(R=R&tpmt
verify_cmd((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytsetup_verify s&cC�sdS(sLPerform any postprocessing. To be replaced by a plugin if required.
        N((R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytpostproc-scC�sd|j�}|d|j�d}t|j�r�|d}xr|jD]g}|ddt|d�t|d�f}|d	d
kr�|dt|d�}n|d
}qKW|d}nt|j�ry|d}x�|jD]�}|drPt|d�rPdt|jd�dt|d�}|d|t|d�f}q�|dt|d�}q�W|d}nt|j�r�|d}x%|jD]}|dt|�}q�W|d}n|jdkr�|d}|t|j�d}ntj	r|j
d�S|SdS(sm Present all information that was gathered in an html file that
        allows browsing the results.
        u<hr/><a name="%s"></a>
s<h2> Plugin <em>s</em></h2>
s<p>Files copied:<br><ul>
s<li><a href="%s">%s</a>u..R�R�R�R�s (symlink to %s)R�s</li>
s
</ul></p>
s<p>Commands Executed:<br><ul>
R�u../R�Rs<li><a href="%s">%s</a></li>
R�s<li>%s</li>
s<p>Alerts:<br><ul>
Rs<p>Additional Information:<br>
s</p>
R�N(R�R�RiRRjRTRkRlRtPY2tencode(R=thtmltafileR�tcmd_rel_pathtalert((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytreport2s>
&

)



	
c	C�s�t}d}yZtj|�}xD|D]<}t|d�}|j�j�}||kr%t}q%q%WWntk
r|}tSX|S(saChecks if a named process is found in /proc/[0-9]*/cmdline.
        Returns either True or False.s/proc/[0-9]*/cmdlinetr(RLRtopenRR RJR�(	R=tprocessR�t
cmd_line_globtcmd_line_pathsR'Rtcmd_lineR�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytcheck_process_by_namegs
c	C�s�g}d}tj|�}x~|D]v}yWt|d��B}|j�j�}||krx|j|jd�d�nWdQXWq"tk
r�}q"q"Xq"W|S(slReturns PIDs of all processes with process name.
        If the process doesn't exist, returns an empty lists/proc/[0-9]*/cmdlineR�RiN(RR�RR RvRR�(	R=R�tpidsR�R�R'RR�R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytget_process_pidsws
'N(((((((`RXRYRZR[R�RJt
requires_roottversionR�R-R�R_RER�tprofilesR_RyRLR�R�R�RWtpropertyRcR�tclassmethodR�R�R�R�R�R�R�R�R�R�R�R�R�R�ROR�RwR�R�R�R�R�R�R�R�R�R�R�R�R�R�R
RRRzRRR5R=R@RARGRIRNRPR$RUR(R]R^RNRbRdR{R�R#R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR\�s�	"																			
	&	+	$			;				<				K	"			
					#					W									=				
		5	tRedHatPlugincB�seZdZRS(s/Tagging class for Red Hat's Linux distributions(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR��sR�cB�sSeZdZed��Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(s�Superclass for plugins operating on Software Collections (SCLs).

    Subclasses of this plugin class can specify class.files and class.packages
    using "%(scl_name)s" interpolation. The plugin invoking mechanism will try
    to match these against all found SCLs on the system. SCLs that do match
    class.files or class.packages are then accessible via self.scls_matched
    when the plugin is invoked.

    Additionally, this plugin class provides "add_cmd_output_scl" (run
    a command in context of given SCL), and "add_copy_spec_scl" and
    "add_copy_spec_limit_scl" (copy package from file system of given SCL).

    For example, you can implement a plugin that will list all global npm
    packages in every SCL that contains "npm" package:

    class SCLNpmPlugin(Plugin, SCLPlugin):
        packages = ("%(scl_name)s-npm",)

        def setup(self):
            for scl in self.scls_matched:
                self.add_cmd_output_scl(scl, "npm ls -g --json")
    cC�s4tt|�d�s'gt|�_nt|�jS(NR�(R�RR�(R=((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytscls_matched�scC�s3td�d}g|j�D]}|j�^qS(Nsscl -lRY(RRVR (R=RYR�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR��scC�s�|jj�}y&td|d�j�jd�}Wn*tk
ra}|jd||f�nXtjd}x-|j	d�D]}d||||f}qWd|||f}|S(	sCwrapping command in "scl enable" call and adds proper PATH
        s/etc/scl/prefixes/%sR�s
s*Failed to find prefix for SCL %s, using %stPATHt:s
%s/%s%s:%ssscl enable %s "PATH=%s %s"(
R`tget_default_scl_prefixR�RtrstripR�R�R�tenvironR(R=R�R�R?R�R'R&tscl_cmd((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytconvert_cmd_scl�s
	
cK�sbt|tj�r|g}ng}x'|D]}|j|j||��q+W|j||�dS(spSame as add_cmd_output, except that it wraps command in
        "scl enable" call and sets proper PATH.
        N(RRR�RvR�RI(R=R�RHtkwargstscl_cmdsR�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytadd_cmd_output_scl�s
cC�s\|jj�}xFddgD]8}tjd|�}|jd|||f|�}qW|S(Ntetctvars^/%s/s
/%s/%s/%s/(R`R�RR�R(R=R�R,t
scl_prefixtrootdirR&((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytconvert_copyspec_scl�s
cC�s_t|tj�r|g}ng}x'|D]}|j|j||��q+W|j|�dS(s`Same as add_copy_spec, except that it prepends path to SCL root
        to "copyspecs".
        N(RRR�RvR�R5(R=R�R)t
scl_copyspecsR,((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytadd_copy_spec_scl�s
cK�s |j|j||�|�dS(seSame as add_copy_spec_limit, except that it prepends path to SCL
        root to "copyspec".
        N(tadd_copy_spec_limitR�(R=R�R,R�((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pytadd_copy_spec_limit_scl�s(RXRYRZR�R�R�R�R�R�R�R�(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR��s					tPowerKVMPlugincB�seZdZRS(s$Tagging class for IBM PowerKVM Linux(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR��st
ZKVMPlugincB�seZdZRS(s Tagging class for IBM ZKVM Linux(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR��stUbuntuPlugincB�seZdZRS(sTagging class for Ubuntu Linux(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR��stDebianPlugincB�seZdZRS(sTagging class for Debian Linux(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR��st
SuSEPlugincB�seZdZRS(s*Tagging class for SuSE Linux distributions(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�stIndependentPlugincB�seZdZRS(s6Tagging class for plugins that can run on any platform(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�	stExperimentalPlugincB�seZdZRS(s=Tagging class that indicates that this plugin is experimental(RXRYRZ(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyR�scC�s)d|}|stf}nt||�S(s�Import name as a module and return a list of all classes defined in that
    module. superclasses should be a tuple of valid superclasses to import,
    this defaults to (Plugin,).
    ssos.plugins.%s(R\R(R�tsuperclassest
plugin_fqname((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt
import_plugins
(-RZt
__future__Rt
sos.utilitiesRRRRRRR�RRR,RRtR�R�Rt	six.movesRR	tFileNotFoundErrort	NameErrorR�RRR$R*R5R6tobjectR7R\R�R�R�R�R�R�R�R�R�R[R�(((s8/usr/lib/python2.7/site-packages/sos/plugins/__init__.pyt<module>sL.

							
P�����c