Mini Shell

Direktori : /lib64/python3.6/site-packages/reportclient/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/reportclient/__pycache__/debuginfo.cpython-36.opt-1.pyc

3


�$`;@�@s�dZddlZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
mZmZm
Z
mZmZmZmZmZmZdd�Zeddd	��Zdd
d�ZGdd
�d
e�ZGdd�de�Zdd�Zdd�ZdS)z\
    This module provides classes and functions used to download and manage
    debuginfos.
�N)�Popen)	�_�log1�log2�	RETURN_OK�RETURN_FAILURE�RETURN_CANCEL_BY_USER�verbose�
ask_yes_no�	error_msgcs4tj��tjd���j�kr �S���fdd�}|S)z�
    Ensures that the function is called using abrt's gid

    Returns:
        Either an unchanged function object or a wrapper function object for
        the function.
    �abrtcs$tj�j��||�}tj��|S)z�
        Wrapper function around the called function.

        Sets up gid to match abrt's and after the function finishes
        rolls its gid back.

        Returns:
            Return value of the wrapped function.
        )�os�setegid�pw_gid)�args�kwargs�retval)r�current_gid�fn��!/usr/lib64/python3.6/debuginfo.py�wrapped6s

z ensure_abrt_gid.<locals>.wrapped)r
�getgid�pwd�getpwnamr)rrr)rrrr�ensure_abrt_gid&s	

rFcCs�td||�td|�ttd�j|��|d}yt|d�}Wn4tk
rr}zttd�j||��tSd}~XnXtd|g|dd
�}|j	�}	|	dkr�td�n|j
�ttd
�j|��tS|j
�t|d�}ttd�jdtjj
|���d}
ddg}|�r,x|D]}|
d|d7}
�qWdd|
j�g}tjdddd��(}
|
j}t||d||
|
d�}|j	�}	WdQRX|j
�|	dk�r�td�tj|�tj|�nttd�j||��tSdS)a�
    Unpacks a single rpm located in tmp_dir into destdir.

    Arguments:
        package_full_path - full file system path to the rpm file
        files - files to extract from the rpm
        tmp_dir - temporary directory where the rpm file is located
        destdir - destination directory for the rpm package extraction
        exact_files - extract only specified files

    Returns:
        RETURN_FAILURE in case of a serious problem
    zExtracting %s to %sz%szExtracting cpio from {0}z/unpacked.cpio�wbzCan't write to '{0}': {1}N�rpm2cpio�)�stdout�bufsizerzcpio written OKzCan't extract package '{0}'�rbz$Caching files from {0} made from {1}z
unpacked.cpio��cpioz-idu�.� zabrt-unpacking-z/tmpF)�prefix�dir�delete)�cwdr �stdinr�stderrzfiles extracted OKz>Can't extract files from '{0}'. For more information see '{1}'���r,)rr�printr�format�open�IOErrorrr�wait�closer
�path�basename�strip�tempfileZNamedTemporaryFile�name�unlink)�package_full_path�files�tmp_dirZdestdir�exact_filesZunpacked_cpio_pathZ
unpacked_cpio�exrZretcodeZ
file_patternsZ	cpio_args�filenameZlog_fileZ
log_file_namer#rrr�
unpack_rpmOsP









r?cCsf|rbytj|�WnNtk
r`}z2|jtjkrP|dkrPttd�j|t|���WYdd}~XnXdS)z*
    Removes the temporary directory.
    FzCan't remove '{0}': {1}N)	�shutilZrmtree�OSError�errno�ENOENTrrr.�str)r;Zsilentr=rrr�clean_up�srEc@s eZdZdZdd�Zdd�ZdS)�DownloadProgressz;
    This class serves as a download progress handler.
    cCs||_d|_d|_d|_dS)zx
        Sets up instance variables

        Arguments:
            total_pkgs - number of packages to download
        rN)�
total_pkgs�downloaded_pkgs�last_pct�	last_time)�selfrGrrr�__init__�szDownloadProgress.__init__cCs�||jkrtd�dS||_tjj�rptjjdj|jd|j||��|dkr�t	t
d�j|jd|j||��nltj�}|jdkr�||_|dks�|j|ks�||jdkr�t	t
d�j|jd|j||��||_|dkr�d|_tjj
�dS)	z�
        A method used to update the progress

        Arguments:
            name - filename
            pct  - percent downloaded
        z-percentage is the same, not updating progressNz*Downloading ({0} of {1}) {2}: {3:3}%r�dz$Downloading ({0} of {1}) {2}: {3:3}%r�)rIr�sysr�isatty�writer.rHrGr-r�timerJ�flush)rKr7Zpct�trrr�update�s*	



 
zDownloadProgress.updateN)�__name__�
__module__�__qualname__�__doc__rLrUrrrrrF�s
rFc@s�eZdZdZd dd�Zdd�Zd	d
�Zdd�Zd
d�Ze	dd��Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd!dd�ZdS)"�DebugInfoDownloadz>
    This class is used to manage download of debuginfos.
    �*debug*FTcCsFd|_||_||_||_||_||_i|_g|_d|_d|_	d|_
