3
$r\*                 @   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
eZ	dd Z
G dd de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}ndd | j dD }t|dkrD|\}}}tj|||}nRt|dkr|\}}|dkrptj||d}qt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  ZS )DistroDataOutdatedzDistribution data outdated.c                s   t t| j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.)superr   __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               @   s"   e Zd ZdZdddZdd ZdS )DistroReleasez"Represents a distributions releaseNc	       	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S )N)versioncodenameseriescreatedreleaseeol
eol_servereol_esm)	r   r"   r#   r$   r%   r&   r'   r(   r)   r   r   r   r   >   s    zDistroRelease.__init__c             C   s2   || j ko0| jdkp0|| jkp0| jdk	o0|| jkS )z:Check whether this release is supported on the given date.N)r%   r'   r(   )r   r   r   r   r   is_supportedJ   s    zDistroRelease.is_supported)NNNNN)r   r   r   r   r   r*   r   r   r   r   r!   9   s    
r!   c             C   s   || krt | | S d S )N)r   )rowcolumnr   r   r   	_get_dateP   s    r-   c               @   sx   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 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jt |j d }t|}tj|}g | _	xX|D ]P}t
|d |d |d t|dt|dt|dt|dt|d	}| j	j| q<W |j  tjj | _d S )
Nz.csvr"   r#   r$   r%   r&   r'   z
eol-serverzeol-esm)_distroospathjoinr   loweropencsvZ
DictReader	_releasesr!   r-   appendcloser   r   Ztoday_date)r   ZdistrofilenameZcsvfileZ
csv_readerr+   r&   r   r   r   r   Y   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   r   k   s    z"DistroInfo.all.<locals>.<listcomp>)r6   )r   r   r   r   allh   s    zDistroInfo.allr#   c                s    fddj D S )zList all known distributions.c                s   g | ]}j  |qS r   )_format)r   r   )resultr   r   r   r   o   s    z&DistroInfo.get_all.<locals>.<listcomp>)r6   )r   r=   r   )r=   r   r   get_allm   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   r   s   s    z%DistroInfo._avail.<locals>.<listcomp>)r6   )r   r   r   )r   r   _availq   s    zDistroInfo._availNc             C   s   |S )z3Map codename aliases to the codename they describe.r   )r   r&   r   defaultr   r   r   r#   u   s    zDistroInfo.codenamec                s@    dkr| j   fdd| j D }|s0t | j||d S )z<Get latest development distribution based on the given date.Nc                s8   g | ]0}|j d ks0 |j k r|jd ks0 |jkr|qS )N)r&   r'   )r   r   )r   r   r   r   ~   s    z$DistroInfo.devel.<locals>.<listcomp>r   )r9   r?   r   r<   )r   r   r=   distrosr   )r   r   develz   s    zDistroInfo.develc             C   sb   |dkr|S |dkr|j S |dkr@| jd |j d |j d S |dkrN|jS td| d	 d
S )z"Format a given distribution entry.objectr#   fullname z ""r&   zQOnly codename, fullname, object, and release are allowed result values, but not 'z'.N)r$   r/   r"   r#   r   )r   format_stringr&   r   r   r   r<      s    zDistroInfo._formatc                s@    dkr| j   fdd| j D }|s0t | j||d S )z7Get latest stable distribution based on the given date.Nc                s8   g | ]0}|j d k	r |j kr|jd ks0 |jkr|qS )N)r&   r'   )r   r   )r   r   r   r      s    z%DistroInfo.stable.<locals>.<listcomp>r   rA   )r9   r?   r   r<   )r   r   r=   rB   r   )r   r   stable   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   r=   r   r   r   	supported   s    zDistroInfo.supportedc             C   s
   || j kS )z%Check if the given codename is known.)r;   )r   r#   r   r   r   valid   s    zDistroInfo.validc                s8   |dkrj }j| fddj|D }|S )zBGet list of all unsupported distributions based on the given date.Nc                s"   g | ]}|j krj |qS r   )r$   r<   )r   r   )r=   r   rK   r   r   r      s    z*DistroInfo.unsupported.<locals>.<listcomp>)r9   rK   r?   )r   r   r=   rB   r   )r=   r   rK   r   unsupported   s
    
zDistroInfo.unsupported)r#   )NN)Nr#   )Nr#   )NN)Nr#   )r   r   r   r   r   propertyr;   r>   r?   r#   rC   r<   rI   rK   rL   rM   r   r   r   r   r.   T   s   






