U
    &Ÿˆcœ  ã                   @   sh   d Z ddlmZ zddlmZ W n ek
r4   Y nX ddlZddlZddlm	Z	 G dd„ dej
ƒZ
dS )z"Classes related to cdrom handling.é    )Úprint_function)ÚOptionalN)ÚCdromProgressc                   @   s:   e Zd ZdZddd„Zddd„Zddd	„Zed
d„ ƒZdS )ÚCdroma;  Support for apt-cdrom like features.

    This class has several optional parameters for initialisation, which may
    be used to influence the behaviour of the object:

    The optional parameter `progress` is a CdromProgress() subclass, which will
    ask for the correct cdrom, etc. If not specified or None, a CdromProgress()
    object will be used.

    The optional parameter `mountpoint` may be used to specify an alternative
    mountpoint.

    If the optional parameter `nomount` is True, the cdroms will not be
    mounted. This is the default behaviour.
    NTc                 C   s`   t j | ¡ |d krtƒ | _n|| _|d k	r:t j d|¡ |rNt j dd¡ nt j dd¡ d S )NzAcquire::cdrom::mountzAPT::CDROM::NoMountÚtrueZfalse)Úapt_pkgr   Ú__init__r   Ú	_progressÚconfigÚset)ÚselfÚprogressZ
mountpointZnomount© r   ú+/usr/lib/python3/dist-packages/apt/cdrom.pyr   5   s    
zCdrom.__init__c                 C   s   t j | |p| j¡S )zAdd cdrom to the sources.list.)r   r   Úaddr	   ©r   r   r   r   r   r   E   s    z	Cdrom.addc                 C   s   t j | |p| j¡S )zIdentify the cdrom.)r   r   Úidentr	   r   r   r   r   r   J   s    zCdrom.identc              
   C   s   |   ¡ }|dkrdS t tj d¡d ¡}| tj d¡¡ |D ]J}t|ƒ8}|D ],}| ¡  	d¡sR||krR W 5 Q R £  dS qRW 5 Q R X q@dS )z:Check if the cdrom is already in the current sources.list.NFzDir::Etc::sourcepartsÚ*zDir::Etc::sourcelistú#T)
r   Úglobr   r
   Zfind_dirÚappendZ	find_fileÚopenÚlstripÚ
startswith)r   Zcd_idÚsrcÚfnameZfobjÚliner   r   r   Úin_sources_listO   s    
 zCdrom.in_sources_list)NNT)N)N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úpropertyr   r   r   r   r   r   $   s   


r   )r!   Z
__future__r   Útypingr   ÚImportErrorr   r   Zapt.progress.baser   r   r   r   r   r   Ú<module>   s   