v_c@ssdZddlZddlZddlZddlZddlZddlTddlmZddlmZddl m Z m Z ddlm Z ddl mZddljZdd lmZyejejd ZWneefk rd ZnXd Zd ZdZdZdZdZdZdefdYZ dZ!e"dkroe!ndS(s/Various utility functions, and a utility class.iN(t*(tErrors(t_(t utf8_widtht exception2msg(t logginglevels(t OptionGroup(t format_numbert SC_CLK_TCKidcs%tjfd}|t_dS(sChange 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(sConvert 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|d kred|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:%02diiQiiQiii((tseconds((s/usr/share/yum-cli/utils.pytseconds_to_ui_time?s       cCs5|s dSyt|}Wntk r0}dSXi}xtd|D]}|ddkrdqHn|d jdd}t|dkrqHn|djdr|dd |dN( R,tIOErrortcriticalRR#RRRRttimetctime(R&tloggerR(R'tnmsgtago((s/usr/share/yum-cli/utils.pytshow_lock_owners&   !t YumUtilBasecBseZdZdZdZdZdZdZdZdZ dZ d Z e j d ejfd Zd Zed ZdZRS(s,A class to extend the yum cli for utilities.cCstj|td|dtd||_||_||_||_t|jd|jd|_ |jj |j t t j d}t j d}t|dr|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.pyRSs    cCs*|jjtd|jr&dSdS(swOutput a message stating that the operation was cancelled by the user. :return: the exit code s Exiting on user cancelii(RHRERtunlock(R`((s/usr/share/yum-cli/utils.pyt exUserCancels cCs\|jdkr(|jjtdn |jjtdt||jrXdSdS(sOutput 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 %sii(terrnoRHRERRRc(R`R'((s/usr/share/yum-cli/utils.pyt exIOErrors   cCs<t|}|r(|jjd|n|jr8dSdS(sCalled 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 %sii(RRHtwarnRc(R`R'texitmsg((s/usr/share/yum-cli/utils.pyt exPluginExits   cCs-|jjdt||jr)dSdS(sOutput a message stating that a fatal error has occurred. :param e: the exception :return: the exit code s %sii(RHRERRc(R`R'((s/usr/share/yum-cli/utils.pytexFatals cCs6y|j|jWntjk r1}dSXdS(s>Release the yum lock. :return: the exit code ii(t closeRpmDBtdoUnlockRt LockError(R`R'((s/usr/share/yum-cli/utils.pyRcs  cCs|jS(sReturn 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(sReturn 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 j dn|jj |}|j rd|_n|jrd|_|_ny|j}|j|_||_|j |_||_|j|_|j|_|j|_t|drL|jj|j|_nt|drv|jj|j|_nt|dr|j|_n|j |jrx6|jjD]%}t|j |t|j|qWnWnt!j"k r"}|j#j$t%dt&|t j dnt'k r`}|j#j$t%dt&|t j dnt(j)k r}|j#j$t%d t&|t j dnBt!j*k r}|j#j$t%d t&|t j dnX|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 _parseSetOptstsetoptst main_setoptstitemstsetattrtgetattrtversionRrRtexittgetRoottquiett debugleveltverboset errorleveltpreconftconffiletfntroott nopluginst init_pluginst plugin_typest optparserR^t _splitArgRstdisabled_pluginsRttenabled_pluginsRutconfRt ConfigErrorRHRERRRtpluginst PluginYumExitt YumBaseErrort set_usageRWtsetupYumConfigtcmdstbasecmdR#textcmds(R`targst pluginsTypestoptstoptRtpcR'((s/usr/share/yum-cli/utils.pytdoUtilConfigSetupsf  #              *  cCs|y<|j|j|j|jdt|jWn9tjk rw}|jj t |t j dnXdS(sDo a default setup for all the normal or necessary yum components; this method is mostly just a used for testing. tdoSetupiN( t waitForLockt_getTst _getRpmDBt _getReposRUt _getSacksRRRHRERRR~(R`tmsg((s/usr/share/yum-cli/utils.pytdoUtilYumSetupds   cCsy|jd|\}}Wn}tjk r>}|j|Stjk rh}d}t|g}n4tk r|jSt k r}|j |SX|dkr|j rdSdS|dkrkx0|j |D]\}}|j j||qW|jjs |jjtdn|jd|jjdtsW|jjtdn|j rgdSdS|d krznN|j jtd |x|D]}|j j|qW|j rdSd S|jjtjtd d S(sBuild the transaction. :param unfinished_transactions_check: whether to check if an unfinished transaction has been saved tunfinished_transactions_checkiiis= 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(tbuildTransactionRRRiRRRR RdRDRfRctpretty_output_restringRHRERt skip_brokenRbtinfoRt_rpmdb_warn_checkstFalsetlogRtINFO_2(R`Rtresultt resultmsgsR'tprefixR((s/usr/share/yum-cli/utils.pytdoUtilBuildTransactionssD           cCsy|j}Wnrtjk r2}|j|Stjk rQ}|j|Stk rh|jSt k r}|j |SX|j j t jtd|jrdS|S(sPerform the transaction.s Complete!i(t doTransactionRRRiRRRjR RdRDRfRbRRRRRc(R`t return_codeR'((s/usr/share/yum-cli/utils.pytdoUtilTransactions     (t__name__t __module__t__doc__RSRdRfRiRjRcRnRoRrRtargvRt TYPE_CORERRRURR(((s/usr/share/yum-cli/utils.pyRLs      O  -c Csd}d}d}t|||}|j}|jdddddd d td d |jjd |j}|jjd|jddj|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_optionRRHRRRtjoinR(RCRaROtutiltparserR((s/usr/share/yum-cli/utils.pytmains     t__main__(#RtosRRFR RptcliRRtyum.i18nRRRtoptparseRt yum.pluginsRturlgrabber.progressRtsysconft sysconf_namesRtAttributeErrortKeyErrorRRRR,R"R%RKRRRLRR(((s/usr/share/yum-cli/utils.pyts8          $   &