
,t€`±&  ã               @   sž   d  Z  d d l Z d d l Z d d l Z d d „  Z d d „  Z Gd d „  d e ƒ Z Gd	 d
 „  d
 e ƒ Z	 Gd d „  d e	 ƒ Z
 Gd d „  d e	 ƒ Z d S)z>provides information about Ubuntu's and Debian's distributionsé    Nc             C   sß   |  s d } nÌ d d „  |  j  d ƒ Dƒ } t | ƒ d k rd | \ } } } t j | | | ƒ } nw t | ƒ d k rÏ | \ } } | d k r¦ t j | | d ƒ } qÛ t j | | d	 d	 ƒ t j d	 ƒ } n t d
 ƒ ‚ | S)z9Convert a date string in ISO 8601 into a datetime object.Nc             S   s   g  |  ] } t  | ƒ ‘ q S© )Úint)Ú.0Úxr   r   ú-/usr/lib/python3/dist-packages/distro_info.pyú
<listcomp>   s   	 z convert_date.<locals>.<listcomp>ú-é   é   é   é   é   zDate not in ISO 8601 format.)ÚsplitÚlenÚdatetimeÚdateZ	timedeltaÚ
ValueError)Ústringr   ÚpartsZyearZmonthZdayr   r   r   Úconvert_date   s    	)r   c               C   s   d S)z4Get the data directory based on the module location.z/usr/share/distro-infor   r   r   r   r   Ú_get_data_dir(   s    r   c                   s(   e  Z d  Z d Z ‡  f d d †  Z ‡  S)ÚDistroDataOutdatedzDistribution data outdated.c                s   t  t |  ƒ j d ƒ d  S)Nz‹Distribution data outdated. Please check for an update for distro-info-data. See /usr/share/doc/distro-info-data/README.Debian for details.)Úsuperr   Ú__init__)Úself)Ú	__class__r   r   r   0   s    zDistroDataOutdated.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   )r   r   r   -   s   r   c               @   sµ   e  Z d  Z d Z d d „  Z e d d d „ ƒ Z d d „  Z d	 d	 d
 d „ Z d	 d d d „ Z	 d d „  Z
 d	 d d d „ Z d	 d	 d d „ Z d d „  Z d	 d d d „ Z d	 S)Ú
DistroInfozzBase class for distribution information.
    Use DebianDistroInfo or UbuntuDistroInfo instead of using this directly.
    c             C   sÁ   | |  _  t j j t ƒ  | j ƒ  d ƒ } t | ƒ } t j | ƒ } g  |  _	 xO | D]G } x. d D]& } | | k rc t
 | | ƒ | | <qc W|  j	 j | ƒ qV W| j ƒ  t j j ƒ  |  _ d  S)Nz.csvÚcreatedÚreleaseÚeolú
eol-serverúeol-esm)r!   zreleaser#   r$   r%   )Ú_distroÚosÚpathÚjoinr   ÚlowerÚopenÚcsvZ
DictReaderÚ_rowsr   ÚappendÚcloser   r   ZtodayÚ_date)r   ZdistroÚfilenameZcsvfileZ
csv_readerÚrowÚcolumnr   r   r   r   <   s    	"	

zDistroInfo.__init__Úcodenamec                s   ‡  ‡ f d d †  ˆ j  Dƒ S)zList all known distributions.c                s"   g  |  ] } ˆ j  ˆ  | ƒ ‘ q Sr   )Ú_format)r   r   )Úresultr   r   r   r   N   s   	 z"DistroInfo.all.<locals>.<listcomp>)r-   )r   r6   r   )r6   r   r   ÚallK   s    zDistroInfo.allc                s   ‡  f d d †  |  j  Dƒ S)z?Return all distributions that were available on the given date.c                s&   g  |  ] } ˆ  | d  k r | ‘ q S)r!   r   )r   r   )r   r   r   r   R   s   	 z%DistroInfo._avail.<locals>.<listcomp>)r-   )r   r   r   )r   r   Ú_availP   s    zDistroInfo._availNc             C   s   | S)z3Map codename aliases to the codename they describe.r   )r   r"   r   Údefaultr   r   r   r4   T   s    zDistroInfo.codenamec                sZ   ˆ  d k r |  j  ‰  ‡  f d d †  |  j ˆ  ƒ Dƒ } | sF t ƒ  ‚ |  j | | d ƒ S)z<Get latest development distribution based on the given date.Nc                sV   g  |  ]L } | d  d k sL ˆ  | d  k  r | d d k sL ˆ  | d k r | ‘ q S)r"   Nr#   r   )r   r   )r   r   r   r   \   s   	 z$DistroInfo.devel.<locals>.<listcomp>r   éÿÿÿÿ)r0   r8   r   r5   )r   r   r6   Údistrosr   )r   r   ÚdevelX   s    	"	zDistroInfo.develc             C   so   | d k r | d S| d k rC |  j  d | d d | d d S| d k rW | d St d	 | d
 ƒ ‚ d S)z"Format a given distribution entry.r4   ÚseriesÚfullnameú Úversionz "ú"r"   zIOnly codename, fullname, and release are allowed result values, but not 'z'.N)r&   r   )r   Úformat_stringr2   r   r   r   r5   d   s    #zDistroInfo._formatc                sZ   ˆ  d k r |  j  ‰  ‡  f d d †  |  j ˆ  ƒ Dƒ } | sF t ƒ  ‚ |  j | | d ƒ S)z7Get latest stable distribution based on the given date.Nc                sV   g  |  ]L } | d  d k	 r ˆ  | d  k r | d d k sL ˆ  | d k r | ‘ q S)r"   Nr#   r   )r   r   )r   r   r   r   u   s   	  z%DistroInfo.stable.<locals>.<listcomp>r   r:   )r0   r8   r   r5   )r   r   r6   r;   r   )r   r   Ústableq   s    	"	zDistroInfo.stablec             C   s   t  ƒ  ‚ d S)z@Get list of all supported distributions based on the given date.N)ÚNotImplementedError)r   r   r6   r   r   r   Ú	supported|   s    zDistroInfo.supportedc             C   s   | |  j  k S)z%Check if the given codename is known.)r7   )r   r4   r   r   r   Úvalid€   s    zDistroInfo.validc                sP   | d k r ˆ j  } ˆ j | ƒ ‰ ‡  ‡ ‡ f d d †  ˆ j | ƒ Dƒ } | S)zBGet list of all unsupported distributions based on the given date.Nc                s2   g  |  ]( } | d  ˆ k r ˆ j  ˆ  | ƒ ‘ q S)r=   )r5   )r   r   )r6   r   rE   r   r   r   ‰   s   	 z*DistroInfo.unsupported.<locals>.<listcomp>)r0   rE   r8   )r   r   r6   r;   r   )r6   r   rE   r   Úunsupported„   s
    	(zDistroInfo.unsupported)r   r   r   r   r   Úpropertyr7   r8   r4   r<   r5   rC   rE   rF   rG   r   r   r   r   r    7   s   r    c                   sŽ   e  Z d  Z d Z ‡  f d d †  Z d d d d „ Z d d d d	 „ Z d d d
 d „ Z d d d d „ Z d d d d „ Z	 d d „  Z
 ‡  S)ÚDebianDistroInfoz1provides information about Debian's distributionsc                s   t  t |  ƒ j d ƒ d  S)NZDebian)r   rI   r   )r   )r   r   r   r   ‘   s    zDebianDistroInfo.__init__Nc             C   s‚   | d k r |  j  | ƒ } n` | d k r< |  j | ƒ } nB | d k rZ |  j | ƒ } n$ | d k rx |  j | ƒ } n | } | S)z3Map 'unstable', 'testing', etc. to their codenames.ÚunstableÚtestingrC   Ú	oldstable)r<   rK   rC   Úold)r   r"   r   r9   r4   r   r   r   r4   ”   s    zDebianDistroInfo.codenamer4   c                sf   ˆ  d k r |  j  ‰  ‡  f d d †  |  j ˆ  ƒ Dƒ } t | ƒ d k  rR t ƒ  ‚ |  j | | d ƒ S)z<Get latest development distribution based on the given date.Nc                sV   g  |  ]L } | d  d k sL ˆ  | d  k  r | d d k sL ˆ  | d k r | ‘ q S)r"   Nr#   r   )r   r   )r   r   r   r   ¦   s   	 z*DebianDistroInfo.devel.<locals>.<listcomp>r
   éþÿÿÿ)r0   r8   r   r   r5   )r   r   r6   r;   r   )r   r   r<   ¢   s    	"	zDebianDistroInfo.develc                sf   ˆ  d k r |  j  ‰  ‡  f d d †  |  j ˆ  ƒ Dƒ } t | ƒ d k  rR t ƒ  ‚ |  j | | d ƒ S)z=Get old (stable) Debian distribution based on the given date.Nc                s6   g  |  ], } | d  d k	 r ˆ  | d  k r | ‘ q S)r"   Nr   )r   r   )r   r   r   r   ²   s   	 z(DebianDistroInfo.old.<locals>.<listcomp>r
   rN   )r0   r8   r   r   r5   )r   r   r6   r;   r   )r   r   rM   ®   s    	"	zDebianDistroInfo.oldc                sA   ˆ  d k r ˆ j  ‰  ‡  ‡ ‡ f d d †  ˆ j ˆ  ƒ Dƒ } | S)zRGet list of all supported Debian distributions based on the given
           date.Nc                sB   g  |  ]8 } | d  d k s, ˆ  | d  k r ˆ j  ˆ | ƒ ‘ q S)r#   N)r5   )r   r   )r   r6   r   r   r   r   ½   s   	 z.DebianDistroInfo.supported.<locals>.<listcomp>)r0   r8   )r   r   r6   r;   r   )r   r6   r   r   rE   ¸   s    	(zDebianDistroInfo.supportedc                sZ   ˆ  d k r |  j  ‰  ‡  f d d †  |  j ˆ  ƒ Dƒ } | sF t ƒ  ‚ |  j | | d ƒ S)z?Get latest testing Debian distribution based on the given date.Nc                sp   g  |  ]f } | d  d k r& | d sf | d  d k	 r ˆ  | d  k  r | d d k sf ˆ  | d k r | ‘ q S)r"   Nr@   r#   r   )r   r   )r   r   r   r   Å   s   	  z,DebianDistroInfo.testing.<locals>.<listcomp>r   r:   )r0   r8   r   r5   )r   r   r6   r;   r   )r   r   rK   Á   s    	"	zDebianDistroInfo.testingc             C   s   t  j |  | ƒ p | d k S)z%Check if the given codename is known.rJ   rK   rC   rL   )zunstableztestingzstablez	oldstable)r    rF   )r   r4   r   r   r   rF   Í   s    zDebianDistroInfo.valid)r   r   r   r   r   r4   r<   rM   rE   rK   rF   r   r   )r   r   rI   Ž   s   
	rI   c                   sj   e  Z d  Z d Z ‡  f d d †  Z d d d d „ Z d d	 „  Z d d d
 d „ Z d d d d „ Z ‡  S)ÚUbuntuDistroInfoz1provides information about Ubuntu's distributionsc                s   t  t |  ƒ j d ƒ d  S)NZUbuntu)r   rO   r   )r   )r   r   r   r   Ö   s    zUbuntuDistroInfo.__init__Nr4   c                sT   ˆ  d k r |  j  ‰  ‡  f d d †  |  j Dƒ } | s@ t ƒ  ‚ |  j | | d ƒ S)zZGet latest long term support (LTS) Ubuntu distribution based on the
           given date.Nc                sO   g  |  ]E } | d  j  d ƒ d k r ˆ  | d k r ˆ  | d k r | ‘ q S)r@   ÚLTSr   r"   r#   )Úfind)r   r   )r   r   r   r   Þ   s   	 z(UbuntuDistroInfo.lts.<locals>.<listcomp>r   r:   )r0   r-   r   r5   )r   r   r6   r;   r   )r   r   ÚltsÙ   s    		zUbuntuDistroInfo.ltsc                s8   ‡  f d d †  |  j  Dƒ } | s& d Sd | d d k S)zIs codename an LTS release?c                s&   g  |  ] } | d  ˆ  k r | ‘ q S)r=   r   )r   r   )r4   r   r   r   ç   s   	 z+UbuntuDistroInfo.is_lts.<locals>.<listcomp>FrP   r   r@   )r-   )r   r4   r;   r   )r4   r   Úis_ltså   s    zUbuntuDistroInfo.is_ltsc                sA   ˆ  d k r ˆ j  ‰  ‡  ‡ ‡ f d d †  ˆ j ˆ  ƒ Dƒ } | S)zRGet list of all supported Ubuntu distributions based on the given
           date.Nc                sR   g  |  ]H } ˆ  | d  k s< | d d k	 r ˆ  | d k r ˆ j  ˆ | ƒ ‘ q S)r#   z
eol-serverN)r5   )r   r   )r   r6   r   r   r   r   ñ   s   	 z.UbuntuDistroInfo.supported.<locals>.<listcomp>)r0   r8   )r   r   r6   r;   r   )r   r6   r   r   rE   ì   s    	(zUbuntuDistroInfo.supportedc                sA   ˆ  d k r ˆ j  ‰  ‡  ‡ ‡ f d d †  ˆ j ˆ  ƒ Dƒ } | S)zVGet list of all ESM supported Ubuntu distributions based on the
           given date.Nc                sB   g  |  ]8 } | d  d k	 r ˆ  | d  k r ˆ j  ˆ | ƒ ‘ q S)zeol-esmN)r5   )r   r   )r   r6   r   r   r   r   û   s   	 z2UbuntuDistroInfo.supported_esm.<locals>.<listcomp>)r0   r8   )r   r   r6   r;   r   )r   r6   r   r   Úsupported_esmö   s    	(zUbuntuDistroInfo.supported_esm)	r   r   r   r   r   rR   rS   rE   rT   r   r   )r   r   rO   Ó   s   
rO   )r   r,   r   r'   r   r   Ú	Exceptionr   Úobjectr    rI   rO   r   r   r   r   Ú<module>   s   
WE