ó
N_c           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d d l Td d l j	 Z	 d d l
 m Z d d l Z d e j f d     YZ d S(   s<   
A shell implementation for the yum command line interface.
i’’’’N(   t   Errors(   t   *(   t   to_utf8t   YumShellc           B   s¹   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s.   A class to implement an interactive yum shell.c         C   så   t  j j |   | |  _ d |  _ d |  _ |  j d 7_ t |  _ d g |  _	 t
 | j  d k rw | j d |  _ n  d d d d d	 d
 d d g |  _ |  j |  j j j   |  _ t j d  |  _ t j d  |  _ g  |  _ d  S(   Ns   > i    t   -s   Leaving Shellt   repot
   repositoryt   exitt   quitt   runt   tst   transactiont   configs   yum.clis   yum.verbose.cli(   t   cmdt   Cmdt   __init__t   baset   promptt   resultt
   identcharst   Falset	   from_filet
   resultmsgst   lent   extcmdst   filet   shell_specific_commandst   yum_cli_commandst   keyst   commandlistt   loggingt	   getLoggert   loggert   verbose_loggert   _shell_history_cmds(   t   selfR   (    (    s   /usr/share/yum-cli/shell.pyR   #   s    				c         C   s'   |  j  j j s d  S|  j j |  d  S(   N(   R   t   conft   history_recordR"   t   append(   R#   t   cmds(    (    s   /usr/share/yum-cli/shell.pyt   _shell_history_add_cmds7   s    c         C   sn   g  } | d k r | Sy t j |  } Wn> t k
 ri } |  j j d |  |  j rj t j d  qj n X| S(   s@   split the input using shlex rules, and error or exit accordinglys   Script Error: %ss   Fatal error in script, exitingN(	   t   Nonet   shlext   splitt
   ValueErrorR    t   criticalR   R    t   YumBaseError(   R#   t   input_stringt   inputst   e(    (    s   /usr/share/yum-cli/shell.pyt   _shlex_split=   s    	c            su   t   t j   j       f d   } | t _  y t j j |  | |  } Wn  t _    n X t _  | S(   s    Sick hack for readline. c            s(     t  _  t |    }  t  _ | S(   N(   t   syst   stdoutR   (   R   t   rret(   t   _ostdoutt
   oraw_inputt   owriter(    s   /usr/share/yum-cli/shell.pyt   _sick_hack_raw_inputT   s    		(   t	   raw_inputR3   R4   t   streamt   __builtin__R   R   t   cmdloop(   R#   t   argst   kwargsR9   t   cret(    (   R6   R7   R8   s   /usr/share/yum-cli/shell.pyR=   M   s    					c         C   s   y t  |  j d  } Wn% t k
 r= t j d |  j  n X| j   } | j   t |  _ x | D] } |  j	 |  qd W|  j	 d  t S(   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.
        t   rs!   Error: Cannot open %s for readingt   EOF(
   t   openR   t   IOErrorR3   R   t	   readlinest   closet   TrueR   t   onecmd(   R#   t   fdt   linest   line(    (    s   /usr/share/yum-cli/shell.pyt   scriptg   s    
	c         C   sr  d |  _  t |  d k r4 | j   d d k r4 n:|  j |  \ } } } | |  j k r” | g } |  j j j d d | | d | k r” |  j d  t	 Sn  | d k r± d S| |  j _
 |  j j
 j d d  |  j _
 |  j |  j j
  |  j _ |  j j j d d |  j j |  j |  j j  y |  j j   Wn t j k
 rOn X|  j j   \ } } | |  _  d S(   s  Handle 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
        i    t   #R>   t    t   shellNs   
(   R   R   t   stript	   parselineR   R   t   pluginsR	   t   do_helpR   t	   cmdstringt   replaceR2   R'   R(   t   parseCommandsR    R.   t
   doCommands(   R#   RK   R   R>   t   xargsR   t   _(    (    s   /usr/share/yum-cli/shell.pyt   defaulty   s.    	(	c         C   s   d S(   s%   Do nothing on an empty line of input.N(    (   R#   (    (    s   /usr/share/yum-cli/shell.pyt	   emptyline   s    c         C   sd   t  j j |  | | | |  } x? |  j j D]1 } | j |  r+ | d k r+ | 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   R   t   completenamesR   R   t
   startswithR&   (   R#   t   textRK   t   begidxt   endidxt   rett   command(    (    s   /usr/share/yum-cli/shell.pyR\   ”   s
    c         C   s{   d } | d k r d | } n? | d k r8 d | } n& | d k rQ d	 | } n |  j  j   |  j j |  d
 |  _ d S(   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
    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
                  R   R   sÜ   
    %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.
        i    N(   s   transactions   ts(   s   repos
   repository(   R   t
   shellUsageR!   t   infoR   (   R#   t   argt   msg(    (    s   /usr/share/yum-cli/shell.pyRS   ­   s    c         C   s   |  j  |  t S(   sI   Exit the shell when EOF is reached.

        :param line: unused
        (   t   do_exitRG   (   R#   RK   (    (    s   /usr/share/yum-cli/shell.pyt   do_EOFŚ   s    c         C   s   |  j  |  t S(   s5   Exit the shell.

        :param line: unused
        (   Rg   RG   (   R#   RK   (    (    s   /usr/share/yum-cli/shell.pyt   do_quitā   s    c         C   s@   |  j  j j d k s$ |  j d k r0 d |  _ n  d g |  _ t S(   s5   Exit the shell.

        :param line: unused
        t   0i   i    s   Leaving Shell(   R   R$   t   shell_exit_statusR   R   RG   (   R#   RK   (    (    s   /usr/share/yum-cli/shell.pyRg   ź   s    $c         C   s   |  j  |  d S(   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(   t   do_transaction(   R#   RK   (    (    s   /usr/share/yum-cli/shell.pyt   do_tsõ   s    c         C   sE  d |  _  |  j |  \ } } } | d k rO |  j j t j |  j j    nņ | d k rk |  j j	   nÖ | d k ry |  j j
   \ } } Wn3 t j k
 rÅ } |  j j d |  d |  _  t SX| d k rx! | D] } |  j j d |  qŁ Wd |  _  qA|  j j t j d  n& | d	 k r4|  j d
  S|  j d  d S(   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.
        i    t   listt   resett   solves   Error building transaction: %si   s	   Error: %ss   Success resolving dependenciesR	   RN   R   N(   s   listN(   R   RQ   R)   R!   t   logt   logginglevelst   INFO_2R   t   listTransactiont
   closeRpmDBt   buildTransactionR    R.   R    R-   R   t   do_runRS   (   R#   RK   R   R>   t   codet   msgsR1   Rf   (    (    s   /usr/share/yum-cli/shell.pyRl   ż   s.    
		
c         C   sø  d |  _  |  j |  \ } } } | d k r|  j |  } | sp |  j j t j d | t |  j j	 |   q“| d } y t
 |  } Wn1 t k
 r½ |  j j d | |  d |  _  d SXt |  j j	 | |  | d k rš t j |  q“| d k r“t j |  q“n„| d k rį|  j |  } | s^|  j j t j d | t |  j j	 |   q“| d } | j   t k r|  j j d | |  d |  _  t St | j   } t |  j j	 | |  | d
 k r“d |  j _ q“nÓ | d k r§| j d d  } |  j |  } | sZd | } | d j t |  j j	 |   } |  j j t j |  t St |  j j	 | |  |  j j rd |  j _ n  d |  j _ |  j j   n |  j d  d S(   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.
        i    t
   debuglevelt
   errorlevels   %s: %ss(   Value %s for %s cannot be made to an inti   Nt   gpgcheckt   repo_gpgcheckt	   obsoletest	   assumeyess    Value %s for %s is not a Booleant   excludet   ,t    s   %s: R   (   Rz   R{   (   R|   R}   R~   R   (   R   (   R   RQ   R2   R!   Rq   Rr   Rs   t   getattrR   R$   t   intR,   R    R-   t   setattrt   setDebugLevelt   setErrorLevelt   lowert   BOOLEAN_STATESR   R)   t   upRU   t   joint   pkgSackRu   RS   (   R#   RK   R   R>   t   optst   valt   valueRf   (    (    s   /usr/share/yum-cli/shell.pyt	   do_config&  s^    
	
	
	
"c         C   s   |  j  |  d S(   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(   t   do_repo(   R#   RK   (    (    s   /usr/share/yum-cli/shell.pyt   do_repositoryh  s    c         C   sé  d |  _  |  j |  \ } } } | d k rĘ |  j |  } | sN d g } n  | j d d  | |  j _ |  j |  j j  y |  j j   Wn t	 j
 k
 r¤ qåX|  j j   \ } } | |  _  n| d k rņ|  j |  } x| D]} y# |  j j |  j j j |  }	 Wn] t	 j k
 rB}
 |  j j |
  d |  _  qč t	 j k
 rp}
 |  j j |
  d |  _  qč Xxk |	 D]c } y |  j j d |  Wqxt	 j k
 rŚ}
 |  j j d  |  j j j |  d |  _  t SXqxWd |  j _ qč Wnó | d	 k rŲ|  j |  } xµ | D]­ } y |  j j j |  } Wn] t	 j k
 rd}
 |  j j |
  d |  _  qt	 j k
 r}
 |  j j |
  d |  _  qXx+ | D]# } |  j j j | } | j   qWqW|  j j j   n |  j d
  d S(   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.
        i    Rn   t   enabledt   repolistt   enablei   t   thisrepos   Disabling Repositoryt   disableR   N(   s   listN(   R   RQ   R)   R2   t   insertR   R'   R(   RV   R    R.   RW   R   t   repost
   enableRepot   ConfigErrorR    R-   t	   RepoErrort   doRepoSetupt   disableRepoR   R   RF   t   buildIndexesRS   (   R#   RK   R   R>   R'   R   RY   R   R   t   changedR1   t   offrepost   repoidR   (    (    s   /usr/share/yum-cli/shell.pyR   p  sh    
	
		c         C   s4   |  j  |  \ } } } | GH| GH| GHd |  _ d  S(   Ni    (   RQ   R   (   R#   RK   R   R>   (    (    s   /usr/share/yum-cli/shell.pyt   do_testĮ  s
    c         C   sÅ  d |  _  t |  j j  d k rĮye |  j j   \ } } | d k rv x! | D] } |  j j d |  qL Wd |  _  t S|  j j   } Wn t	 j
 k
 rŗ } |  j j d |  d |  _  qĮt k
 rå } |  j j d  d |  _  qĮt k
 r"} | j d k r|  j j d  n  d |  _  qĮX| d k rK|  j j d  d |  _  nf | d k rs|  j j d	  d |  _  n( | d k r|  j j d
  d |  _  n  |  j j t j d  |  j j   n  d S(   s:   Run the transaction.

        :param line: unused
        i    i   s	   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 transactions   Transaction didn't starts   Finished TransactionN(   i    i   i’’’’(   R   R   R   t   tsInfoRv   R    R-   R   t   doTransactionR    R.   t   KeyboardInterruptRD   t   errnoR!   Rd   Rq   Rr   Rs   Ru   (   R#   RK   Rx   Ry   Rf   t	   returnvalR1   (    (    s   /usr/share/yum-cli/shell.pyRw   Č  s@    		(   t   __name__t
   __module__t   __doc__R   R(   R2   R=   RL   RZ   R[   R\   RS   Rh   Ri   Rg   Rm   Rl   R   R   R   R£   Rw   (    (    (    s   /usr/share/yum-cli/shell.pyR       s(   						$			-					)	B		Q	(   R«   R3   R   R*   R   t   yumR    t   yum.constantst   yum.logginglevelsRr   t   yum.i18nR   R<   R   R   (    (    (    s   /usr/share/yum-cli/shell.pyt   <module>   s   
