�
�v_c@ssdZddlZddlZddlZddlZddlZddlTddlmZddlmZddl m
Z
mZddlmZddl
mZddljZdd lmZyejejd
�ZWneefk
r�dZnXd�Zd
�Zd�Zd�Zd�Zd�Zd�Zdefd��YZ d�Z!e"dkroe!�ndS(s/Various utility functions, and a utility class.i����N(t*(tErrors(t_(t
utf8_widtht
exception2msg(t
logginglevels(tOptionGroup(t
format_numbert
SC_CLK_TCKidcs%tj��fd�}|t_dS(s�Change settings so that nothing will be printed to the
terminal after an uncaught :class:`exceptions.KeyboardInterrupt`.
cs&|tjkr"�|||�ndS(N(t
exceptionstKeyboardInterrupt(ttypetvaluet traceback(told_excepthook(s/usr/share/yum-cli/utils.pytnew_hook.sN(tsyst
excepthook(R((Rs/usr/share/yum-cli/utils.pyt#suppress_keyboard_interrupt_message(s cCst|�tS(s�Convert a number of jiffies to seconds. How many jiffies are in a second
is system-dependent, e.g. 100 jiffies = 1 second is common.
:param jiffies: a number of jiffies
:return: the equivalent number of seconds
(tintt_USER_HZ(tjiffies((s/usr/share/yum-cli/utils.pytjiffies_to_seconds6scCs{|dkr8d|d |d
d|dd|dfS|dkred|d|dd|dfSd|d|dfS(
sReturn a human-readable string representation of the length of
a time interval given in seconds.
:param seconds: the length of the time interval in seconds
:return: a human-readable string representation of the length of
the time interval
i<is%d day(s) %d:%02d:%02ds%d:%02d:%02ds %02d:%02dii�Qii�Qiii((tseconds((s/usr/share/yum-cli/utils.pytseconds_to_ui_time?s
cCs5|s
dSyt|�}Wntk
r0}dSXi}x�td|�D]�}|ddkrdqHn|d jdd�}t|�dkr�qHn|djd�r�|dd |d<n|dj�||d
j�j�<qHWd|kr�dSd|krdSt�}|dkrdS|j
t||��|S(
s�Return information about a process taken from
/proc/*pid*/status, /proc/stat/, and /proc/*pid*/stat.
:param pid: the process id number
:return: a dictionary containing information about the process
Ns/proc/%d/statusi����s
s: iis kBi����itvmrsstvmsize(Rt
ValueErrortopentsplittlentendswithtstriptlowert
get_boot_timetNonetupdatetget_process_time(tpidtetpstlinetdatat boot_time((s/usr/share/yum-cli/utils.pytget_process_infoQs2( cCsAx:td�D],}|jd�r
t|td�d!�Sq
WdS(Ns
/proc/statsbtime i����(Rt
startswithRR(R)((s/usr/share/yum-cli/utils.pyR"uscCsi}td|�j�j�}||jd�dj�}t|d�|d<t|d�|d<t|d�|d <t|d
�|d<|t|d�|d
<itd�d6td�d6td�d6td�d6td�d6j|dtd��|d<|S(Ns
/proc/%d/statt)iitutimeitstimei
tcutimeitcstimeit
start_timetRunningtRtSleepingtStUninterruptibletDtZombietZsTraced/StoppedtTitUnknowntstate(RtreadR trfindRRRtget(R&R+R(tps_stat((s/usr/share/yum-cli/utils.pyR%{s
cCsCyt|�}Wn/tk
rA}|jdt|��d}nX|sLdS|ddkrktd�}ntd�|d}|jd|�|jtd�tt|d�d�tt|d �d�f�ttt j ��|d
�}|jtd�t j
|d
�|f�|jtd�|d
|f�|S(swOutput information about another process that is holding the
yum lock.
:param pid: the process id number of the process holding the yum
lock
:param logger: the logger to output the information to
:return: a dictionary containing information about the process.
This is the same as the dictionary returned by
:func:`get_process_info`.
s%stnames
yumBackend.pys& The other application is: PackageKits The other application is: %ss Memory : %5s RSS (%5sB VSZ)RiRR3s Started: %s - %s agos State : %s, pid: %dR>N(R,tIOErrortcriticalRR#RRRRttimetctime(R&tloggerR(R'tnmsgtago((s/usr/share/yum-cli/utils.pytshow_lock_owner�s&
!tYumUtilBasecBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zej
d
ejfd�Zd�Zed
�Zd�ZRS(s,A class to extend the yum cli for utilities.cCs�tj|�td|dtd|�|_||_||_||_t|jd|jd�|_ |jj
|j �t�tj
d�}tj
d�}t|d�r�|jjd �ndS(
Ntbasetutilstusages
%s optionstsyum.utilsyum.verbose.utiltrun_with_package_namess yum-utils(t
YumBaseClit__init__tYumOptionParsertTruet_parsert_usaget _utilNamet_utilVerRt
_option_grouptadd_option_groupRtloggingt getLoggerthasattrRQtadd(tselfRCtverRORHtverbose_logger((s/usr/share/yum-cli/utils.pyRS�s
cCs*|jjtd��|j�r&dSdS(swOutput a message stating that the operation was cancelled
by the user.
:return: the exit code
s
Exiting on user canceli�i(RHRERtunlock(R`((s/usr/share/yum-cli/utils.pytexUserCancel�scCs\|jdkr(|jjtd��n |jjtd�t|��|j�rXdSdS(s�Output a message stating that the program is exiting due to
an IO exception.
:param e: the IO exception
:return: the exit code
i s
Exiting on Broken Pipes
%si�i(terrnoRHRERRRc(R`R'((s/usr/share/yum-cli/utils.pyt exIOError�s cCs<t|�}|r(|jjd|�n|j�r8dSdS(s�Called when a plugin raises
:class:`yum.plugins.PluginYumExit`. Log the plugin's exit
message if one was supplied.
:param e: the exception
:return: the exit code
s
%si�i(RRHtwarnRc(R`R'texitmsg((s/usr/share/yum-cli/utils.pytexPluginExit�scCs-|jjdt|��|j�r)dSdS(s�Output a message stating that a fatal error has occurred.
:param e: the exception
:return: the exit code
s
%si�i(RHRERRc(R`R'((s/usr/share/yum-cli/utils.pytexFatal�scCs6y|j�|j�Wntjk
r1}dSXdS(s>Release the yum lock.
:return: the exit code
i�i(t
closeRpmDBtdoUnlockRt LockError(R`R'((s/usr/share/yum-cli/utils.pyRc�s
cCs|jS(s�Return the :class:`cli.YumOptionParser` for this object.
:return: the :class:`cli.YumOptionParser` for this object
(RV(R`((s/usr/share/yum-cli/utils.pytgetOptionParserscCs|jS(s�Return an option group to add non inherited options.
:return: a :class:`optparse.OptionGroup` for adding options
that are not inherited from :class:`YumBaseCli`.
(RZ(R`((s/usr/share/yum-cli/utils.pytgetOptionGroup
scCsd|j|jtjfGHdS(Ns%s - %s (yum - %s)(RXRYtyumt__version__(R`((s/usr/share/yum-cli/utils.pyt_printUtilVersionsicCsG|jj|�}|j|j�|jrax3|jjD]"}t||t|j|��q8Wn|jr�|j �t
jd�n|jj|�}|j
r�d|_n|jr�d|_|_ny|j}|j|_||_|j|_||_|j|_|j|_|j|_t|d�rL|jj|j�|_nt|d�rv|jj|j�|_nt|d�r�|j|_n|j |jr�x6|jjD]%}t|j |t|j|��q�WnWnt!j"k
r"}|j#j$t%d�t&|��t
jd�n�t'k
r`}|j#j$t%d�t&|��t
jd�n�t(j)k
r�}|j#j$t%d �t&|��t
jd�nBt!j*k
r�}|j#j$t%d
�t&|��t
jd�nX|jj+|j,�|jj-�\}|_.|j.r*|j.d|_/n d|_/|j.d|_1|S(s'Parse command line options, and perform configuration.
:param args: list of arguments to use for configuration
:param pluginsTypes: a sequence specifying the types of
plugins to load
:return: a dictionary containing the values of command line options
iitdisablepluginst
enablepluginst
releaseversConfig Error: %sisOptions Error: %ssPluginExit Error: %ss
Yum Error: %sN(2RVt
firstParset
_parseSetOptstsetoptstmain_setoptstitemstsetattrtgetattrtversionRrRtexittgetRoottquiett
debugleveltverboset
errorleveltpreconftconffiletfntroott nopluginstinit_pluginstplugin_typest optparserR^t _splitArgRstdisabled_pluginsRttenabled_pluginsRutconfRtConfigErrorRHRERRRtpluginst
PluginYumExittYumBaseErrort set_usageRWtsetupYumConfigtcmdstbasecmdR#textcmds(R`targstpluginsTypestoptstoptR�tpcR'((s/usr/share/yum-cli/utils.pytdoUtilConfigSetupsf #
* cCs|y<|j�|j�|j�|jdt�|j�Wn9tjk
rw}|jj t
|��tjd�nXdS(s�Do a default setup for all the normal or necessary yum components;
this method is mostly just a used for testing.
tdoSetupiN(
twaitForLockt_getTst _getRpmDBt _getReposRUt _getSacksRR�RHRERRR~(R`tmsg((s/usr/share/yum-cli/utils.pytdoUtilYumSetupds
cCs�y|jd|�\}}Wn}tjk
r>}|j|�Stjk
rh}d}t|�g}n4tk
r|j�St k
r�}|j
|�SX|dkr�|j�r�dSdS|dkrkx0|j|�D]\}}|j
j||�q�W|jjs |jjtd��n|jd|jjdt�sW|jjtd��n|j�rgdSdS|d krznN|j
jtd
�|�x|D]}|j
j|�q�W|j�r�dSdS|jjtjtd��d
S(s�Build the transaction.
:param unfinished_transactions_check: whether to check if an
unfinished transaction has been saved
tunfinished_transactions_checkiii�s= You could try using --skip-broken to work around the problemtoutRgs4 You could try running: rpm -Va --nofiles --nodigestis Unknown Error(s): Exit Code: %d:is
Dependencies ResolvedN(tbuildTransactionR�R�RiRR�RR
RdRDRfRctpretty_output_restringRHRER�tskip_brokenRbtinfoRt_rpmdb_warn_checkstFalsetlogRtINFO_2(R`R�tresultt
resultmsgsR'tprefixR�((s/usr/share/yum-cli/utils.pytdoUtilBuildTransactionssD
cCs�y|j�}Wnrtjk
r2}|j|�Stjk
rQ}|j|�Stk
rh|j�St k
r�}|j
|�SX|jjt
jtd��|j�r�dS|S(sPerform the transaction.s Complete!i�(t
doTransactionR�R�RiRR�RjR
RdRDRfRbR�RR�RRc(R`treturn_codeR'((s/usr/share/yum-cli/utils.pytdoUtilTransaction�s
(t__name__t
__module__t__doc__RSRdRfRiRjRcRnRoRrRtargvR�t TYPE_CORER�R�RUR�R�(((s/usr/share/yum-cli/utils.pyRL�s
O -cCs�d}d}d}t|||�}|j�}|jdddddd d
tdd�|jjd
�|j�}|jjd�|j�ddj|j �GHdGH|GH|jjd|�dS(Nttestutils0.1stestutil [options] [args]RPs
--myoptiontdesttmyoptiontactiont
store_truetdefaultthelpsThis is an util optionsSetup Yum Configs Setup YumsCommand line args: %st sCommand line options :s%s Completed(
RLRnt
add_optionR�RHR�R�R�tjoinR�(RCRaROtutiltparserR�((s/usr/share/yum-cli/utils.pytmain�s
t__main__(#R�tosRRFR RptcliRRtyum.i18nRRRtoptparseRtyum.pluginsR�turlgrabber.progressRtsysconft
sysconf_namesRtAttributeErrortKeyErrorRRRR,R"R%RKRRRLR�R�(((s/usr/share/yum-cli/utils.pyt<module>s8
$ &� |