o
    .Úeeð0  ã                   @   s„   d Z ddlZddlZddlZdd„ Zdd„ ZG dd„ deƒZG d	d
„ d
ƒZdd„ Z	G dd„ dƒZ
G dd„ de
ƒZG dd„ de
ƒZdS )z>provides information about Ubuntu's and Debian's distributionsé    Nc                 C   sž   | sd}|S dd„ |   d¡D ƒ}t|ƒdkr$|\}}}t |||¡}|S t|ƒdkrK|\}}|dkr;t ||d¡}|S t ||d	 d	¡t d	¡ }|S td
ƒ‚)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ÚdateÚ	timedeltaÚ
ValueError)Ústringr   ÚpartsÚyearÚmonthÚ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‡  ZS )ÚDistroDataOutdatedzDistribution data outdated.c                    ó   t ƒ  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.©ÚsuperÚ__init__©Úself©Ú	__class__r   r   r    2   s   ÿzDistroDataOutdated.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    Ú__classcell__r   r   r#   r   r   /   s    r   c                   @   s0   e Zd ZdZ							ddd„Zdd„ ZdS )ÚDistroReleasez"Represents a distributions releaseNc                 C   s@   || _ || _|| _|| _|| _|| _|| _|	| _|| _|
| _	d S ©N)
ÚversionÚcodenameÚseriesÚcreatedÚreleaseÚeolÚeol_ltsÚeol_eltsÚeol_esmÚ
eol_server)r"   r,   r-   r.   r/   r0   r1   r4   r2   r3   r5   r   r   r   r    ?   s   
zDistroRelease.__init__c                 C   s2   || j ko| jdu p|| jkp| jduo|| jkS )z:Check whether this release is supported on the given date.N)r/   r1   r5   ©r"   r   r   r   r   Úis_supportedX   s   

ÿýzDistroRelease.is_supported)NNNNNNN)r%   r&   r'   r(   r    r7   r   r   r   r   r*   9   s    

õr*   c                 C   s   || v r
t | | ƒS d S r+   )r   )ÚrowÚcolumnr   r   r   Ú	_get_datea   s   r:   c                   @   s‚   e Zd ZdZdd„ Zedd„ ƒZddd„Zd	d
„ Zddd„Z	ddd„Z
ddd„Zdd„ Zddd„Zddd„Zdd„ Z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 tƒ | ¡ d ¡}t|dd��C}t |¡}g | _	|D ]0}t
|d |d |d t|dƒt|dƒt|d	ƒt|d
ƒt|dƒt|dƒt|dƒƒ
}| j	 |¡ q W d   ƒ n1 s[w   Y  tj ¡ | _d S )Nz.csvzutf-8)Úencodingr,   r-   r.   r/   r0   r1   zeol-esmzeol-ltszeol-eltsz
eol-server)Ú_distroÚosÚpathÚjoinr   ÚlowerÚopenÚcsvÚ
DictReaderÚ	_releasesr*   r:   Úappendr   r   ÚtodayÚ_date)r"   ÚdistroÚfilenameÚcsvfileÚ
csv_readerr8   r0   r   r   r   r    j   s,   
öóýzDistroInfo.__init__c                 C   s   dd„ | j D ƒS )z*List codenames of all known distributions.c                 S   s   g | ]}|j ‘qS r   ©r.   r   r   r   r   r   ƒ   s    z"DistroInfo.all.<locals>.<listcomp>©rE   r!   r   r   r   Úall€   s   zDistroInfo.allr-   c                    s   ‡ ‡fdd„ˆj D ƒS )zList all known distributions.c                    s   g | ]}ˆ  ˆ |¡‘qS r   )Ú_formatr   ©Úresultr"   r   r   r   ‡   s    z&DistroInfo.get_all.<locals>.<listcomp>rN   )r"   rR   r   rQ   r   Úget_all…   s   zDistroInfo.get_allc                    s   ‡ fdd„| j D ƒS )z?Return all distributions that were available on the given date.c                    s   g | ]	}ˆ |j kr|‘qS r   )r/   r   ©r   r   r   r   ‹   ó    z%DistroInfo._avail.<locals>.<listcomp>rN   r6   r   rT   r   Ú_avail‰   ó   zDistroInfo._availNc                 C   s   |S )z3Map codename aliases to the codename they describe.r   )r"   r0   r   Údefaultr   r   r   r-   �   s   zDistroInfo.codenamec                 C   s*   | j D ]}||j|jfv r|j  S q|S )z!Map codename or series to version)rE   r-   r.   r,   )r"   ÚnamerX   r0   r   r   r   r,   ’   s
   

