????

Your IP : 216.73.216.152


Current Path : /usr/lib/python2.7/site-packages/sos/
Upload File :
Current File : //usr/lib/python2.7/site-packages/sos/archive.pyo

�
Dr^c@sOddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
mZyddlZWnek
r�nXddlZejr�eZndZdZdZdZd	efd
��YZdefd��YZd
ejfd��YZdefd��YZdS(i����N(tLock(tPopen(tsos_get_command_outputt
is_executabletfiletlinktnodetdirtArchivecBs�eZdZed��Zejd�ZdZe	Z
e�Zd�Z
d�Zd�Zd�Zd�Zd	�Zdd
�Zdd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(s!Abstract base class for archives.cCs|jS(s6Returns the archive class's name as a string.
        (t__name__(tcls((s//usr/lib/python2.7/site-packages/sos/archive.pytarchive_type.stsostunsetcCsd|j�|fS(Ns[archive:%s] %s(R(tselftmsg((s//usr/lib/python2.7/site-packages/sos/archive.pyt_format_msg;scCs
||_dS(N(t_debug(Rtdebug((s//usr/lib/python2.7/site-packages/sos/archive.pyt	set_debug>scCs|jj|j|��dS(N(tlogterrorR(RR((s//usr/lib/python2.7/site-packages/sos/archive.pyt	log_errorAscCs|jj|j|��dS(N(RtwarningR(RR((s//usr/lib/python2.7/site-packages/sos/archive.pytlog_warnDscCs|jj|j|��dS(N(RtinfoR(RR((s//usr/lib/python2.7/site-packages/sos/archive.pytlog_infoGscCs*|js
dS|jj|j|��dS(N(RRRR(RR((s//usr/lib/python2.7/site-packages/sos/archive.pyt	log_debugJs	cCs
t�dS(N(tNotImplementedError(Rtsrctdest((s//usr/lib/python2.7/site-packages/sos/archive.pytadd_fileRstwcCs
t�dS(N(R(RtcontentRtmode((s//usr/lib/python2.7/site-packages/sos/archive.pyt
add_stringUscCs
t�dS(N(R(RR!R((s//usr/lib/python2.7/site-packages/sos/archive.pyt
add_binaryXscCs
t�dS(N(R(Rtsourcet	link_name((s//usr/lib/python2.7/site-packages/sos/archive.pytadd_link[scCs
t�dS(N(R(Rtpath((s//usr/lib/python2.7/site-packages/sos/archive.pytadd_dir^scCs
t�dS(N(R(RR(R"tdevice((s//usr/lib/python2.7/site-packages/sos/archive.pytadd_nodeascCs
t�dS(s�Return a temporary directory that clients of the archive may
        use to write content to. The content of the path is guaranteed
        to be included in the generated archive.N(R(R((s//usr/lib/python2.7/site-packages/sos/archive.pytget_tmp_dirdscCs
t�dS(s�Return the maximum file name length this archive can support.
        This is the lesser of the name length limit of the archive
        format and any temporary file system based cache.N(R(R((s//usr/lib/python2.7/site-packages/sos/archive.pytname_maxjscCsdS(sTReturn a string representing the path to the temporary
        archive. For archive classes that implement in-line handling
        this will be the archive file itself. Archives that use a
        directory based cache prior to packaging should return the
        path to the temporary directory where the report content is
        locatedN((R((s//usr/lib/python2.7/site-packages/sos/archive.pytget_archive_pathpscCsdS(s:Clean up any temporary resources used by an Archive class.N((R((s//usr/lib/python2.7/site-packages/sos/archive.pytcleanupyscCs|j�dS(sFinalize an archive object via method. This may involve creating
        An archive that is subsequently compressed or simply closing an
        archive that supports in-line handling. If method is automatic then
        the following methods are tried in order: xz, bz2 and gzipN(tclose(Rtmethod((s//usr/lib/python2.7/site-packages/sos/archive.pytfinalize}sN(R	t
__module__t__doc__tclassmethodRtloggingt	getLoggerRt_nametFalseRRt
_path_lockRRRRRRtNoneRR#R$R'R)R+R,R-R.R/R2(((s//usr/lib/python2.7/site-packages/sos/archive.pyR+s.																tFileCacheArchivecBs�eZdZdZdZdZd�Zd�Zd�Zdd�Z	ded�Zdd�Z
d	d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�ZRS(sd Abstract superclass for archive types that use a temporary cache
    directory in the file system. tcCs�||_||_||_||_||_||_tjj||�|_	|j
�tj|j	d�WdQX|jd|j	f�dS(Ni�s*initialised empty FileCacheArchive at '%s'(
R8t_tmp_dirt_policyt_threadstenc_optstsysroottosR(tjoint
_archive_rootR:tmakedirsR(RtnamettmpdirtpolicytthreadsRARB((s//usr/lib/python2.7/site-packages/sos/archive.pyt__init__�s						
	cCs=tjj|�r'|jtj�}ntjj|j|�S(N(RCR(tisabstlstriptsepRDRE(RRG((s//usr/lib/python2.7/site-packages/sos/archive.pyt	dest_path�scCsL|j|j�r|S|dtjkr6|d}ntjj|j|�S(Nii(t
startswithRBRCRNR(RD(RR(((s//usr/lib/python2.7/site-packages/sos/archive.pytjoin_sysroot�s

i�cs7|jd|�|j�|}�fd�}|jd�sG|}n7tjj|j|��rh|ntjj|�d}|}g}xG|dkr�|dkr�tjj|�\}}	|j|	�|}q�W|j	��}
d}xF|D]>}tjj
|
|�}
||
�sq�ntjj
||�}tjj|
�s�|jd|
�tjj|�rtjj|�rtj
|�}
tjj|�d}tjj
||
�}|j|d|�}tjj|�}|jd|
|
f�tj|
|
�q/|jd	|
�tj|
|�|}q�q�W|S(
s�Create leading path components

            The standard python `os.makedirs` is insufficient for our
            needs: it will only create directories, and ignores the fact
            that some path components may be symbolic links.

            :param src: The source path in the host file system for which
                        leading components should be created, or the path
                        to an sos_* virtual directory inside the archive.

                        Host paths must be absolute (initial '/'), and
                        sos_* directory paths must be a path relative to
                        the root of the archive.

            :param mode: An optional mode to be used when creating path
                         components.
            :returns: A rewritten destination path in the case that one
                      or more symbolic links in intermediate components
                      of the path have altered the path destination.
        sMaking leading paths for %scs|jtjj�d��S(s>Test whether path ``path`` is inside the archive.
            R=(RPRCR(RD(R((troot(s//usr/lib/python2.7/site-packages/sos/archive.pyt
in_archive�st/iR=sMaking path %sR"sMaking symlink '%s' -> '%s'sMaking directory %s(RRERPRCR(tisdirRQtsplittappendtreverseRDtexiststislinktreadlinkt_make_leading_pathstnormpathtsymlinktmkdir(RRR"RRStsrc_dirR(t
path_compstheadttailtabs_pathtsrc_pathtcompttargett
target_dirt
target_src((RRs//usr/lib/python2.7/site-packages/sos/archive.pyR\�sJ		!



$	
c

Cs�|p|j|�}|tkr*|}ntjj|�d}|sJ|Stjj|�r�tjj|�r�td|��nJtjj|�s�|tkr�|ntjj|�d}|j|�nd�}|r�|Stjj|�r�tj	|�}d}	|t
kr>tj|j
�r>t|	|df��n|tkrvtj|j
�rvt|	|df��n|tkr�||j
�r�t|	|df��n|tkr�tj|j
�r�t|	|df��nd	S|S(
s4Check a new destination path in the archive.

            Since it is possible for multiple plugins to collect the same
            paths, and since plugins can now run concurrently, it is possible
            for two threads to race in archive methods: historically the
            archive class only needed to test for the actual presence of a
            path, since it was impossible for another `Archive` client to
            enter the class while another method invocation was being
            dispatched.

            Deal with this by implementing a locking scheme for operations
            that modify the path structure of the archive, and by testing
            explicitly for conflicts with any existing content at the
            specified destination path.

            It is not an error to attempt to create a path that already
            exists in the archive so long as the type of the object to be
            added matches the type of object already found at the path.

            It is an error to attempt to re-create an existing path with
            a different path type (for example, creating a symbolic link
            at a path already occupied by a regular file).

            :param src: the source path to be copied to the archive
            :param path_type: the type of object to be copied
            :param dest: an optional destination path
            :param force: force file creation even if the path exists
            :returns: An absolute destination path if the path should be
                      copied now or `None` otherwise
        is'path '%s' exists and is not a directorycSs:ttj|�tj|�tj|�tj|�g�S(N(tanytstattS_ISBLKtS_ISCHRtS_ISFIFOtS_ISSOCK(R"((s//usr/lib/python2.7/site-packages/sos/archive.pyt
is_special-s
s path '%s' exists and is not a %ssregular files
symbolic linksspecial filet	directoryN(ROtP_DIRRCR(RVRYRUt
ValueErrorR\tlstattP_FILERktS_ISREGtst_modetP_LINKtS_ISLNKtP_NODEtS_ISDIRR;(
RRt	path_typeRtforcetdest_dirR`Rptsttve_msg((s//usr/lib/python2.7/site-packages/sos/archive.pyt_check_path�s8	%
(	cCs�|j��|s|}n|j|t�}|s5dSt|dd�soytj||�WnKtk
r�}|jd�s�|jd�r�q�|j	d||f�nXy�t
j|�}|jd�s�|jd�rtj||�t
j
|d|j|jf�ntj||�t
j||j|j�Wn*tk
ra}|jd||f�nXd|}nI|jd�t|d	��%}x|D]}|j|�q�WWdQXd
}|jd||jf�WdQXdS(Ntreads/sys/s/proc/scaught '%s' copying '%s'tnss&caught '%s' setting attributes of '%s's'%s'iR s	open files!added %s to FileCacheArchive '%s'(R:R�RutgetattrR;tshutiltcopytIOErrorRPRRCRktcopymodetutimetst_atime_nstst_mtime_nstcopystattchowntst_uidtst_gidt	ExceptionRtseektopentwriteRE(RRRteRkt	file_nametftline((s//usr/lib/python2.7/site-packages/sos/archive.pyRIs>
	"	


	R c	Cs�|j��|}|j|tdt�}tj||dd�}t|t�rd|jdd�}n|j	|�t
jj|�r�yt
j||�Wq�tk
r�}|jd||f�q�Xn|jd||jf�WdQXdS(NR}tencodingsutf-8tutf8tignores!Unable to add '%s' to archive: %ss-added string at '%s' to FileCacheArchive '%s'(R:R�RutTruetcodecsR�t
isinstancetbytestdecodeR�RCR(RYR�R�tOSErrorRRRE(RR!RR"RR�R�((s//usr/lib/python2.7/site-packages/sos/archive.pyR#ws

		c	Cso|j�`|j|t�}|s&dStj|ddd�}|j|�|jd||jf�WdQXdS(NtwbR�s,added binary content at '%s' to archive '%s'(	R:R�RuR�R�R;R�RRE(RR!RR�((s//usr/lib/python2.7/site-packages/sos/archive.pyR$�s

	c		Cs>|jd||f�|j�c|j|t�}|s=dStjj|�stj||�|jd|||jf�nWdQX|jd|||f�tjj	|�}tjj
tjj||��}|j|�}d�}tjj
|�s-tjj|�r�|}tjj	|�}tjj|tj|��}tjj||�}|||�r�|jd||f�dS|jd||f�|j||�q-tjj|�r�|jd|�|j|�q-tjj|�r|jd|�|j|�q-|jd	||f�n|jd
�dS(Nsadding symlink at '%s' -> '%s's-added symlink at '%s' to '%s' in archive '%s's.Link follow up: source=%s link_name=%s dest=%scSs�tjj|�}tjj|�sHtjjtjj||��}ntjj|�}||krjtSytj|�Wn)tk
r�}|j	dkr�tS�nXt
S(s�Return ``True`` if the symbolic link ``link_name`` is part
                of a file system loop, or ``False`` otherwise.
            i((RCR(tdirnameRLtrealpathRDR�RkR�terrnoR9(R&R%tlink_dirR�((s//usr/lib/python2.7/site-packages/sos/archive.pytis_loop�s$s#Link '%s' - '%s' loops: skipping...s'Adding link %s -> %s for link follow ups Adding dir %s for link follow ups!Adding file %s for link follow ups)No link follow up: source=%s link_name=%ssleaving add_link()(RR:R�RxRCR(tlexistsR^RER�R�RDRORYRZR[trelpathR'RUR)tisfileR(	RR%R&Rt
source_dirthost_path_nametdest_path_nameR�R~((s//usr/lib/python2.7/site-packages/sos/archive.pyR'�sJ
		!				cCs$|j�|j|t�WdQXdS(smCreate a directory in the archive.

            :param path: the path in the host file system to add
        N(R:R�Rr(RR(((s//usr/lib/python2.7/site-packages/sos/archive.pyR)�s
cCs�|j|t�}|sdStjj|�s�ytj|||�WnLtk
r�}|jtjkr�d}|j	d||f�dS|�nXt
j||�ndS(NsOperation not permittedsadd_node: %s - mknod '%s'(R�RzRCR(RYtmknodR�R�tEPERMRR�R�(RR(R"R*RR�R((s//usr/lib/python2.7/site-packages/sos/archive.pyR+�s
cCs7dtjkr/tjd}tj|j|�SdSdS(NtPC_NAME_MAXi�(RCtpathconf_namestpathconfRE(Rtpc_name_max((s//usr/lib/python2.7/site-packages/sos/archive.pyR-�s
cCs|jS(N(RE(R((s//usr/lib/python2.7/site-packages/sos/archive.pyR,scCs|jS(N(RE(R((s//usr/lib/python2.7/site-packages/sos/archive.pyR.scCsCtjtjj|j|�d|�|jd||jf�dS(ssCreate path, including leading components.

            Used by sos.sosreport to set up sos_* directories.
        R"s2created directory at '%s' in FileCacheArchive '%s'N(RCRFR(RDRER(RR(R"((s//usr/lib/python2.7/site-packages/sos/archive.pyRFs%	cCs+|j|�}tj|ddddd�S(NtrR�sutf-8terrorsR�(ROR�R�(RR(((s//usr/lib/python2.7/site-packages/sos/archive.pyt	open_filescCs,tjj|j�r(tj|j�ndS(N(RCR(RURER�trmtree(R((s//usr/lib/python2.7/site-packages/sos/archive.pyR/scCs|jd|j|f�|j�|j�|jd|jtj|j�jf�||_y|j	�}Wn7t
k
r�}d}|jd||f�|j�SX|j
dr�y|j|�SWqt
k
r�}d}|jd||f�|SXn|SdS(Ns)finalizing archive '%s' using method '%s'sbuilt archive at '%s' (size=%d)s+An error occurred compressing the archive: s%s %stencrypts)An error occurred encrypting the archive:(RREt_build_archiveR/t
_archive_nameRCRktst_sizeR1t	_compressR�RRGRAt_encrypt(RR1tresR�texp_msg((s//usr/lib/python2.7/site-packages/sos/archive.pyR2s*	

	
cCs,|jdd�}|d7}d|}d}|jdr[|d|jd7}||7}n|jdr�d|jdjd	d
�}i|d6}|d7}d
|}||7}nt|ddd|�}|ddkr�|S|ddkr|jdrd}qd}nd|d}t|��dS(s�Encrypts the compressed archive using GPG.

        If encryption fails for any reason, it should be logged by sos but not
        cause execution to stop. The assumption is that the unencrypted archive
        would still be of use to the user, and/or that the end user has another
        means of securing the archive.

        Returns the name of the encrypted archive, or raises an exception to
        signal that encryption failed and the unencrypted archive name should
        be used.
        s
sosreport-ssecured-sosreport-s.gpgsgpg --batch -o %s tkeys--trust-model always -e -r %s tpasswords%ss'"R=tsos_gpgs-c --passphrase-fd 0 s!/bin/bash -c "echo $sos_gpg | %s"ttimeoutitenvtstatusisSpecified key not in keyringsCould not read passphrasesgpg exited with code %sN(treplaceR;RARR�(Rtarchivetarc_nametenc_cmdR�tpasswdR�R((s//usr/lib/python2.7/site-packages/sos/archive.pyR�1s,









		N(R	R3R4R>RER�RKRORQR\R;R9R�RR#R$R'R)R+R-R,R.RFR�R/R2R�(((s//usr/lib/python2.7/site-packages/sos/archive.pyR<�s.	
		WK.		H										t_TarFilecBseZdeddd�ZRS(c	Cs�|jd�|dkr"|}n|dk	rtddl}|jdtd�||�rt|jdd|�dSn|jdk	r�tjj	|�|jkr�|jdd|�dS|jd|�|j
||�}|dkr�|jdd	|�dS|dk	r;||�}|dkr;|jdd|�dSn|j�rutj
|d
��}|j||�WdQXn�|j�r�|j|�|r�xQtj|�D]=}|jtjj||�tjj||�|||�q�Wq�n
|j|�dS(s~Add the file `name' to the archive. `name' may be any type of file
           (directory, fifo, symbolic link, etc.). If given, `arcname'
           specifies an alternative name for the file in the archive.
           Directories are added recursively by default. This can be avoided by
           setting `recursive' to False. `exclude' is a function that should
           return True for each filename to be excluded. `filter' is a function
           that expects a TarInfo object argument and returns the changed
           TarInfo object, if it returns None the TarInfo object will be
           excluded from the archive.
        tawi����Nsuse the filter argument insteadistarfile: Excluded %rstarfile: Skipped %ristarfile: Unsupported type %rtrb(t_checkR;twarningstwarntDeprecationWarningt_dbgRGRCR(tabspatht
gettarinfotisregttarfilet	bltn_opentaddfileRUtlistdirtaddRD(	RRGtarcnamet	recursivetexcludetfilterR�ttarinfoR�((s//usr/lib/python2.7/site-packages/sos/archive.pyR�esB
		
*
*N(R	R3R;R�R�(((s//usr/lib/python2.7/site-packages/sos/archive.pyR�bstTarFileArchivecBseeZdZd	ZeZd�Zd	d�Zd�Z	d�Z
d�Zd�Zd�Z
d�ZRS(
s: archive class using python TarFile to create tar archivescCsPtt|�j||||||�d|_tjj||j��|_dS(Nttar(	tsuperR�RKt_suffixRCR(RDRGR�(RRGRHRIRJRARB((s//usr/lib/python2.7/site-packages/sos/archive.pyRK�s
	cCsn|j|_d|j|jd<d|j|jd<|rF||_n|j|_|j|_|j	|_
dS(Ns%.9ftatimetctime(tst_mtimetmtimetst_atimetpax_headerstst_ctimeR"RwR�tuidR�tgid(Rttar_infotfstatR"((s//usr/lib/python2.7/site-packages/sos/archive.pytset_tarinfo_from_stat�scCs�|jttjj|j�d�}|s8|j}nytj|�}Wntk
r_|SX|j	r�|j
|�}|r�||jd<q�n|j||�|S(Ni����sRHT.security.selinux(
RGtlenRCR(RVR8RERkR�t_with_selinux_contexttget_selinux_contextR�R�(RR�t	orig_pathR�tcontext((s//usr/lib/python2.7/site-packages/sos/archive.pytcopy_permissions_filter�s&
	cCs6ytj|�\}}|SWntk
r1dSXdS(N(tselinuxt
getfileconR�R;(RR(trctc((s//usr/lib/python2.7/site-packages/sos/archive.pyR��s

cCsd|j|jfS(Ns%s.%s(R8R�(R((s//usr/lib/python2.7/site-packages/sos/archive.pyRG�scCstt|�j�S(N(R�R�R-(R((s//usr/lib/python2.7/site-packages/sos/archive.pyR-�scCs�tjr8tjddkr8tj|jdd�}ntj|jdd�}|j|j	dt
jj|j
�dd|j�|j�dS(NiiR"R R�R�(tsixtPY3tsystversion_infoR�R�R�R�R�RERCR(RVR8R�R0(RR�((s//usr/lib/python2.7/site-packages/sos/archive.pyR��s(
c
Cseg}xDdddgD]3}t|�r8|j|�q|jd|�qW|j|krk|jg}nd}t|�}x�|D]�}d|jdd�}|jj||j�}y�d	||j	�f}t
|d
tdd�}|d
r!|j|d�td||d
f��n|j
|7_
|j	�SWq�tk
rV}	|	}q�Xq�W|�dS(Ntxztbzip2tgzips#"%s" compression method unavailablesNo compression utilities found.t.tipR=s%s %ststderrR�iR�toutputs%s exited with %s(RRWRR1R�R�R?tget_cmd_for_compress_methodR@RGRR�RR�(
RtmethodsR1R�t
last_errortcmdtsuffixtexec_cmdR�R�((s//usr/lib/python2.7/site-packages/sos/archive.pyR��s0

	N(R	R3R4R;R1R9R�RKR�R�R�RGR-R�R�(((s//usr/lib/python2.7/site-packages/sos/archive.pyR��s	
					(RCR�R�R6R�R�R�Rkt	threadingRt
subprocessRt
sos.utilitiesRRR�tImportErrorR�R�tinttlongRuRxRzRrtobjectRR<tTarFileR�R�(((s//usr/lib/python2.7/site-packages/sos/archive.pyt<module>s4
		[��B