ó
Č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 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/zypp/repos.d/c          C   sť   d d l  }  |  j   } | d k r( d S| d k rˇ t j j d  rˇ t d d  } x\ | j   D]K } | j d  rb | j d	  d k sĄ | j d
  d k r­ d } q­ qb qb Wqˇ n  | S(   sB   
    Get system architecture (like libzypp's ZConfig does it)
    i˙˙˙˙Nt    t   noarcht   i686s   /proc/cpuinfot   rt   flagst   cx8t   cmovt   i586(	   t   platformt   machinet   ost   patht   existst   opent	   readlinest
   startswitht   find(   R
   t   architecturet   cpuinfot   line(    (    sA   /usr/lib/python2.7/dist-packages/smart/plugins/zyppchannelsync.pyt   _getbasearch$   s    *c          C   sŘ   y d d l  }  Wn t k
 r$ d SXd } t j d d  } |  j |  } | j   d k rÔ | j d d  } | j   d k r | j d d  } n  | j   d k rË | j	   } t
 | d	  } ~ n  ~ ~ n  | S(
   s)   
    Get system release and version.
    i˙˙˙˙Ns   rpm-roott   /i    t   providess   openSUSE-releases   distribution-releaset   version(   t   rpmt   ImportErrort   Nonet   sysconft   gett   TransactionSett   openDBt   dbMatcht   countt   nextt   str(   R   t
   releasevert   rpmroott   tst   idxt   hdr(    (    sA   /usr/lib/python2.7/dist-packages/smart/plugins/zyppchannelsync.pyt   _getreleasever9   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(    (    sA   /usr/lib/python2.7/dist-packages/smart/plugins/zyppchannelsync.pyt   _replaceStringsT   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   readlineR   (   t
   mirrorlistt   repoR3   t   listt   baseurlR   (    (    sA   /usr/lib/python2.7/dist-packages/smart/plugins/zyppchannelsync.pyt   _findBaseUrl\   s    c         C   sR  t  |   } t   } t j   } | j |   x| j   D]} d | } t | j | d   } d } d } | j | d  r t | j | d   } nW | j | d  rŘ t | j | d   } t	 | |  } n t
 j t d  |  | S| j | d  r| j | d  }	 n t }	 | j | d  r]| j | d  }
 |
 d k rcd	 }
 qcn d	 }
 | j d
  rd | d } n  | j d  d k rŽ| j d  d } n  i |
 d 6| d 6| d 6|	 d 6} | ră| | d <n  | j |  y t | |  Wn0 t k
 r3} t
 j t d  |  | f  q; Xt j d | f |  q; W| S(   s1   
    Loads each repository file information.
    s   zyppsync-%st   nameR9   R6   sN   ZYpp channel %s does not contain baseurl or mirrorlist addresses. Not syncing.t   enabledt   typet   NONEs   rpm-mds   cd://s   localmedia://i   s	   ?devices=i˙˙˙˙t   ?i    t   disableds   While using %s: %st   channelsN(   R   t   sett   ConfigParsert   readt   sectionsR1   R   R   t
   has_optionR:   t   ifacet   warningt   _t
   getbooleant   FalseR   R   t   splitt   addt   createChannelt   Errort   errorR   (   t   filenamet   filet   seent   repofileR7   t   aliasR;   R9   R6   R<   R=   t   datat   e(    (    sA   /usr/lib/python2.7/dist-packages/smart/plugins/zyppchannelsync.pyt   _loadRepoFileo   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(   s9   
    Sync Smart channels based on ZYpp repositories.
    s   .repoRA   s	   zyppsync-N(   RB   R   R   t   isdirt   listdirt   endswitht   joint   isfilet   updateRX   R   R   t   keysR   t   remove(   t   reposdirt   forceRS   t   entryt   filepathRA   RU   (    (    sA   /usr/lib/python2.7/dist-packages/smart/plugins/zyppchannelsync.pyt   syncZyppRepos˛   s    	 s   sync-zypp-reposs   zypp-repos-dir(   i   i   (   t	   posixpathR   RC   R+   t   syst   version_infot   setsR    RB   t   smart.channelt   smartt   ZYPP_REPOS_DIRR   R*   R-   R.   R1   R:   RX   R   Re   R   t   getReadOnlyR   RK   (    (    (    sA   /usr/lib/python2.7/dist-packages/smart/plugins/zyppchannelsync.pyt   <module>   s(   

							C