Ñò
‹[³Kc        
   @   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 e 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 o> |  o7 y t i
 d |  ƒ } Wn | j
 o t	 ‚ n X| S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   s|  |  i  ƒ  i d ƒ o  t i |  d d d ƒd }  n d d  k } h | i d  6| i d 6| i d 6| i d 6| i	 d 6} 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Ä W| oL | o | | d <n d | j o& | o t
 | ƒ | d <q;| d =qxn: d | j o, | | d <| o | i | ƒ | d <qx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 attributet   vexact(   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   vstringt	   add_exactR"   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"   sX      


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 ~ St  Sd  S(   Ns   old-versionsR   i   (   t   _old_versionsR   R!   R,   R   (   R   R   RB   t   st   _[2]R@   (    (    s'   /usr/share/pycentral-data/pyversions.pyR*   U   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 ~ St  Sd  S(   Ns   unsupported-versionsR   i   (   t   _unsupported_versionsR   R!   R,   R   (   R   R   RB   RF   RG   R@   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   unsupported_versionsc   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¢~ S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   PIPERM   t   ImportErrorR	   t   popent   joinR   R   t   closeR.   t   sub(   R   R   RB   RF   t   cmdRQ   t   pt   fdt   dependst   lineRG   t   _[3]R@   (    (    s'   /usr/share/pycentral-data/pyversions.pyR(   q   s8    4 -
0
$c         C   si  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 St  Sd  S(   Ns   /usr/bin/pythons   -cs!   import sys; print sys.version[:3]iÿÿÿÿRK   i   RL   RM   s6   /usr/bin/python -c 'import sys; print sys.version[:3]'s   \d\.\d$t   pythons   default-versions	   python2.5s   /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   RQ   RR   R+   RS   RM   RT   RU   t   readlineR,   RW   R.   R0   R   R   R
   RV   (   R   t   linkRY   RQ   RZ   R[   R]   t   debian_default(    (    s'   /usr/share/pycentral-data/pyversions.pyt   default_version“   s6    
"
	c         C   s4  d  } t |  d t ƒ} t d t ƒ } t | ƒ d j ol d | j o
 | } qíd | j o t d t ƒ g } qíd | j o | d } qí| d i | ƒ } nHd | j o d | j o t d ‚ n!d | j oV d | j o | d i | ƒ } n t | ƒ } d | j o | i	 | d ƒ qín¾ d | j o: t d t ƒ } | | d j o t d	 ‚ n | g } nw d | j p d | j oS t ƒ  } d | j o | d i | ƒ } n d | j o | i	 | d ƒ qín
 t d
 ‚ | p t
 d ‚ n | o | Sg  } | D] } | d | q~ Sd  S(   NR6   R   i   R   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   RD   R)   R(   t   lenRf   t   intersectionR   R'   t   updateR    (   R5   R   R   R8   t	   supportedR   RB   R@   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   requested_versions³   sH    
		c   
      C   s_  d  } t |  d t ƒ} t d t ƒ } t d t ƒ } t d t ƒ } | i | ƒ t | ƒ d j ol d | j o
 | } qd | j o t d t ƒ g } qd | j o | d } q| d i	 | ƒ } nHd | j o d | j o t
 d ‚ n!d | j oV d | j o | d i	 | ƒ } n t | ƒ } d | j o | i | d ƒ qn¾ d | j o: t d t ƒ } | | d j o t
 d	 ‚ n | g } nw d | j p d | j oS t ƒ  } d | j o | d i	 | ƒ } n d | j o | i | d ƒ qn
 t
 d
 ‚ | p t d ‚ n | o | Sg  } | D] }	 | d |	 qC~ Sd  S(   NR6   R   i   R   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   RD   R)   R*   RI   R(   t   extendRg   Rf   Rh   R   R'   Ri   R    (
   R5   R   R   R8   t   oldt   unsupportedRj   R   RB   R@   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   requested_versions_for_runtimeá   sN    
		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„ ~ S| Sd  S(   Niÿÿÿÿs   /usr/bin/python[0-9].[0-9]i   (   t   globR(   R	   R
   t   basenamet   sort(   R   Rp   Rj   RB   RF   R   RG   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.pyRt     s   t   MissingVersionValueErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s'   /usr/share/pycentral-data/pyversions.pyRu     s   c         C   s  d } d } d } x t |  ƒ D]} | i ƒ  } | d j o0 | d j o q n | 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 ƒ  } q1q q W| d j o t d
 ‚ n | d j o | d j o t d ‚ n | S| 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 sectionRO   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!   Rt   Ru   (   t   fnt   pkgt   versiont   sversiont   sectionR]   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   extract_pyversion_attribute   sF     



 (
c         C   sm   g  } |  i  d ƒ D] } | t | ƒ q ~ } g  } | i  d ƒ D] } | t | ƒ qD ~ } t | | ƒ S(   Nt   .(   R!   t   intt   cmp(   t   ver1t   ver2RB   t   it   v1RG   t   v2(    (    s'   /usr/share/pycentral-data/pyversions.pyt   version_cmpI  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!   Rg   R†   t   appendR   Rr   (	   R5   R   R   t   py_supported_shortt   itemR@   t   verRB   Rƒ   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   requested_versions_bisN  s4      )c         C   s   t  |  ƒ i ƒ  i d ƒ } | S(   Ns   
(   R   Rc   t   rstrip(   Rx   R5   (    (    s'   /usr/share/pycentral-data/pyversions.pyt   extract_pyversion_attribute_bisi  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 versionsRj   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   RN   s   debian/controlRw   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
   Rq   t   syst   argvR•   Rg   Rf   R   R   t   exitRj   RV   R(   R—   Rs   R–   t   isfileR}   Rk   Rt   t   stderrt   writeRu   t   dirnameRŽ   RŒ   t   IOError(   R   R   t   parsert   optst   argst   programt   msgR   Rx   R5   t   vs(    (    s'   /usr/share/pycentral-data/pyversions.pyt   mainm  s|    

!t   __main__(#   R	   R.   R    Rœ   R'   t   SetTypet	   NameErrort   setst   SetR   R    R   R   R   R+   RD   RE   R*   RH   RI   RP   R(   R`   Rf   Rk   Ro   Rs   Rt   Ru   R}   R†   RŒ   RŽ   Rª   R   (    (    (    s'   /usr/share/pycentral-data/pyversions.pyt   <module>   s<   0
	2! ..	)			D