ÿzDistroInfo.versionc                    ó@   ˆ du r| j ‰ ‡ fdd„|  ˆ ¡D ƒ}|stƒ ‚|  ||d ¡S )ú<Get latest development distribution based on the given date.Nc                    ó8   g | ]}|j d u sˆ |j k r|jd u sˆ |jkr|‘qS r+   ©r0   r1   r   rT   r   r   r   �   ó
    (þz$DistroInfo.devel.<locals>.<listcomp>éÿÿÿÿ©rH   rV   r   rP   ©r"   r   rR   Údistrosr   rT   r   Údevel™   ó   
þzDistroInfo.develc                 C   s^   |dkr|S |dkr|j S |dkr | jd |j d |j d S |dkr'|jS td| d	 ƒ‚)
z"Format a given distribution entry.Úobjectr-   Úfullnameú z "ú"r0   zQOnly codename, fullname, object, and release are allowed result values, but not 'z'.)r.   r=   r,   r-   r   )r"   Úformat_stringr0   r   r   r   rP   ¦   s   ÿÿÿzDistroInfo._formatc                    rZ   )z7Get latest stable distribution based on the given date.Nc                    s8   g | ]}|j d urˆ |j kr|jd u sˆ |jkr|‘qS r+   r]   r   rT   r   r   r   º   r^   z%DistroInfo.stable.<locals>.<listcomp>r_   r`   ra   r   rT   r   Ústable¶   rd   zDistroInfo.stablec                 C   s   t ƒ ‚)z@Get list of all supported distributions based on the given date.)ÚNotImplementedError)r"   r   rR   r   r   r   Ú	supportedÃ   s   zDistroInfo.supportedc                 C   s
   || j v S )ú%Check if the given codename is known.)rO   ©r"   r-   r   r   r   ÚvalidÇ   s   
zDistroInfo.validc                    s8   |du rˆj }ˆ |¡‰‡ ‡‡fdd„ˆ |¡D ƒ}|S )zBGet list of all unsupported distributions based on the given date.Nc                    s"   g | ]}|j ˆvrˆ ˆ |¡‘qS r   )r.   rP   r   ©rR   r"   rl   r   r   r   Ð   s   " z*DistroInfo.unsupported.<locals>.<listcomp>)rH   rl   rV   ra   r   rp   r   ÚunsupportedË   s
   
zDistroInfo.unsupported©r-   ©NNr+   ©Nr-   )r%   r&   r'   r(   r    ÚpropertyrO   rS   rV   r-   r,   rc   rP   rj   rl   ro   rq   r   r   r   r   r;   e   s    






r;   c                       sn   e Zd ZdZ‡ fdd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	ddd„Z
ddd„Zdd„ Z‡  ZS )ÚDebianDistroInfoz1provides information about Debian's distributionsc                    r   )NÚDebianr   r!   r#   r   r   r    ×   ó   zDebianDistroInfo.__init__Nc                 C   s`   |dkr|   |¡}|S |dkr|  |¡}|S |dkr!|  |¡}|S |dkr,|  |¡}|S |}|S )z3Map 'unstable', 'testing', etc. to their codenames.ÚunstableÚtestingrj   Ú	oldstable)rc   rz   rj   Úold)r"   r0   r   rX   r-   r   r   r   r-   Ú   s   
	ø
ú
ü
ÿzDebianDistroInfo.codenamer-   c                    óH   ˆ du r| j ‰ ‡ fdd„|  ˆ ¡D ƒ}t|ƒdk rtƒ ‚|  ||d ¡S )r[   Nc                    r\   r+   r]   r   rT   r   r   r   ì   r^   z*DebianDistroInfo.devel.<locals>.<listcomp>r   éþÿÿÿ©rH   rV   r   r   rP   ra   r   rT   r   rc   è   s   
þzDebianDistroInfo.develc                    r}   )z=Get old (stable) Debian distribution based on the given date.Nc                    s$   g | ]}|j d urˆ |j kr|‘qS r+   )r0   r   rT   r   r   r   ù   s   $ z(DebianDistroInfo.old.<locals>.<listcomp>r   r~   r   ra   r   rT   r   r|   õ   s   zDebianDistroInfo.oldc                    ó.   ˆ du rˆj ‰ ‡ ‡‡fdd„ˆ ˆ ¡D ƒ}|S )zOGet list of all supported Debian distributions based on the given
        date.Nc                    s,   g | ]}|j d u sˆ |j krˆ ˆ|¡‘qS r+   )r1   rP   r   ©r   rR   r"   r   r   r     s    &z.DebianDistroInfo.supported.<locals>.<listcomp>©rH   rV   ra   r   r�   r   rl   þ   s   ÿzDebianDistroInfo.supportedc                    r€   )zSGet list of all LTS supported Debian distributions based on the given
        date.Nc                    ó@   g | ]}|j d urˆ |j kr|jd urˆ |jkrˆ ˆ|¡‘qS r+   )r1   r2   rP   r   r�   r   r   r     ó    
