ó
È”Mc           @   sÏ   d  d l  m Z m Z d  d l m Z d  d l m Z d  d l Td  d l Td  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z e d ƒ Z e d ƒ Z e d ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   OptionParsert
   append_all(   t   getFileDigest(   t   NEVER(   t   *Ns   smart channel [options]sŒ  
This command allows one to manipulate channels. Channels are
used as sources of information about installed and available
packages. Depending on the channel type, a different backend
is used to handle interactions with the operating system and
extraction of information from the given channel.

The following channel types are available:

%(types)s

Use --help-type <type> for more information.
s  
smart channel --help-type apt-rpm
smart channel --add mydb type=rpm-sys name="RPM Database"
smart channel --add mychannel type=apt-rpm name="Some repository" \
                  baseurl=http://somewhere.com/pub/repos components=extra
smart channel --set mychannel priority=-100
smart channel --disable mychannel
smart channel --remove mychannel
smart channel --show
smart channel --show mychannel > mychannel.txt
smart channel --add ./mychannel.txt
smart channel --add http://some.url/mychannel.txt
smart channel --add /mnt/cdrom
c          C   sW   d }  t  ƒ  j ƒ  } | j ƒ  x+ | D]# \ } } |  d | | j f 7}  q& W|  j ƒ  S(   Nt    s     %-10s - %s
(   t   getAllChannelInfost   itemst   sortt   namet   rstrip(   t   resultt   typeinfot   typet   info(    (    s:   /usr/lib/python2.7/dist-packages/smart/commands/channel.pyt   build_types?   s    
c      
   C   s+  g  } t  g  |  D]0 } t | d ƒ | d d  k r9 d p< d ^ q ƒ } xÒ |  D]Ê \ } } } } } | st | } n  d d | }	 t j d | d d d	 |	 d
 |	 ƒ }
 |
 j d ƒ j ƒ  } | d  k rÔ | d 7} n  | j d | d | t | ƒ | f ƒ x |
 D] } | j | ƒ qWqP Wd j | ƒ S(   Ni    i   i   t    i   t   textt   widthiF   t   initial_indentt   subsequent_indents    (*)s     %s%s - %ss   
(	   t   maxt   lent   Nonet   textwrapt   wrapt   popt   stript   appendt   join(   t   fieldsR   t   xt   maxkeyt   keyt   labelt   ftypet   defaultt   descrt   indentt   linest   line(    (    s:   /usr/lib/python2.7/dist-packages/smart/commands/channel.pyt   format_fieldsG   s     C		(c       	   C   sH  t  i t ƒ  d 6}  t d t d |  d t ƒ } d  | j d <d  | j d <d  | j d <d  | j d <d  | j d	 <d  | j d
 <d  | j d <d  | j d <| j d d d d t d t	 d ƒ ƒ| j d d d d t d t	 d ƒ ƒ| j d d d d t d t	 d ƒ ƒ| j d d d d t	 d ƒ ƒ| j d d d d t d t	 d ƒ ƒ| j d d d d t d t	 d ƒ ƒ| j d d d d t d t	 d ƒ ƒ| j d d d d t	 d  ƒ ƒ| j d! d d d t d t	 d" ƒ ƒ| j d# d d d t d t	 d$ ƒ ƒ| j d% d& d d d t	 d' ƒ ƒ| j d( d d) d* d+ d t	 d, ƒ ƒ| S(-   Nt   typest   usaget   descriptiont   examplest   addt   sett   removet   enablet   disablet   listt   showt   yamls   --addt   actiont   callbackt   helpsÕ   argument is an alias and one or more key=value pairs defining a channel, or a filename/url pointing to a channel description in the same format used by --show, or a directory path where autodetection will be trieds   --setsI   argument is an alias, and one or more key=value pairs modifying a channels   --removes+   arguments are channel aliases to be removeds   --remove-allt
   store_trues   remove all existent channelss   --lists   list all known channel aliasess   --showsL   show channels with given aliases, or all channels if no arguments were givens   --yamls"   show given channels in YAML formats   --edits&   edit channels in editor set by $EDITORs   --enables"   enable channels with given aliasess	   --disables#   disable channels with given aliasess   -ys   --yess   execute without askings   --help-typet   storet   metavart   TYPEs)   show further information about given type(
   t   DESCRIPTIONR   R    t   USAGEt   EXAMPLESR   t   defaultst
   add_optionR   t   _(   R,   t   parser(    (    s:   /usr/lib/python2.7/dist-packages/smart/commands/channel.pyt   option_parserY   sJ    	c         C   s+   t  ƒ  } | j |  ƒ \ } } | | _ | S(   N(   RD   t
   parse_argst   args(   t   argvRC   t   optsRF   (    (    s:   /usr/lib/python2.7/dist-packages/smart/commands/channel.pyt   parse_options‡   s    		c   "      C   sË  | j  r{ t | j  ƒ } t d ƒ G| j  Gd G| j GHH| j j ƒ  GHHt d ƒ GHt | j ƒ GHHt d ƒ GHHt j	 d ƒ n  t
 j ƒ  t k rß | j d  k rß | j d  k rß | j d  k rß t j t d ƒ ƒ t t d ƒ ‚ n  | j d  k	 rÌ| j r`| j d g k r`g  } t j j ƒ  } t | ƒ } x´| D]' } | | } | | d <| j | ƒ q2Wn‚t | j ƒ d	 k r| j d } t j j | ƒ r¹t
 j d
 | d t ƒt | ƒ } qât j j  | ƒ r$g  } t! | ƒ j ƒ  } t | ƒ } x| D]' } | | } | | d <| j | ƒ qöWqâd | k rø|  j" | g d ƒ \ }	 }
 |
 rkt t d ƒ |
 | ‚ n  t! |	 | ƒ j ƒ  } |	 | j# t
 j$ d ƒ ƒ r±t j% |	 | ƒ n  g  } t | ƒ } xE | D]' } | | } | | d <| j | ƒ qÊWqât t d ƒ | ‚ nÔ | j rÓ| j j& d ƒ j ƒ  } | sGt t d ƒ ‚ n  i  } xa | j D]V } d | k rt t d ƒ | ‚ n  | j' d d	 ƒ \ } } | j ƒ  | | j ƒ  <qWWt( | ƒ } | | d <| g } n t t d ƒ ‚ g  } xl| D]d} | j$ d ƒ } | j) sct | ƒ } HxB | j D]7 \ } } } } } | | k r$d | | | f GHq$q$WHn  | j) st j* t d ƒ ƒ rïy t+ d | ƒ Wn t k
 rª} ‚  qSXy | j$ d ƒ } xP | sÜt
 j, d | f ƒ r| rôt d ƒ | GHn  t- t d ƒ ƒ j ƒ  } qÀW| d =t
 j d | f | ƒ | j | ƒ WqSt. k
 rOHqSXqïqïWg  | D]$ } t
 j$ d | d f ƒ r^| ^ q^} | rÌHt d ƒ GHHd d  l/ } | j0 | ƒ } | j1 |  | ƒ qÌn  | j rH| j sðt t d ƒ ‚ n  | j j& d ƒ } d | k r t t d ƒ ‚ n  t
 j$ d | f ƒ } | sQt t d  ƒ | ‚ n  x£ | j D]˜ } d | k rƒt t d ƒ | ‚ n  | j' d d	 ƒ \ } } | j ƒ  } | d k rÅt t d! ƒ ‚ n  | d k rãt t d" ƒ ‚ n  | j ƒ  | | <q[Wx( | j2 ƒ  D] } | | s| | =qqWt+ | | ƒ t
 j d | f | ƒ n  | j3 rÒx~ | j3 D]p } t
 j, d | f ƒ s™| j) s™t j* t d# ƒ | ƒ r[t
 j3 d | f ƒ sËt j t d$ ƒ | ƒ qËq[q[Wn  | j4 rt
 j$ d ƒ s	| j) s	t j* t d% ƒ ƒ rt
 j3 d ƒ qn  | j5 rxY | j5 D]K } t
 j, d | f ƒ sdt j t d$ ƒ | ƒ q/t
 j3 d | d& f ƒ q/Wn  | j6 réx\ | j6 D]N } t
 j, d | f ƒ sÉt j t d$ ƒ | ƒ q”t
 j d | d& f d' ƒ q”Wn  | j d  k	 r[	x` | j p	t
 j$ d d/ ƒ D]@ } t
 j$ d | f ƒ } | sO	t j t d$ ƒ | ƒ q	| GHq	Wn  | j d  k	 rì	x | j p…	t
 j$ d d0 ƒ D]_ } t
 j$ d | f ƒ } | sÁ	t j t d$ ƒ | ƒ q†	t7 | t( | ƒ ƒ } | r†	| GHHq†	q†	Wn  | j d  k	 r
