o
    IPa0                     @   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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  ZS )DistroDataOutdatedzDistribution data outdated.c                       t  d d S )NzDistribution 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+   r,   r-   r0   r.   r/   r1   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+   r-   r1   r   r   r   r   r   is_supportedX   s   

zDistroRelease.is_supported)NNNNNNN)r!   r"   r#   r$   r   r3   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   r6   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+   r,   r-   zeol-esmzeol-ltszeol-eltsz
eol-server)_distroospathjoinr   loweropencsvZ
DictReader	_releasesr&   r6   appendr   r   Ztoday_date)r   ZdistrofilenameZcsvfileZ
csv_readerr4   r,   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>r@   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>rE   )r   rI   r   rH   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>rE   r2   r   rK   r   _avail      zDistroInfo._availNc                 C   s   |S )z3Map codename aliases to the codename they describe.r   )r   r,   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)r@   r)   r*   r(   )r   namerO   r,   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'   r,   r-   r   rK   r   r   r          z$DistroInfo.devel.<locals>.<listcomp>rB   rM   r   rG   r   r   rI   distrosr   rK   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 ""r,   zQOnly codename, fullname, object, and release are allowed result values, but not 'z'.)r*   r9   r(   r)   r   )r   format_stringr,   r   r   r   rG      s   zDistroInfo._formatc                    rQ   )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'   rT   r   rK   r   r   r      rU   z%DistroInfo.stable.<locals>.<listcomp>rV   rW   rX   r   rK   r   stable   r[   zDistroInfo.stablec                 C   s   t  )z@Get list of all supported distributions based on the given date.)NotImplementedError)r   r   rI   r   r   r   	supported   s   zDistroInfo.supportedc                 C   s
   || j v S )%Check if the given codename is known.)rF   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*   rG   r   rI   r   rc   r   r   r      s   " z*DistroInfo.unsupported.<locals>.<listcomp>)rB   rc   rM   rX   r   rg   r   unsupported   s
   
zDistroInfo.unsupportedr)   NNr'   Nr)   )r!   r"   r#   r$   r   propertyrF   rJ   rM   r)   r(   rZ   rG   ra   rc   rf   rh   r   r   r   r   r7   e   s    






r7   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   )NZ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testingra   	oldstable)rZ   rp   ra   old)r   r,   r   rO   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 )rR   Nc                    rS   r'   rT   r   rK   r   r   r      rU   z*DebianDistroInfo.devel.<locals>.<listcomp>r   rB   rM   r   r   rG   rX   r   rK   r   rZ      s   
zDebianDistroInfo.develc                    rs   )z=Get old (stable) Debian distribution based on the given date.Nc                    s$   g | ]}|j d ur |j kr|qS r'   )r,   r   rK   r   r   r      s   $ z(DebianDistroInfo.old.<locals>.<listcomp>r   rt   ru   rX   r   rK   r   rr      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'   )r-   rG   r   r   rI   r   r   r   r     s    

z.DebianDistroInfo.supported.<locals>.<listcomp>rB   rM   rX   r   rw   r   rc      s   zDebianDistroInfo.supportedc                    rv   )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'   )r-   r.   rG   r   rw   r   r   r         
z2DebianDistroInfo.lts_supported.<locals>.<listcomp>rx   rX   r   rw   r   lts_supported     zDebianDistroInfo.lts_supportedc                    rv   )z\Get list of all Extended LTS supported Debian distributions based on
        the given date.Nc                    ry   r'   )r.   r/   rG   r   rw   r   r   r     rz   z3DebianDistroInfo.elts_supported.<locals>.<listcomp>rx   rX   r   rw   r   elts_supported  r|   zDebianDistroInfo.elts_supportedc                    rQ   )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'   )r,   r(   r-   r   rK   r   r   r   &  s     z,DebianDistroInfo.testing.<locals>.<listcomp>rV   rW   rX   r   rK   r   rp   "  s   
zDebianDistroInfo.testingc                 C   s   t | |p	|dv S )rd   )ro   rp   ra   rq   )r7   rf   re   r   r   r   rf   0  rN   zDebianDistroInfo.validrj   rk   )r!   r"   r#   r$   r   r)   rZ   rr   rc   r{   r}   rp   rf   r%   r   r   r   r   rm      s    



	



rm   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   )NZUbuntur   r   r   r   r   r   =  rn   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(   findr,   r-   r   rK   r   r   r   E  s    
z(UbuntuDistroInfo.lts.<locals>.<listcomp>rV   )rB   r@   r   rG   rX   r   rK   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   rD   r   ri   r   r   r   N  rL   z+UbuntuDistroInfo.is_lts.<locals>.<listcomp>Fr   r   )r@   r(   )r   r)   rY   r   ri   r   is_ltsL  s   zUbuntuDistroInfo.is_ltsc                    rv   )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'   )r-   r1   rG   r   rw   r   r   r   X  s    
z.UbuntuDistroInfo.supported.<locals>.<listcomp>rx   rX   r   rw   r   rc   S     zUbuntuDistroInfo.supportedc                    rv   )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'   )r0   rG   r   rw   r   r   r   d  s    
z2UbuntuDistroInfo.supported_esm.<locals>.<listcomp>rx   rX   r   rw   r   supported_esm_  r   zUbuntuDistroInfo.supported_esmrk   )
r!   r"   r#   r$   r   r   r   rc   r   r%   r   r   r   r   r~   :  s    

r~   )r$   r?   r   r:   r   r   	Exceptionr   r&   r6   r7   rm   r~   r   r   r   r   <module>   s   
(of