ýz2DebianDistroInfo.lts_supported.<locals>.<listcomp>r‚   ra   r   r�   r   Últs_supported  ó   þzDebianDistroInfo.lts_supportedc                    r€   )z\Get list of all Extended LTS supported Debian distributions based on
        the given date.Nc                    rƒ   r+   )r2   r3   rP   r   r�   r   r   r     r„   z3DebianDistroInfo.elts_supported.<locals>.<listcomp>r‚   ra   r   r�   r   Úelts_supported  r†   zDebianDistroInfo.elts_supportedc                    rZ   )z?Get latest testing Debian distribution based on the given date.Nc                    sH   g | ] }|j d u r|js |j d urˆ |j k r|jd u s ˆ |jkr|‘qS r+   )r0   r,   r1   r   rT   r   r   r   &  s    (ýz,DebianDistroInfo.testing.<locals>.<listcomp>r_   r`   ra   r   rT   r   rz   "  s   
þzDebianDistroInfo.testingc                 C   s   t  | |¡p	|dv S )rm   )ry   rz   rj   r{   )r;   ro   rn   r   r   r   ro   0  rW   zDebianDistroInfo.validrs   rt   )r%   r&   r'   r(   r    r-   rc   r|   rl   r…   r‡   rz   ro   r)   r   r   r#   r   rv   Ô   s    



	



rv   c                       sF   e Zd ZdZ‡ fdd„Zddd„Zdd	„ Zdd
d„Zddd„Z‡  Z	S )ÚUbuntuDistroInfoz1provides information about Ubuntu's distributionsc                    r   )NÚUbuntur   r!   r#   r   r   r    =  rx   zUbuntuDistroInfo.__init__Nr-   c                    s<   ˆ du r| j ‰ ‡ fdd„| jD ƒ}|stƒ ‚|  ||d ¡S )zWGet latest long term support (LTS) Ubuntu distribution based on the
        given date.Nc                    s<   g | ]}|j  d ¡dkr|jˆ   kr|jkrn n|‘qS )ÚLTSr   )r,   Úfindr0   r1   r   rT   r   r   r   E  s    6z(UbuntuDistroInfo.lts.<locals>.<listcomp>r_   )rH   rE   r   rP   ra   r   rT   r   Últs@  s   
ÿzUbuntuDistroInfo.ltsc                    s*   ‡ fdd„| j D ƒ}|sdS d|d jv S )zIs codename an LTS release?c                    s   g | ]	}|j ˆ kr|‘qS r   rM   r   rr   r   r   r   N  rU   z+UbuntuDistroInfo.is_lts.<locals>.<listcomp>FrŠ   r   )rE   r,   )r"   r-   rb   r   rr   r   Úis_ltsL  s   zUbuntuDistroInfo.is_ltsc                    r€   )zOGet list of all supported Ubuntu distributions based on the given
        date.Nc                    s6   g | ]}ˆ |j ks|jd urˆ |jkrˆ ˆ|¡‘qS r+   )r1   r5   rP   r   r�   r   r   r   X  s
    
þz.UbuntuDistroInfo.supported.<locals>.<listcomp>r‚   ra   r   r�   r   rl   S  ó   þzUbuntuDistroInfo.supportedc                    r€   )zSGet list of all ESM supported Ubuntu distributions based on the
        given date.Nc                    s,   g | ]}|j d urˆ |j krˆ ˆ|¡‘qS r+   )r4   rP   r   r�   r   r   r   d  s
    
þz2UbuntuDistroInfo.supported_esm.<locals>.<listcomp>r‚   ra   r   r�   r   Úsupported_esm_  rŽ   zUbuntuDistroInfo.supported_esmrt   )
r%   r&   r'   r(   r    rŒ   r�   rl   r�   r)   r   r   r#   r   rˆ   :  s    

rˆ   )r(   rC   r   r>   r   r   Ú	Exceptionr   r*   r:   r;   rv   rˆ   r   r   r   r   Ú<module>   s   
(of