d d  l } i  } xn | j p(
t
 j$ d d1 ƒ D]Q } t
 j$ d | f ƒ } | sd
t j t d$ ƒ | ƒ q)
t( | ƒ } | | | <q)
W| j8 | ƒ GHn  | j9 rÇt
 j: ƒ  t; j< d( ƒ \ } } t j= | d) ƒ } t
 j2 d ƒ } | j> ƒ  xF | D]> } t
 j$ d | f ƒ } t7 | t( | ƒ ƒ } | | IJ| Jqé
W| j? ƒ  t j@ j$ d* d+ ƒ } tA | ƒ } x^t r¶t jB d, | | f ƒ tA | ƒ }  |  | k r’Pn  t! | ƒ } | j ƒ  } | j? ƒ  y t | ƒ } WnE t k
 r} t jC tD | ƒ ƒ t j* t d- ƒ t ƒ sYPqqYn XtE }! xh | D]` } | | } y t+ | | ƒ Wqt k
 rx} t }! t jC t d. ƒ | tD | ƒ f ƒ qXqW|! r¢t j* t d- ƒ t ƒ s³Pq³qYt
 j d | ƒ PqYWt j% | ƒ n  d  S(2   Ns   Type:t   -s   Fields:s-   (*) These fields are necessary for this type.i    s    Can't edit channels information.s"   Configuration is in readonly mode.t   aliasi   s   default-localmediat   softs   :/s   channel descriptions'   Unable to fetch channel description: %ss   data-dirs   File not found: %ss   Channel has no aliast   =s   Argument '%s' has no '='s   Channel information neededR   s   %s: %ss   Include this channel?t   channelss%   Channel alias '%s' is already in use.s   Channel alias: t	   removables   Updating removable channels...iÿÿÿÿs   Invalid argumentss(   First argument must be the channel aliass!   Channel with alias '%s' not founds   Can't change the channel types   Can't change the channel aliass   Remove channel '%s'?s   Channel '%s' not found.s   Remove ALL channels?t   disabledt   yess   .init   wt   EDITORt   vis   %s %ss	   Continue?s   Error in '%s' channel: %s(    (    (    (F   t	   help_typet   getChannelInfoRB   R	   R,   R   R)   R   t   syst   exitt   sysconft   getReadOnlyt   TrueR3   R   R4   R5   t   ifacet   warningt   ErrorR.   RF   t   stdint   readt   parseChannelsDescriptionR   R   t   ost   patht   isdirR/   t   detectLocalChannelst   isfilet   opent   downloadURLst
   startswitht   gett   unlinkR   t   splitt   parseChannelDataRQ   t   askYesNot   createChannelt   hast	   raw_inputt   KeyboardInterruptt   updateRI   t   maint   keysR0   t
   remove_allR1   R2   t   createChannelDescriptiont   dumpt   editt   assertWritablet   tempfilet   mkstempt   fdopenR   t   closet   environR   t   systemt   errort   unicodet   False("   t   ctrlRH   R   t   newchannelst   datat   descriptionsRK   t   channelt   argt   succt   failR!   t   valuet
   newaliasesR   R"   R#   R$   R%   t   eRO   Rs   t
   updateoptst   descR5   t   yamlchannelst   fdR	   t   filet   aliasest   editort	   olddigestt	   newdigestt   failed(    (    s:   /usr/lib/python2.7/dist-packages/smart/commands/channel.pyRt      s²   	!





	
			$		
	$			 """	



	

(   t   smart.optionR    R   t   smart.util.filetoolsR   t   smart.constR   t   smart.channelt   smartR{   R   RW   Rb   RB   R>   R=   R?   R   R)   RD   RI   Rt   (    (    (    s:   /usr/lib/python2.7/dist-packages/smart/commands/channel.pyt   <module>   s"   

					.	