
§|jÝ  ã               @   sÈ   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l	 m
 Z
 d d d	 d
 g Z d d d „ Z d d d „ Z Gd d	 „  d	 e
 ƒ Z Gd d
 „  d
 e ƒ Z d S)é    )Úconvert_path)Úlog)ÚDistutilsOptionErrorN)Úconfigparser)ÚCommandÚconfig_fileÚedit_configÚoption_baseÚsetoptÚlocalc             C   s’   |  d k r d S|  d k r> t  j j t  j j t j ƒ d ƒ S|  d k r t  j d k r_ d pb d } t  j j t d	 | ƒ ƒ St	 d
 |  ƒ ‚ d S)z�Get the filename of the distutils, local, global, or per-user config

    `kind` must be one of "local", "global", or "user"
    r   z	setup.cfgÚglobalzdistutils.cfgÚuserÚposixÚ.Ú z~/%spydistutils.cfgz7config_file() type must be 'local', 'global', or 'user'N)
ÚosÚpathÚjoinÚdirnameÚ	distutilsÚ__file__ÚnameÚ
expanduserr   Ú
ValueError)ÚkindÚdot© r   ú?/tmp/pip-build-5c7ija6t/setuptools/setuptools/command/setopt.pyr      s    	Fc       	   	   C   s”  t  j d |  ƒ t j ƒ  } | j |  g ƒ x%| j ƒ  D]\ } } | d k rt t  j d | |  ƒ | j | ƒ q9 | j | ƒ s£ t  j d | |  ƒ | j	 | ƒ xª | j ƒ  D]œ \ } } | d k r t  j d | | |  ƒ | j
 | | ƒ | j | ƒ sLt  j d | |  ƒ | j | ƒ q° t  j d | | | |  ƒ | j | | | ƒ q° Wq9 Wt  j d |  ƒ | s�t |  d	 ƒ � } | j | ƒ Wd QRXd S)
aY  Edit a configuration file to include `settings`

    `settings` is a dictionary of dictionaries or ``None`` values, keyed by
    command/section name.  A ``None`` value means to delete the entire section,
    while a dictionary lists settings to be changed or deleted in that section.
    A setting of ``None`` means to delete that setting.
    zReading configuration from %sNzDeleting section [%s] from %szAdding new section [%s] to %szDeleting %s.%s from %sz#Deleting empty [%s] section from %szSetting %s.%s to %r in %sz
Writing %sÚw)r   Údebugr   ÚRawConfigParserÚreadÚitemsÚinfoÚremove_sectionÚhas_sectionÚadd_sectionÚremove_optionÚoptionsÚsetÚopenÚwrite)	ÚfilenameÚsettingsÚdry_runÚoptsÚsectionr(   ÚoptionÚvalueÚfr   r   r   r   !   s8    	
c               @   sI   e  Z d  Z d Z d d d g Z d d g Z d d „  Z d d „  Z d S)r	   z<Abstract base class for commands that mess with config filesúglobal-configÚgú0save options to the site-wide distutils.cfg fileúuser-configÚuú7save options to the current user's pydistutils.cfg fileú	filename=r3   ú-configuration file to use (default=setup.cfg)c             C   s   d  |  _  d  |  _ d  |  _ d  S)N)Úglobal_configÚuser_configr,   )Úselfr   r   r   Úinitialize_options\   s    		zoption_base.initialize_optionsc             C   s§   g  } |  j  r" | j t d ƒ ƒ |  j r> | j t d ƒ ƒ |  j d  k	 r] | j |  j ƒ | sv | j t d ƒ ƒ t | ƒ d k r— t d | ƒ ‚ | \ |  _ d  S)Nr   r   r   é   z/Must specify only one configuration file option)r<   Úappendr   r=   r,   Úlenr   )r>   Ú	filenamesr   r   r   Úfinalize_optionsa   s    			zoption_base.finalize_optionsN)r4   r5   r6   )r7   r8   r9   )r:   r3   r;   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úuser_optionsÚboolean_optionsr?   rD   r   r   r   r   r	   L   s      	c               @   si   e  Z d  Z d Z d Z d d d d g e j Z e j d g Z d d „  Z d d „  Z	 d d „  Z
 d S)r
   z#Save command-line options to a filez1set an option in setup.cfg or another config fileúcommand=Úcúcommand to set an option forúoption=Úoúoption to setú
set-value=Úsúvalue of the optionÚremoveÚrúremove (unset) the valuec             C   s5   t  j |  ƒ d  |  _ d  |  _ d  |  _ d  |  _ d  S)N)r	   r?   Úcommandr1   Ú	set_valuerT   )r>   r   r   r   r?   �   s
    			zsetopt.initialize_optionsc             C   s`   t  j |  ƒ |  j d  k s+ |  j d  k r7 t d ƒ ‚ |  j d  k r\ |  j r\ t d ƒ ‚ d  S)Nz%Must specify --command *and* --optionz$Must specify --set-value or --remove)r	   rD   rW   r1   r   rX   rT   )r>   r   r   r   rD   ˆ   s
    zsetopt.finalize_optionsc             C   s;   t  |  j |  j |  j j d d ƒ |  j i i |  j ƒ d  S)Nú-Ú_)r   r,   rW   r1   ÚreplacerX   r.   )r>   r   r   r   Úrun�   s    $z
setopt.runN)rK   rL   rM   )rN   rO   rP   )rQ   rR   rS   )rT   rU   rV   )rE   rF   rG   rH   Údescriptionr	   rI   rJ   r?   rD   r\   r   r   r   r   r
   s   s   
)Údistutils.utilr   r   r   Zdistutils.errorsr   r   Zsetuptools.extern.six.movesr   Ú
setuptoolsr   Ú__all__r   r   r	   r
   r   r   r   r   Ú<module>   s   +'