v_c@sdZddlZddlZddlZddlZddlmZddlTddlj Z ddl m Z ddl Z dej fdYZdS(s< A shell implementation for the yum command line interface. iN(tErrors(t*(tto_utf8tYumShellcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZRS(s.A class to implement an interactive yum shell.cCstjj|||_d|_d|_|jd7_t|_dg|_ t |j dkrw|j d|_ nddddd d d d g|_ |j |jjj|_tjd |_tjd|_g|_dS(Ns> it-s Leaving Shelltrepot repositorytexittquittrunttst transactiontconfigsyum.clisyum.verbose.cli(tcmdtCmdt__init__tbasetprompttresultt identcharstFalset from_filet resultmsgstlentextcmdstfiletshell_specific_commandstyum_cli_commandstkeyst commandlisttloggingt getLoggertloggertverbose_loggert_shell_history_cmds(tselfR((s/usr/share/yum-cli/shell.pyR#s      cCs'|jjjsdS|jj|dS(N(Rtconfthistory_recordR"tappend(R#tcmds((s/usr/share/yum-cli/shell.pyt_shell_history_add_cmds7scCsng}|dkr|Sytj|}Wn>tk ri}|jjd||jrjtjdqjnX|S(s@split the input using shlex rules, and error or exit accordinglysScript Error: %ssFatal error in script, exitingN( tNonetshlextsplitt ValueErrorR tcriticalRRt YumBaseError(R#t input_stringtinputste((s/usr/share/yum-cli/shell.pyt _shlex_split=s  csuttjjfd}|t_ytjj|||}Wnt_nXt_|S(s Sick hack for readline. cs(t_t|}t_|S(N(tsyststdoutR(Rtrret(t_ostdoutt oraw_inputtowriter(s/usr/share/yum-cli/shell.pyt_sick_hack_raw_inputTs  (t raw_inputR3R4tstreamt __builtin__R Rtcmdloop(R#targstkwargsR9tcret((R6R7R8s/usr/share/yum-cli/shell.pyR=Ms     cCsyt|jd}Wn%tk r=tjd|jnX|j}|jt|_x|D]}|j |qdW|j dtS(sExecute a script file in the yum shell. The location of the script file is supplied by the :class:`cli.YumBaseCli` object that is passed as a parameter to the :class:`YumShell` object when it is created. trs!Error: Cannot open %s for readingtEOF( topenRtIOErrorR3Rt readlinestclosetTrueRtonecmd(R#tfdtlinestline((s/usr/share/yum-cli/shell.pytscriptgs      cCsrd|_t|dkr4|jddkr4n:|j|\}}}||jkr|g}|jjjdd||d|kr|jdt Sn|dkrdS||j_ |jj j dd|j_ |j |jj |j_ |jjjdd|jj |j|jj y|jjWntjk rOnX|jj\}}||_dS(sHandle the next line of input if there is not a dedicated method of :class:`YumShell` to handle it. This method will handle yum commands that are not unique to the shell, such as install, erase, etc. :param line: the next line of input it#R>ttshellNs (RRtstript parselineRRtpluginsR tdo_helpRt cmdstringtreplaceR2R'R(t parseCommandsRR.t doCommands(R#RKR R>txargsRt_((s/usr/share/yum-cli/shell.pytdefaultys. (    cCsdS(s%Do nothing on an empty line of input.N((R#((s/usr/share/yum-cli/shell.pyt emptylinescCsdtjj|||||}x?|jjD]1}|j|r+|dkr+|j|q+q+W|S(sReturn a list of possible completions of a command. :param text: the command to be completed :return: a list of possible completions of the command RO(R Rt completenamesRRt startswithR&(R#ttextRKtbegidxtendidxtrettcommand((s/usr/share/yum-cli/shell.pyR\s cCs{d}|d krd|}n?|d kr8d|}n&|dkrQd |}n |jj|jj|d |_d S(sOutput help information. :param arg: the command to output help information about. If *arg* is an empty string, general help will be output. s Shell specific arguments: config - set config options repository (or repo) - enable/disable/list repositories transaction (or ts) - list, reset or run the transaction set run - run the transaction set exit or quit - exit the shell R R s %s arg list: lists the contents of the transaction reset: reset (zero-out) the transaction solve: run the dependency solver on the transaction run: run the transaction RRs %s arg [option] list: lists repositories and their status. option = [all] name/id glob enable: enable repositories. option = repository id disable: disable repositories. option = repository id R s %s arg [value] args: debuglevel, errorlevel, obsoletes, gpgcheck, assumeyes, exclude If no value is given it prints the current value. If value is given it sets that value. iN(s transactionsts(srepos repository(Rt shellUsageR!tinfoR(R#targtmsg((s/usr/share/yum-cli/shell.pyRSs        cCs|j|tS(sIExit the shell when EOF is reached. :param line: unused (tdo_exitRG(R#RK((s/usr/share/yum-cli/shell.pytdo_EOFs cCs|j|tS(s5Exit the shell. :param line: unused (RgRG(R#RK((s/usr/share/yum-cli/shell.pytdo_quits cCs@|jjjdks$|jdkr0d|_ndg|_tS(s5Exit the shell. :param line: unused t0iis Leaving Shell(RR$tshell_exit_statusRRRG(R#RK((s/usr/share/yum-cli/shell.pyRgs$  cCs|j|dS(sHandle the ts alias of the :func:`do_transaction` method. :param line: the remainder of the line, containing the name of a subcommand. If no subcommand is given, run the list subcommand. N(tdo_transaction(R#RK((s/usr/share/yum-cli/shell.pytdo_tsscCsEd|_|j|\}}}|d krO|jjtj|jjn|dkrk|jj n|dkry|jj \}}Wn3t j k r}|j jd|d|_tSX|dkrx!|D]}|j jd|qWd|_qA|jjtjdn&|d kr4|jd S|jd d S(sExecute the given transaction subcommand. The list subcommand outputs the contents of the transaction, the reset subcommand clears the transaction, the solve subcommand solves dependencies for the transaction, and the run subcommand executes the transaction. :param line: the remainder of the line, containing the name of a subcommand. If no subcommand is given, run the list subcommand. itlisttresettsolvesError building transaction: %sis Error: %ssSuccess resolving dependenciesR RNR N(slistN(RRQR)R!tlogt logginglevelstINFO_2RtlistTransactiont closeRpmDBtbuildTransactionRR.R R-Rtdo_runRS(R#RKR R>tcodetmsgsR1Rf((s/usr/share/yum-cli/shell.pyRls.           cCsd|_|j|\}}}|dkr|j|}|sp|jjtjd|t|jj |q|d}yt |}Wn1t k r|j j d||d|_dSXt|jj |||dkrtj|q|dkrtj|qn|dkr|j|}|s^|jjtjd|t|jj |q|d}|jtkr|j j d ||d|_tSt|j}t|jj |||d krd|j_qn|dkr|jdd}|j|}|sZd|}|djt|jj |}|jjtj|tSt|jj |||jjrd|j_nd|j_|jjn |jddS(sConfigure yum shell options. :param line: the remainder of the line, containing an option, and then optionally a value in the form [option] [value]. Valid options are one of the following: debuglevel, errorlevel, obsoletes, gpgcheck, assumeyes, exclude. If no value is given, print the current value. If a value is supplied, set the option to the given value. it debuglevelt errorlevels%s: %ss(Value %s for %s cannot be made to an intiNtgpgcheckt repo_gpgcheckt obsoletest assumeyess Value %s for %s is not a Booleantexcludet,t s%s: R (RzR{(R|R}R~R(R(RRQR2R!RqRrRstgetattrRR$tintR,R R-tsetattrt setDebugLevelt setErrorLeveltlowertBOOLEAN_STATESRR)tupRUtjointpkgSackRuRS(R#RKR R>toptstvaltvalueRf((s/usr/share/yum-cli/shell.pyt do_config&s^             "  cCs|j|dS(sHandle the repository alias of the :func:`do_repo` method. :param line: the remainder of the line, containing the name of a subcommand. N(tdo_repo(R#RK((s/usr/share/yum-cli/shell.pyt do_repositoryhscCsd|_|j|\}}}|d kr|j|}|sNdg}n|jdd||j_|j|jjy|jjWnt j k rqX|jj \}}||_n|dkr|j|}x|D]}y#|jj |jj j|} Wn]t jk rB} |jj| d|_qt jk rp} |jj| d|_qXxk| D]c}y|jjd|Wqxt jk r} |jjd|jj j|d|_tSXqxWd |j_qWn|d kr|j|}x|D]}y|jj j|} Wn]t jk rd} |jj| d|_qt jk r} |jj| d|_qXx+| D]#} |jj j | } | jqWqW|jj jn |jd d S( sExecute the given repo subcommand. The list subcommand lists repositories and their statuses, the enable subcommand enables the given repository, and the disable subcommand disables the given repository. :param line: the remainder of the line, containing the name of a subcommand and other parameters if required. If no subcommand is given, run the list subcommand. iRntenabledtrepolisttenableitthisreposDisabling RepositorytdisableRN(slistN(RRQR)R2tinsertRR'R(RVRR.RWRtrepost enableRepot ConfigErrorR R-t RepoErrort doRepoSetupt disableRepoRRRFt buildIndexesRS(R#RKR R>R'RRYRRtchangedR1toffrepostrepoidR((s/usr/share/yum-cli/shell.pyRpsh                  cCs4|j|\}}}|GH|GH|GHd|_dS(Ni(RQR(R#RKR R>((s/usr/share/yum-cli/shell.pytdo_tests cCsd|_t|jjdkrye|jj\}}|dkrvx!|D]}|jjd|qLWd|_tS|jj}Wnt j k r}|jjd|d|_qt k r}|jjdd|_qt k r"}|j dkr|jjdnd|_qX|d krK|jjdd|_nf|dkrs|jjd d|_n(|dkr|jjd d|_n|jjtjd |jjnd S(s:Run the transaction. :param line: unused iis Error: %ss Exiting on user canceli s Exiting on Broken Pipeis(Transaction encountered a serious error.s.There were non-fatal errors in the transactionsTransaction didn't startsFinished TransactionN(iii(RRRttsInfoRvR R-Rt doTransactionRR.tKeyboardInterruptRDterrnoR!RdRqRrRsRu(R#RKRxRyRft returnvalR1((s/usr/share/yum-cli/shell.pyRws@             (t__name__t __module__t__doc__RR(R2R=RLRZR[R\RSRhRiRgRmRlRRRRRw(((s/usr/share/yum-cli/shell.pyR s(      $  -    ) B  Q (RR3R R*RtyumRt yum.constantstyum.logginglevelsRrtyum.i18nRR<RR(((s/usr/share/yum-cli/shell.pyts