łň
ć­oHc        
   @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z y
 e Z Wn1 e j
 o% d  d k Z e i Z e i Z n Xd e	 f d     YZ
 d a d d  Z d   Z d a e d  Z d a e d  Z d a e d  Z d a e d	  Z e d
  Z e d  Z e d  Z d e	 f d     YZ d e	 f d     YZ d   Z d   Z e d  Z d   Z  d   Z! e" d j o e!   n d S(   i˙˙˙˙Nt   PyCentralEmptyValueErrorc           B   s   e  Z d  Z RS(   s   Python Central Value Error(   t   __name__t
   __module__t   __doc__(    (    (    s'   /usr/share/pycentral-data/pyversions.pyR       s   c         C   sŹ   d d k  l } l } t pC t i i d  o& |   } | i t d   | a q` t	  n t oA |  o: y t i
 d |   } Wn | j
 o t	  n X| Sn d  S(   Ni˙˙˙˙(   t   SafeConfigParsert   NoOptionErrors!   /usr/share/python/debian_defaultst   DEFAULT(   t   ConfigParserR   R   t	   _defaultst   ost   patht   existst   readfpt   filet
   ValueErrort   gett   None(   t   nameR   R   t   configt   value(    (    s'   /usr/share/pycentral-data/pyversions.pyt   read_default   s    	

c      
   C   s3  |  i    i d  o  t i |  d d d d }  n d d  k } h  | i d  <| i d <| i d <| i d <| i	 d <} h  } t
 g   } t
 t d	 t  t d	 t   } t } x5|  i d
  D]$} | i   } | d j o d | d <qÎ n | d j o | | d <qÎ n | i d t
    t i d  } | i |  }	 y |	 i d  |	 i d  }
 } |
 d j o | i |  nF t } | |
 } g  } | D]! } | | |  o | | q¨q¨~ } WqÎ t j
 o t d  qÎ XqÎ Wd | j o, | | d <| o | i |  | d <q/n | S(   Ns   python:versions=t   =t   maxspliti   i˙˙˙˙s   >=s   <=s   <<t   version_onlyt   ,t   allt   currentt   current_extt   versionss   (>=|<=|<<|=)? *(\d\.\d)$i   s&   error parsing Python-Version attribute(   s   currents   current_ext(   NR   (   t   lowert
   startswitht   stringt   splitt   operatort   eqR   t   get   let   ltt   sett   supported_versionst   Truet   old_versionst   Falset   stript
   setdefaultt   ret   compilet   matcht   groupt   addt	   ExceptionR   t   union(   t   vstringR!   t	   operatorst   vinfot   exact_versionst   version_ranget
   relop_seent   fieldt   vet   mt   opt   vt   filtopt   _[1]t   av(    (    s'   /usr/share/pycentral-data/pyversions.pyt   parse_versions"   sJ      


9
c      
   C   s   t  p` y@ t d  } g  } | i d  D] } | | i   q* ~ a  Wqg t j
 o g  a  qg Xn |  o' g  } t  D] } | | d qy ~ Sn t  Sd  S(   Ns   old-versionsR   i   (   t   _old_versionsR   R    R+   R   (   R   R   R@   t   st   _[2]R>   (    (    s'   /usr/share/pycentral-data/pyversions.pyR)   L   s    4'c      
   C   s   t  p` y@ t d  } g  } | i d  D] } | | i   q* ~ a  Wqg t j
 o g  a  qg Xn |  o' g  } t  D] } | | d qy ~ Sn t  Sd  S(   Ns   unsupported-versionsR   i   (   t   _unsupported_versionsR   R    R+   R   (   R   R   R@   RD   RE   R>   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   unsupported_versionsZ   s    4'c         C   sĆ  t  py@ t d  } g  } | i d  D] } | | i   q* ~ a  Wqt j
 o6d d d d g } y= d d  k } | i | d d	 d
 t d | i } | i	 } Wn+ t
 j
 o t i d i |   } n Xd  } xG | D]? }	 |	 i d  o) |	 i d d	  d	 i   i d  } qâ qâ W| i   | o: g  }
 | D] } |
 t i d d |  qA~
 } | a  n t  p d d g a  qqXn |  o' g  } t  D] } | | d q˘~ Sn t  Sd  S(   Ns   supported-versionsR   s   /usr/bin/apt-caches   --no-all-versionst   shows
   python-alli˙˙˙˙t   bufsizei   t   shellt   stdoutt    s   Depends:t   :s   \s*(\S+)[ (]?.*s   \1s	   python2.4s	   python2.5i   (   t   _supported_versionsR   R    R+   R   t
   subprocesst   PopenR*   t   PIPERK   t   ImportErrorR	   t   popent   joinR   R   t   closeR-   t   sub(   R   R   R@   RD   t   cmdRO   t   pt   fdt   dependst   lineRE   t   _[3]R>   (    (    s'   /usr/share/pycentral-data/pyversions.pyR'   h   s8    4 -
0
'c         C   sl  t  pJy t i d  a  } WnÇ t j
 oť d  a  yL d d d g } d d  k } | i | d d d t d | i } | i	 } Wn" t
 j
 o t i d	  } n X| i   i   } | i   t i d
 |  o d | a  qč n Xy t d  } Wn t j
 o d } n Xt  | t i i d |  f j o t d |  n | a  n |  o t  d Sn t  Sd  S(   Ns   /usr/bin/pythons   -cs!   import sys; print sys.version[:3]i˙˙˙˙RI   i   RJ   RK   s6   /usr/bin/python -c 'import sys; print sys.version[:3]'s   \d\.\d$t   pythons   default-versions	   python2.4s   /usr/binsZ   /usr/bin/python does not match the python default version. It must be reset to point to %si   (   t   _default_versionR	   t   readlinkt   OSErrorR   RO   RP   R*   RQ   RK   RR   RS   t   readlineR+   RU   R-   R/   R   R   R
   RT   (   R   t   linkRW   RO   RX   RY   R[   t   debian_default(    (    s'   /usr/share/pycentral-data/pyversions.pyt   default_version   s6    
"
c         C   sn  d  } t |   } t d t  } t |  d j oQ d | j o
 | } q$d | j o t d t  g } q$| d i |  } n  d | j o d | j o t d  ny d | j o | d i |  } } nQ d | j o: t d t  } | | d j o t d  n | g } n
 t d  | p t d	  n | o | Sn$ g  } | D] } | d
 | qR~ Sd  S(   NR   i   R   R   R   s*   both `current' and `all' in version strings+   `current' version not in supported versionss   error in version strings   empty set of versionss   python%s(	   R   RB   R'   R(   t   lenRd   t   intersectionR   R    (   R4   R   R   R6   t	   supportedR   R@   R>   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   requested_versionsŞ   s0    
	c   
      C   s  d  } t |   } t d t  } t d t  } t d t  } | i |  t |  d j oQ d | j o
 | } qOd | j o t d t  g } qO| d i	 |  } n  d | j o d | j o t
 d  ny d | j o | d i	 |  } } nQ d | j o: t d t  } | | d j o t
 d  n | g } n
 t
 d  | p t d	  n | o | Sn$ g  } | D] }	 | d
 |	 q}~ Sd  S(   NR   i   R   R   R   s*   both `current' and `all' in version strings+   `current' version not in supported versionss   error in version strings   empty set of versionss   python%s(   R   RB   R)   R(   RG   R'   t   extendRe   Rd   Rf   R   R    (
   R4   R   R   R6   t   oldt   unsupportedRg   R   R@   R>   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   requested_versions_for_runtimeË   s6    
	c         C   s¨   d d  k  } t   } g  } | i  d  D]6 } t i i |  | j o | t i i |  q) q) ~ } | i   |  o' g  } | D] } | | d q ~ Sn | Sd  S(   Ni˙˙˙˙s   /usr/bin/python[0-9].[0-9]i   (   t   globR'   R	   R
   t   basenamet   sort(   R   Rm   Rg   R@   RD   R   RE   R>   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   installed_versionsě   s    	9
't   ControlFileValueErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s'   /usr/share/pycentral-data/pyversions.pyRq   ř   s   t   MissingVersionValueErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s'   /usr/share/pycentral-data/pyversions.pyRr   ú   s   c         C   s  d } d } d } xt |   D]ţ } | i   } | d j o | d j o Pn d } q | i d  o
 d } q | i d |  o
 | } q | i d  o: | d j o t d  n | i d d  d i   } q | i d	  o1 | | j o  | i d d  d i   } qq q W| d j o t d
  n | d j o" | d j o t d  n | Sn | d j o t d |  n | S(   s{   read the debian/control file, extract the XS-Python-Version
    field; check that XB-Python-Version exists for the package.t    t   Sources   Source:s	   Package: s   XS-Python-Version:s1   attribute XS-Python-Version not in Source sectionRM   i   s   XB-Python-Version:s   not a control files)   missing XS-Python-Version in control files)   missing XB-Python-Version for package `%sN(   R   R   R+   R   R   R    Rq   Rr   (   t   fnt   pkgt   versiont   sversiont   sectionR[   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   extract_pyversion_attributeý   sB     



 (
c         C   sm   g  } |  i  d  D] } | t |  q ~ } g  } | i  d  D] } | t |  qD ~ } t | |  S(   Nt   .(   R    t   intt   cmp(   t   ver1t   ver2R@   t   it   v1RE   t   v2(    (    s'   /usr/share/pycentral-data/pyversions.pyt   version_cmp$  s    00c   	   	   C   sz  g  } t  d t  } x|  i d  D]ü } | i d  } t |  d j oŽ | d p | d | d <n | d p | d | d <n x | D]e } yI t | | d  d j o+ t | | d  d j o | i |  n Wq t j
 o q Xq Wq% | d | j o | i | d  q% q% W| i t  | p t d  n | p) g  } | D] } | d | qX~ } n | S(	   NR   R   t   -i   i    i˙˙˙˙s   empty set of versionsR]   (   R'   R(   R    Re   R   t   appendR   Ro   (	   R4   R   R   t   py_supported_shortt   itemR>   t   verR@   R   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   requested_versions_bis)  s4      )c         C   s   t  |   i   i d  } | S(   Ns   
(   R   Ra   t   rstrip(   Ru   R4   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   extract_pyversion_attribute_bisD  s    c          C   sŇ  d d k  l }  d } |  d |  } | i d d d d d	 d
 d d | i d d d d d	 d
 d d | i d d d d d	 d
 d d | i d d d d d	 d
 d d | i d d d d d t d	 d
 d d | i   \ } } t i i t i	 d  } | i
 o[ t |  d j oH y t | i  GHWqÎt j
 o# } d | G| GHt i d  qÎXnj| i o. t |  d j o d  i t | i   GHn2| i o. t |  d j o d  i t | i   GHnú| i oČt |  d j oľt |  d j o
 d! } n | d } yKt i i |  o| } y% t | d"  }	 t |	 | i  }
 WqUt j
 o. t i i d# | | f  t i d  qUt j
 o t i i t i i |  d$  } t i i d% | | f  y" t |  }	 t |	 | i  }
 Wq?t  j
 o* t i i d& |  t | i  }
 q?XqUXn t | | i  }
 d  i |
  GHWqÎt j
 o0 } t i i d' | | f  t i d  qÎXn( t i i d( | | f  t i d  d  S()   Ni˙˙˙˙(   t   OptionParsersk   [-v] [-h] [-d|--default] [-s|--supported] [-i|--installed] [-r|--requested <version string>|<control file>]t   usages   -ds	   --defaultt   helps    print the default python versiont   actiont
   store_truet   destt   defaults   -ss   --supporteds#   print the supported python versionsRg   s   -rs   --requesteds   print the python versions requested by a build; the argument is either the name of a control file or the value of the XS-Python-Version attributet	   requesteds   -is   --installeds-   print the installed supported python versionst	   installeds   -vs	   --versions    print just the version number(s)R   i    s   %s:i   RL   s   debian/controlRt   s   %s: not a control file: %s, t
   pyversionss?   %s: missing XS-Python-Version in control file, fall back to %s
sD   %s: missing debian/pyversions file, fall back to supported versions
s   %s: %s
s   usage: %s %s
(!   t   optparseR   t
   add_optionR*   t
   parse_argsR	   R
   Rn   t   syst   argvR   Re   Rd   R   R   t   exitRg   RT   R'   R   Rp   R   t   isfileRz   Rh   Rq   t   stderrt   writeRr   t   dirnameR   R   t   IOError(   R   R   t   parsert   optst   argst   programt   msgR   Ru   R4   t   vs(    (    s'   /usr/share/pycentral-data/pyversions.pyt   mainH  s|    

!t   __main__(#   R	   R-   R   R   R&   t   SetTypet	   NameErrort   setst   SetR   R    R   R   R   RB   RC   R*   R)   RF   RG   RN   R'   R^   Rd   Rh   Rl   Rp   Rq   Rr   Rz   R   R   R   R§   R   (    (    (    s'   /usr/share/pycentral-data/pyversions.pys   <module>   s<   0
		)! !!	'			D