ó
È”Mc           @   s
  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z e j d k  r^ d  d l m Z n  d  d l	 Td  d l
 Td Z d „  Z d „  Z e ƒ  Z e ƒ  Z d	 „  Z d
 „  Z d „  Z d „  Z d d „ Z e j ƒ  se j d e ƒ re e j d e ƒ ƒ qn  d S(   iÿÿÿÿNi   i   (   t   Set(   t   *s   /etc/yum.repos.d/c          C   s6   y d d l  }  |  j j ƒ  SWn t k
 r1 d SXd S(   s)   
    Get system "base" architecture.
    iÿÿÿÿN(   t   rpmUtils.archt   archt   getBaseArcht   ImportErrort   None(   t   rpmUtils(    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   _getbasearch%   s
    c          C   sí   y d d l  }  d d l } Wn t k
 r0 d SXt j d d ƒ } | j j d | ƒ } | j |  j	 |  j
 Bƒ d } | j d d ƒ } | j ƒ  d k r¯ | j d d	 ƒ } n  | j ƒ  d k rã | j ƒ  } t | d
 ƒ } ~ n  ~ ~ | S(   s)   
    Get system release and version.
    iÿÿÿÿNs   rpm-roott   /t   roott   providess   fedora-releasei    s   redhat-releaset   version(   t   rpmt   rpmUtils.transactionR   R   t   sysconft   gett   transactiont   initReadOnlyTransactiont   pushVSFlagst   _RPMVSF_NOSIGNATURESt   _RPMVSF_NODIGESTSt   dbMatcht   countt   nextt   str(   R   R   t   rpmroott   tst
   releasevert   idxt   hdr(    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   _getreleasever/   s&    c         C   s6   t  j d d t |  ƒ } t  j d d t | ƒ } | S(   sK   
    Replace some predefined strings that may appear in the repo file.
    s
   \$basearchs   %ss   \$releasever(   t   ret   subt   BASEARCHt
   RELEASEVER(   t   txtt   retxt(    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   _replaceStringsL   s    c         C   sœ   d d l  } | j |  ƒ } d } xt | j ƒ  } | j d ƒ rE q$ q$ | j d ƒ s | j d ƒ s | j d ƒ s | j d ƒ r‹ | } Pq$ | s$ Pq$ q$ | S(   sT   
    Fetches the first suggested mirror from the mirrorlist and use as baseurl.
    iÿÿÿÿNt   #s   http:s   https:s   ftp:s   file:(   t   urllibt   urlopenR   t   readlinet
   startswith(   t
   mirrorlistt   repoR(   t   listt   baseurlt   line(    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   _findBaseUrlT   s    c         C   s°   d } d } t |  ƒ } x‡ | j ƒ  } | s1 Pn  | j ƒ  } | j d ƒ rp | j d ƒ rp | j d ƒ } q q | | k r | j d ƒ r t | d ƒ } Pq q | j ƒ  | S(   sS   
    Hack to find the commented out baseurl line if mirrorlist is feeling sad.
    t   [t   ]s   []s	   #baseurl=i	   N(   R   t   openR*   t   stripR+   t   endswithR&   t   close(   t   repofileR-   t   sectionR/   t   fileR0   (    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   _searchCommentsg   s     
c         C   sG  t  |  ƒ } t ƒ  } t j ƒ  } | j |  ƒ x| j ƒ  D]} d | } t | j | d ƒ ƒ } d } d } | j | d ƒ rî t | j | d ƒ ƒ } | j	 d ƒ d k rÁ | j
 ƒ  d } n  | d k rÖ d } n  | d	 k rý d } qý n t |  | ƒ } | j | d
 ƒ rBt | j | d
 ƒ ƒ } | sBt | | ƒ } qBn  | d k ru| d k rut j t d ƒ | ƒ | S| j | d ƒ r| j | d ƒ }	 n t }	 i d d 6| d 6| d 6|	 d 6}
 | rØ| |
 d
 <n  | j | ƒ y t | |
 ƒ Wn0 t k
 r(} t j t d ƒ |  | f ƒ q; Xt j d | f |
 ƒ q; W| S(   s1   
    Loads each repository file information.
    s
   yumsync-%st   nameR/   s   
i    i   s   file:///media/cdrom/s   localmedia://s   file:///media/cdrecorder/R,   sM   Yum channel %s does not contain baseurl or mirrorlist addresses. Not syncing.t   enableds   rpm-mdt   typet   disableds   While using %s: %st   channelsN(   R4   t   sett   ConfigParsert   readt   sectionsR&   R   R   t
   has_optiont   findt
   splitlinesR;   R1   t   ifacet   warningt   _t
   getbooleant   Falset   addt   createChannelt   Errort   errorR   (   t   filenameR:   t   seenR8   R-   t   aliasR<   R/   R,   R=   t   datat   e(    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   _loadRepoFile|   sT    	
  	 

!c         C   så   t  ƒ  } t j j |  ƒ r‡ xi t j |  ƒ D]U } | j d ƒ r+ t j j |  | ƒ } t j j | ƒ r€ | j t	 | ƒ ƒ q€ q+ q+ Wn  t
 j d ƒ } xH t
 j d ƒ D]7 } | j d ƒ r¦ | | k r¦ t
 j d | f ƒ q¦ q¦ Wd S(   s8   
    Sync Smart channels based on Yum repositories.
    s   .repoR@   s   yumsync-N(   RA   t   ost   patht   isdirt   listdirR6   t   joint   isfilet   updateRV   R   R   t   keysR+   t   remove(   t   reposdirt   forceRR   t   entryt   filepathR@   RS   (    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   syncYumReposº   s    	 s   sync-yum-reposs   yum-repos-dir(   i   i   (   t	   posixpathRW   RB   R    t   syst   version_infot   setsR    RA   t   smart.channelt   smartt   YUM_REPOS_DIRR   R   R"   R#   R&   R1   R;   RV   R   Rd   R   t   getReadOnlyR   RL   (    (    (    s@   /usr/lib/python2.7/dist-packages/smart/plugins/yumchannelsync.pyt   <module>   s*   

	
							>