3 l]�j��@s�ddlmZddlmZddlmZddlZddlZddlmZddl m Z ddd d gZ dd d�Z ddd�Z Gdd �d e �ZGdd �d e�ZdS)�)� convert_path)�log)�DistutilsOptionErrorN)� configparser)�Command� config_file� edit_config� option_base�setopt�localcCsh|dkr dS|dkr,tjjtjjtj�d�S|dkrZtjdkrBdpDd}tjjtd |��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)Zkind�dot�r�/usr/lib/python3.6/setopt.pyrsFc Cs.tjd|�tj�}|j|g�x�|j�D]�\}}|dkrTtjd||�|j|�q*|j|�svtjd||�|j |�x||j�D]p\}}|dkr�tjd|||�|j ||�|j |�s�tjd||�|j|�q�tjd||||�|j |||�q�Wq*Wtjd|�|�s*t |d ��}|j|�WdQRXdS) aYEdit 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. zReading configuration from %sNzDeleting section [%s] from %szAdding new section [%s] to %szDeleting %s.%s from %sz#Deleting empty [%s] section from %szSetting %s.%s to %r in %sz Writing %s�w)r�debugrZRawConfigParser�read�items�infoZremove_sectionZ has_sectionZ add_sectionZ remove_option�options�set�open�write) �filenameZsettings�dry_runZoptsZsectionr"�option�value�frrrr!s8            c@s2eZdZdZdddgZddgZd d �Zd d�ZdS)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=r*�-configuration file to use (default=setup.cfg)cCsd|_d|_d|_dS)N)� global_config� user_configr&)�selfrrr�initialize_options\szoption_base.initialize_optionscCsvg}|jr|jtd��|jr,|jtd��|jdk rB|j|j�|sT|jtd��t|�dkrjtd|��|\|_dS)Nr r r �z/Must specify only one configuration file option)r3�appendrr4r&�lenr)r5� filenamesrrr�finalize_optionsas   zoption_base.finalize_optionsN)r+r,r-)r.r/r0)r1r*r2)�__name__� __module__� __qualname__�__doc__� user_options�boolean_optionsr6r;rrrrr Lsc@sJeZdZdZdZddddgejZejd gZdd�Zdd�Z dd�Z dS)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 valuecCs&tj|�d|_d|_d|_d|_dS)N)r r6�commandr(� set_valuerK)r5rrrr6�s  zsetopt.initialize_optionscCsDtj|�|jdks|jdkr&td��|jdkr@|j r@td��dS)Nz%Must specify --command *and* --optionz$Must specify --set-value or --remove)r r;rNr(rrOrK)r5rrrr;�s  zsetopt.finalize_optionscCs*t|j|j|jjdd�|jii|j�dS)N�-�_)rr&rNr(�replacerOr')r5rrr�run�sz setopt.runN)rBrCrD)rErFrG)rHrIrJ)rKrLrM) r<r=r>r?� descriptionr r@rAr6r;rSrrrrr ss )r )F)Zdistutils.utilrrrZdistutils.errorsrrZsetuptools.extern.six.movesrZ setuptoolsr�__all__rrr r rrrr�<module>s        +'