dS)NrrFr,)�
old_stdout�cachedir�tmpdir�keeprpms�noninteractive�repo_pattern�package_files_dict�	not_found�todownload_size�installed_size�find_packages_run)rK�cacheZtmpraZ	keep_rpmsr`rrrrL�szDebugInfoDownload.__init__cCs|jS)N)rd)rKrrr�get_download_size�sz#DebugInfoDownload.get_download_sizecCs|jS)N)re)rKrrr�get_install_size�sz"DebugInfoDownload.get_install_sizecCs tdkrtj|_tdd�t_dS)zJ
        Links sys.stdout with /dev/null and saves the old stdout
        �z	/dev/null�wN)r	rOrr\r/)rKrrr�mute_stdout�szDebugInfoDownload.mute_stdoutcCs(tdkr$|jdkr|jt_ntd�dS)z@
        Replaces sys.stdout by stdout saved using mute
        rjrz ERR: unmute called without mute?Nr,)r	r\rOrr-)rKrrr�
unmute_stdout�s

zDebugInfoDownload.unmute_stdoutcCs�tjj|j�sLytj|j�Wn,tk
rJ}ztd|�tSd}~XnXtjj|j�s�ytj|j�Wn,tk
r�}ztd|�tSd}~XnXt	S)NzCan't create tmpdir: %szCan't create cachedir: %s)
r
r3�existsr^�makedirsrAr-rr]r)rKr=rrr�setup_tmp_dirs	sz DebugInfoDownload.setup_tmp_dirscCsdS)Nr)rKrrr�prepareszDebugInfoDownload.preparecCsdS)Nr)rKZupdaterrrr�initialize_progresssz%DebugInfoDownload.initialize_progresscCsdS)Nr)rKrrr�initialize_repositories sz)DebugInfoDownload.initialize_repositoriescCsdS)Nr)rKr:rrr�triage#szDebugInfoDownload.triagecCsdS)Nr)rK�pkgrrr�download_package&sz"DebugInfoDownload.download_packagecCs`d|_|stSttd��|j�ttd��|j�ttd��|j|�\|_|_|_	|_
dS)NTzInitializing package managerzSetting up repositoriesz+Looking for needed packages in repositories)rfrr-rrqrsrtrbrcrdre)rKr:rrr�
find_packages)szDebugInfoDownload.find_packagescCs0|stS|j�}|tkr|S|js,|j|�tdksBt|j�dkrZtt	d�j
t|j���tdksrt|j�dk�r�tt	d�j
t|j���t	d�j
|jd|j
d�}|jr�t|�r�tt	d��tStj|j�}t|j|j�d}|jd|k�r0t	d�j
|j|�}|j�r0t|��r0tt	d��tStj|j�}t|j|j�d}|j
d|k�r�t	d�j
|j|�}|j�r�t|��r�tt	d��tStt|j��}|j|��x|jj�D�]�\}	}|j|	�\}
}|�r y|
d	k	�r�tj|
�Wntk
�r
YnXtt	d
�j
|	��n�t|
||j|j|d�}|tk�r�tt	d��tj|j�}
t j!d
�}|
j"|j#k�r�tt	d�j
|j��t$|j�tS|j%�s�t&d|
�tj|
�|j'd7_'�q�W|j%�r,tj(j)|j��r,tt	d�j
|j��ytj*|j�Wn*tk
�r*t+t	d�j
|j��YnXtS)a\
        Downloads rpms shipping given files into a temporary directory

        Arguments:
            file - a list of files to download
            download_exact_files - extract only specified files

        Returns:
            RETURN_OK if all goes well.
            RETURN_FAILURE in case it cannot set up either of the directories.
        rz+Can't find packages for {0} debuginfo fileszPackages to download: {0}z;Downloading {0:.2f}Mb, installed size: {1:.2f}Mb. Continue?izDownload cancelled by userzKWarning: Not enough free space in tmp dir '{0}' ({1:.2f}Mb left). Continue?zMWarning: Not enough free space in cache dir '{0}' ({1:.2f}Mb left). Continue?NzDownloading package {0} failed)r<z&Unpacking failed, aborting download...rzV'{0}' must be owned by group abrt. Please run '# chown -R :abrt {0}' to fix the issue.zkeeprpms = False, removing %srzRemoving {0}z0Can't remove {0}, probably contains an error logiiiiii),rrprrfrwr	�lenrcr-rr.rbrdrer`r
rr
�statvfsr^�float�f_bsize�f_bavailr]rFrr�itemsrvr8rAr?�statrr�st_gidrrEr_rrHr3rn�rmdirr)rKr:Zdownload_exact_filesrZquestion�resZ	tmp_spaceZcache_spaceZprogress_observerrur9�errZ
unpack_result�srrrr�download>s�












zDebugInfoDownload.downloadN)r[FT)F)rVrWrXrYrLrhrirlrmrrprqrrrsrtrvrwr�rrrrrZ�s

	rZcs�fdd�|D�S)z�
    Transforms build ids into a path.

    build_id1=${build_id:0:2}
    build_id2=${build_id:2}
    file="usr/lib/debug/.build-id/$build_id1/$build_id2.debug"
    cs*g|]"}d�|dd�|dd�f�qS)z&%s/usr/lib/debug/.build-id/%s/%s.debugNrjr)�.0Zb_id)�pfxrr�
<listcomp>�sz%build_ids_to_path.<locals>.<listcomp>r)r��	build_idsr)r�r�build_ids_to_path�s	r�cCs�td|�}g}xB|D]:}td|�tjj|�r:td|�qtd|�|j|�qW|r`|}g}n|Sxv|D]n}td|�xJ|D]B}||}td|�tjj|�r�td|�q�td|�|j|�q�W|r�|}g}qj|SqjW|S)z�
    Checks for installed debuginfos.

    Arguments:
        build_ids - string containing build ids
        cache_dirs - list of cache directories

    Returns:
        List of missing debuginfo files.
    r"zlooking: %sz	found: %sz
not found: %sz
looking in %s)r�rr
r3rn�append)r�Z
cache_dirsr:ZmissingZdebuginfo_path�	cache_dirZcache_debuginfo_pathrrr�filter_installed_debuginfos�s8









r�)F)F)rYrOr
rrRrBr@�
subprocessrr6Zreportclientrrrrrrr	r
rrr?rE�objectrFrZr�r�rrrr�<module>s$,)F

9V