o
    .ee0                     @   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 )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/   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