�
�v_c@s�dZddlZddlZddlZddlZddlmZddlTddlj Z ddl
mZddlZdej
fd��YZdS(s<
A shell implementation for the yum command line interface.
i����N(tErrors(t*(tto_utf8tYumShellcBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(s.A class to implement an interactive yum shell.cCs�tjj|�||_d|_d|_|jd7_t|_dg|_ t
|j�dkrw|jd|_nddddd d
ddg|_
|j
|jjj�|_tjd
�|_tjd�|_g|_dS(Ns> it-s
Leaving Shelltrepot
repositorytexittquittrunttsttransactiontconfigsyum.clisyum.verbose.cli(tcmdtCmdt__init__tbasetprompttresultt
identcharstFalset from_filet
resultmsgstlentextcmdstfiletshell_specific_commandstyum_cli_commandstkeystcommandlisttloggingt 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|�|jrjtjd�qjnX|S(s@split the input using shlex rules, and error or exit accordinglysScript Error: %ssFatal error in script, exitingN( tNonetshlextsplitt
ValueErrorR tcriticalRRtYumBaseError(R#tinput_stringtinputste((s/usr/share/yum-cli/shell.pyt_shlex_split=s csut�tj��j����fd�}|t_ytjj|||�}Wn�t_�nX�t_|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 cCs�yt|jd�}Wn%tk
r=tjd|j�nX|j�}|j�t|_x|D]}|j |�qdW|j d�tS(s�Execute 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|j�ddkr4n:|j|�\}}}||jkr�|g}|jjjdd|�|d|kr�|jd�t Sn|dkr�dS||j_
|jj
jdd�|j_
|j|jj
�|j_
|jjjdd|jj
�|j|jj
�y|jj�Wntjk
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 emptyline�scCsdtjj|||||�}x?|jjD]1}|j|�r+|dkr+|j|�q+q+W|S(s�Return 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}|dkrd|}n?|d
kr8d|}n&|dkrQd |}n
|jj�|jj|�d
|_dS(s�Output 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
RR
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
Rs�
%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(stransactionsts(srepos
repository(Rt
shellUsageR!tinfoR(R#targtmsg((s/usr/share/yum-cli/shell.pyRS�s
cCs|j|�tS(sIExit the shell when EOF is reached.
:param line: unused
(tdo_exitRG(R#RK((s/usr/share/yum-cli/shell.pytdo_EOF�s
cCs|j|�tS(s5Exit the shell.
:param line: unused
(RgRG(R#RK((s/usr/share/yum-cli/shell.pytdo_quit�s
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.pyRg�s$cCs|j|�dS(s�Handle 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_ts�scCsEd|_|j|�\}}}|d
krO|jjtj|jj��n�|dkrk|jj �n�|dkry|jj
�\}}Wn3tjk
r�}|j
jd|�d|_tSX|dkrx!|D]}|j
jd|�q�Wd|_qA|jjtjd�n&|d kr4|jd
�S|jd�dS(s�Execute 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 RNRN(slistN(RRQR)R!tlogt
logginglevelstINFO_2RtlistTransactiont
closeRpmDBtbuildTransactionRR.R R-Rtdo_runRS(R#RKR
R>tcodetmsgsR1Rf((s/usr/share/yum-cli/shell.pyRl�s.
cCs�d|_|j|�\}}}|dkr|j|�}|sp|jjtjd|t|jj |��q�|d}yt
|�}Wn1tk
r�|jj
d||�d|_dSXt|jj ||�|dkr�tj|�q�|dkr�tj|�q�n�|dkr�|j|�}|s^|jjtjd|t|jj |��q�|d}|j�tkr�|jj
d||�d|_tSt|j�}t|jj ||�|d
kr�d|j_q�n�|dkr�|jdd�}|j|�}|sZd|}|djt|jj |��}|jjtj|�tSt|jj ||�|jjr�d|j_nd|j_|jj�n
|jd�dS(s�Configure 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(s�Handle 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_repositoryhscCs�d|_|j|�\}}}|dkr�|j|�}|sNdg}n|jdd�||j_|j|jj�y|jj�Wnt j
k
r�q�X|jj�\}}||_n|dkr�|j|�}x|D]}y#|jj|jj
j|�} Wn]t jk
rB}
|jj|
�d|_q�t jk
rp}
|jj|
�d|_q�Xxk| D]c}y|jjd|�Wqxt jk
r�}
|jjd�|jj
j|�d|_tSXqxWd|j_q�Wn�|d kr�|j|�}x�|D]�}y|jj
j|�}Wn]t jk
rd}
|jj|
�d|_qt jk
r�}
|jj|
�d|_qXx+|D]#}|jj
j
|}
|
j�q�WqW|jjj�n
|jd
�dS(
s�Execute 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.RWR�trepost
enableRepotConfigErrorR R-t RepoErrortdoRepoSetuptdisableRepoRR�RFtbuildIndexesRS(R#RKR
R>R'RRYR�RtchangedR1toffrepostrepoidR�((s/usr/share/yum-cli/shell.pyR�psh
cCs4|j|�\}}}|GH|GH|GHd|_dS(Ni(RQR(R#RKR
R>((s/usr/share/yum-cli/shell.pytdo_test�s
cCs�d|_t|jj�dkr�ye|jj�\}}|dkrvx!|D]}|jjd|�qLWd|_tS|jj�}Wn�t j
k
r�}|jjd|�d|_q�tk
r�}|jjd�d|_q�tk
r"}|j
dkr|jjd�nd|_q�X|d
krK|jjd�d|_nf|dkrs|jjd �d|_n(|dkr�|jjd
�d|_n|jjtjd�|jj�ndS(s:Run the transaction.
:param line: unused
iis Error: %ss
Exiting on user canceli s
Exiting on Broken Pipei����s(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.pyRw�s@
(t__name__t
__module__t__doc__RR(R2R=RLRZR[R\RSRhRiRgRmRlR�R�R�R�Rw(((s/usr/share/yum-cli/shell.pyR s( $ - ) B Q (R�R3R
R*RtyumRt
yum.constantstyum.logginglevelsRrtyum.i18nRR<RR(((s/usr/share/yum-cli/shell.pyt<module>s
|