�
��^c@s=dZddlZddlZddlZddlZddlZddlmZddlm Z m
Z
ddlmZddl
mZddlm Z mZmZmZmZmZmZmZmZdad �Zeed
��Zd�Zdefd
��YZd�Zde
fd��YZd�Z d�Z!dS(s\
This module provides classes and functions used to download and manage
debuginfos.
i����N(tPopen(t_tYumBase(tDownloadBaseCallback(tYumBaseError( Rtlog1tlog2t RETURN_OKtRETURN_FAILUREtRETURN_CANCEL_BY_USERtverboset
ask_yes_not error_msgtcsqddl}tj��tj��|jd���j�krU�j�krU�S����fd�}|S(s�
Ensures that the function is called using abrt's uid and gid
Returns:
Either an unchanged function object or a wrapper function object for
the function.
i����NtabrtcsMtj�j�tj�j��||�}tj��tj��|S(s�
Wrapper function around the called function.
Sets up uid and gid to match abrt's and after the function finishes
rolls its uid and gid back.
Returns:
Return value of the wrapped function.
(tostsetegidtpw_gidtseteuidtpw_uid(targstkwargstretval(Rtcurrent_gidtcurrent_uidtfn(s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytwrapped)s
(tpwdRtgetuidtgetgidtgetpwnamRR(RRR((RRRRs</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytensure_abrt_uids cCs%|d|}td||�td|�td�j|�GH|d}yt|d�}Wn+tk
r�} td�j|| �GHtSXtd|gd |d
d�}
|
j�}|dkr�td
�|std|�t j
|�qn"|j�td�j|�GHtS|j�t|d�}td�jd|�GHd}ddg}
|r�x |D]}|d|d7}qaWdd|j�g}
ntdd��=}t|
d|d
dd|d |d|�}|j�}WdQX|dkr td�t j
|�ntd�j|�GHtSdS( s�
Unpacks a single rpm located in tmp_dir into destdir.
Arguments:
package_file_name - name of 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
keeprpm - check if the user wants to delete rpms from the tmp directory
exact_files - extract only specified files
Returns:
RETURN_FAILURE in case of a serious problem
t/sExtracting %s to %ss%ssExtracting cpio from {0}s/unpacked.cpiotwbsCan't write to '{0}': {1}trpm2cpiotstdouttbufsizei����iscpio written OKskeeprpms = False, removing %ssCan't extract package '{0}'trbs$Caching files from {0} made from {1}s
unpacked.cpioR
tcpios-idut.t s /dev/nulltwtcwdtstdintstderrNsfiles extracted OKsCan't extract files from '{0}'(
RRRtformattopentIOErrorRRtwaitRtunlinktclosetstrip(tpackage_file_nametfilesttmp_dirtdestdirtkeeprpmtexact_filestpackage_full_pathtunpacked_cpio_patht
unpacked_cpiotexR"tretcodet
file_patternst cpio_argstfilenametnullR&((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyt
unpack_rpmCsN
cCsetraytjt�Wqatk
r]}|jtjkr^ttd�jt|��q^qaXndS(s*
Removes the temporary directory.
sCan't remove '{0}': {1}N( tTMPDIRtshutiltrmtreetOSErrorterrnotENOENTRRR-(R=((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytclean_up�stMyDownloadCallbackcBs eZdZd�Zd�ZRS(sR
This class serves as a download progress handler for yum's progress bar.
cCs5||_d|_d|_d|_tj|�dS(sx
Sets up instance variables
Arguments:
total_pkgs - number of packages to download
iN(t
total_pkgstdownloaded_pkgstlast_pctt last_timeRt__init__(tselfRL((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyRP�s
cCsYt|d�}||jkr-td�dS||_tjj�r�tjjd|jd|j||f�|dkrHt d�j
|jd|j||�GHqHn�tj�}|jdkr�||_n|dks�|j|ks�||jdkrHt d�j
|jd|j||�GH||_|dkrHd|_qHntjj
�dS( s
A method used to update the progress
Arguments:
name - filename
frac - progress fracment (0 -> 1)
fread - formated string containing BytesRead
ftime - formated string containing remaining or elapsed time
ids-percentage is the same, not updating progressNs&[sDownloading (%i of %i) %s: %3u%%[uis$Downloading ({0} of {1}) {2}: {3:3}%ii(tintRNRtsysR#tisattytwriteRMRLRR-ttimeROtflush(RQtnametfractfreadtftimetpcttt((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytupdateProgress�s*
!. (t__name__t
__module__t__doc__RPR^(((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyRK�s cCs(td�j|j|j�GHidd6S(s0
A callback function for mirror errors.
sOProblem '{0!s}' occured while downloading from mirror: '{1!s}'. Trying next oneitfail(RR-t exceptiontmirror(tcallBackObj((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytdownloadErrorCallback�stDebugInfoDownloadcBsMeZdZdeed�Zd�Zd�Zed��Z ed�Z
RS(s>
This class is used to manage download of debuginfos.
s*debug*cCs�d|_||_||_|a||_||_||_tj|�|j �t
d�GHy|j�Wn;tk
r�}|j
�t
d�j|�GHtd�nX|j
�dS(Ni����sInitializing yums7Error initializing yum (YumBase.doConfigSetup): '{0!s}'i(t
old_stdouttcachedirttmpdirRDtkeeprpmstnoninteractivetrepo_patternRRPtmute_stdoutRt
doConfigSetupRt
unmute_stdoutR-texit(RQtcachettmpRmt keep_rpmsRlR=((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyRP�s"
cCs1tdkr-tj|_tdd�t_ndS(sJ
Links sys.stdout with /dev/null and saves the old stdout
is /dev/nullR)N(R
RSR#RhR.(RQ((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyRnscCs6tdkr2|jdkr*|jt_q2dGHndS(s@
Replaces sys.stdout by stdout saved using mute
ii����s ERR: unmute called without mute?N(R
RhRSR#(RQ((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyRpscCs�tjj|j�sLytj|j�WqLtk
rH}d|GHtSXntjj|j�s�ytj|j�Wq�tk
r�}d|GHtSXntS(NsCan't create tmpdir: %ssCan't create cachedir: %s( RtpathtexistsRjtmakedirsRGRRiR(RQR=((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytsetup_tmp_dirss cCs�d}d}d}d}|s"tS|j�s=td�GHtSxn|jj�D]]}y!|j�|jj|j�WqMtk
r�}td�j |jt
|��GHqMXqMWtd�GHx�|jjd|j�D]�} y�|jj
| j�}
|jjdt
| j��td|
�t| dt�yt| d t�Wn)ttfk
rh}|GHtd
�GHnXWq�tk
r�}td�j | j|�GH|jj| j�q�Xq�Wtd�GHy|jjd
ddd�Wn'tk
r}td�j |�GHnXy|jjd
ddd�Wn'tk
rI}td�j |�GHnXg}i}x�|D]�}
td|
�|jj|
�}|r|d|j�kr�||dj|
�nI|
g||d<|t|dj�7}|t|dj�7}|d7}td|
|d�q]td|
�|j|
�q]Wt|�}|jj|�|jj t!�t"dks~t#|�dkr�td�j t#|��GHnt"dks�|dkr1td�j |�GHtd�j |d.|d/�}|j$tkrt%|�rtd�GHt&S|j'�}|t(kr.|St)j*|j+�}t|j,|j-�d0}|d1|kr�td�j |j+|�}|j$r�t%|�r�td�GHt&Snt)j*|j.�}t|j,|j-�d2}|d3|kr1td�j |j.|�}|j$r.t%|�r.td�GHt&Sq1nx�|j/�D]�\}}||_0d|_1|j2d�}t)j3j4|�}|j'�}|t(kr�|S|j2d�}d4}|j6d �r|d!}td"|�yt7j8||j+�WqTt9k
r}td#�j ||�GHq>qTXn6t)j3j:|j+|�}||_;|j<d$|g�}|j=d%|j>d%|j?d&|j@}|d'}|r�yt)jA|j+d(|�Wnt9k
r�nXtd)�j |�GHnItB|||j+|j.|jCd*|�}|tkrtd+�GHtD�tS|d7}q>W|jCr�t)j3jE|j+�r�td,�j |j+�GHyt)jF|j+�Wq�t9k
r�tGtd-�j |j+��q�Xnt(S(5s�
Downloads rpms into a temporary directory
Arguments:
package_files_dict - a dict containing {pkg: file list} entries
total_pkgs - total number of packages 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.
is#Error: can't make cachedir, exitings'Can't disable repository '{0!s}': {1!s}sSetting up yum repositoriestpatterntthisreposenabled repo %stskip_if_unavailablet_asyncsACan't disable async download, the output might contain artifacts!sCan't setup {0}: {1}, disablings+Looking for needed packages in repositoriestmdtypetmetadatat cacheonlyis"Error retrieving metadata: '{0!s}'t filelistss#Error retrieving filelists: '{0!s}'syum whatprovides %ssfound pkg for %s: %ssnot found pkg for %ss+Can't find packages for {0} debuginfo filessPackages to download: {0}s;Downloading {0:.2f}Mb, installed size: {1:.2f}Mb. Continue?isDownload cancelled by usersKWarning: Not enough free space in tmp dir '{0}' ({1:.2f}Mb left). Continue?sMWarning: Not enough free space in cache dir '{0}' ({1:.2f}Mb left). Continue?trelativepatht
remote_urlsfile:///iscopying from local repo: %ssCannot copy file '{0}': {1}tpkglistt-R's.rpmR sDownloading package {0} failedR9s&Unpacking failed, aborting download...sRemoving {0}s/Can't remove %s, probably contains an error logiiiiiiN(HRtsetCacheDirRtrepostlistEnabledR2tdisableRepotidRR-tstrt findReposRmt
enableRepotdoSetupRtsetattrtTruetFalset NameErrortAttributeErrortpopulateSackRtpkgSacktsearchFilestkeystappendtfloattsizet
installedsizeRKtsetProgressBartsetMirrorFailureCallbackRfR
tlenRlRR RxRRtstatvfsRjtf_bsizetf_bavailRit iteritemsRMRrtreturnSimpleRutbasenametNonet
startswithREtcopyRGtjoint localpathtdownloadPkgsRXtversiontreleasetarchR1RCRkRJRvtrmdirR(RQR5tdownload_exact_filestinstalled_sizeRLttodownload_sizeRMtrepoR=trtridt not_foundtpackage_files_dicttdebuginfo_pathtpkgtdnlcbtquestionRtrest tmp_spacetcache_spacetremotetlocaltremote_pathterrtpkg_pathtpkg_nvraR4t
unpack_result((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytdownload)s
(
*
#(R_R`RaR�R�RPRnRpRRxR�(((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyRg�s cCs,g|D]!}d||d |df^qS(s�
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"
s&%s/usr/lib/debug/.build-id/%s/%s.debugi((tpfxt build_idstb_id((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytbuild_ids_to_paths cCs.td|�}g}xZ|D]R}td|�tjj|�rTtd|�qntd|�|j|�qW|r�|}g}n|Sx�|D]�}td|�xd|D]\}||}td|�tjj|�r�td|�q�ntd|�|j|�q�W|r"|}g}q�|Sq�W|S(s�
Checks for installed debuginfos.
Arguments:
build_ids - string containing build ids
cache_dirs - list of cache directories
Returns:
List of missing debuginfo files.
R
slooking: %ss found: %ss
not found: %ss
looking in %s(R�RRRuRvR�(R�t
cache_dirsR5tmissingR�t cache_dirtcache_debuginfo_path((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pytfilter_installed_debuginfos
s8
("RaRSRRVRHREt
subprocessRtyumRRt
yum.callbacksRt
yum.ErrorsRtreportclientRRRRR R
RRRDRR�RCRJRKRfRgR�R�(((s</usr/lib64/python2.7/site-packages/reportclient/debuginfo.pyt<module>s*@ ,E B �
|