r.   c                   sZ   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 Z
  ZS )DebianDistroInfoz1provides information about Debian's distributionsc                s   t t| jd d S )NZDebian)r   rO   r   )r   )r   r   r   r      s    zDebianDistroInfo.__init__Nc             C   sX   |dkr| j |}n@|dkr(| j|}n,|dkr<| j|}n|dkrP| j|}n|}|S )z3Map 'unstable', 'testing', etc. to their codenames.unstabletestingrI   	oldstable)rC   rQ   rI   old)r   r&   r   r@   r#   r   r   r   r#      s    zDebianDistroInfo.codenamer#   c                sH    dkr| j   fdd| j D }t|dk r8t | j||d S )z<Get latest development distribution based on the given date.Nc                s8   g | ]0}|j d ks0 |j k r|jd ks0 |jkr|qS )N)r&   r'   )r   r   )r   r   r   r      s    z*DebianDistroInfo.devel.<locals>.<listcomp>r
   )r9   r?   r   r   r<   )r   r   r=   rB   r   )r   r   rC      s    zDebianDistroInfo.develc                sH    dkr| j   fdd| j D }t|dk r8t | j||d S )z=Get old (stable) Debian distribution based on the given date.Nc                s$   g | ]}|j d k	r |j kr|qS )N)r&   )r   r   )r   r   r   r      s    z(DebianDistroInfo.old.<locals>.<listcomp>r
   rT   )r9   r?   r   r   r<   )r   r   r=   rB   r   )r   r   rS      s    zDebianDistroInfo.oldc                s.    dkrj   fddj D }|S )zRGet list of all supported Debian distributions based on the given
           date.Nc                s,   g | ]$}|j d ks |j krj|qS )N)r'   r<   )r   r   )r   r=   r   r   r   r      s    z.DebianDistroInfo.supported.<locals>.<listcomp>)r9   r?   )r   r   r=   rB   r   )r   r=   r   r   rK      s    zDebianDistroInfo.supportedc                s@    dkr| j   fdd| j D }|s0t | j||d S )z?Get latest testing Debian distribution based on the given date.Nc                sH   g | ]@}|j d kr|js@|j d k	r |j k r|jd ks@ |jkr|qS )N)r&   r"   r'   )r   r   )r   r   r   r      s    z,DebianDistroInfo.testing.<locals>.<listcomp>r   rA   )r9   r?   r   r<   )r   r   r=   rB   r   )r   r   rQ      s    zDebianDistroInfo.testingc             C   s   t j| |p|dkS )z%Check if the given codename is known.rP   rQ   rI   rR   )rP   rQ   rI   rR   )r.   rL   )r   r#   r   r   r   rL      s    zDebianDistroInfo.valid)NN)Nr#   )Nr#   )Nr#   )Nr#   )r   r   r   r   r   r#   rC   rS   rK   rQ   rL   r    r   r   )r   r   rO      s   





	
rO   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                s   t t| jd d S )NZUbuntu)r   rU   r   )r   )r   r   r   r      s    zUbuntuDistroInfo.__init__Nr#   c                s<    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                s4   g | ],}|j jd dkr |jkr |jkr|qS )LTSr   )r"   findr&   r'   )r   r   )r   r   r   r      s    z(UbuntuDistroInfo.lts.<locals>.<listcomp>r   rA   )r9   r6   r   r<   )r   r   r=   rB   r   )r   r   lts   s    zUbuntuDistroInfo.ltsc                s*    fdd| j D }|sdS d|d jkS )zIs codename an LTS release?c                s   g | ]}|j  kr|qS r   )r$   )r   r   )r#   r   r   r     s    z+UbuntuDistroInfo.is_lts.<locals>.<listcomp>FrV   r   )r6   r"   )r   r#   rB   r   )r#   r   is_lts  s    zUbuntuDistroInfo.is_ltsc                s.    dkrj   fddj D }|S )zRGet list of all supported Ubuntu distributions based on the given
           date.Nc                s6   g | ].} |j ks&|jd k	r |jkrj|qS )N)r'   r(   r<   )r   r   )r   r=   r   r   r   r     s    
z.UbuntuDistroInfo.supported.<locals>.<listcomp>)r9   r?   )r   r   r=   rB   r   )r   r=   r   r   rK     s    zUbuntuDistroInfo.supportedc                s.    dkrj   fddj D }|S )zVGet list of all ESM supported Ubuntu distributions based on the
           given date.Nc                s,   g | ]$}|j d k	r |j krj|qS )N)r)   r<   )r   r   )r   r=   r   r   r   r     s    z2UbuntuDistroInfo.supported_esm.<locals>.<listcomp>)r9   r?   )r   r   r=   rB   r   )r   r=   r   r   supported_esm  s    zUbuntuDistroInfo.supported_esm)Nr#   )Nr#   )Nr#   )
r   r   r   r   r   rX   rY   rK   rZ   r    r   r   )r   r   rU      s   


rU   )r   r5   r   r0   r   r   	Exceptionr   rD   r!   r-   r.   rO   rU   r   r   r   r   <module>   s   
ZB