
    
_d?                         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Zd dlm	Z	 g dZ
ddZddZ G d	 d
e	      Z G d de      Zy)    )convert_path)log)DistutilsOptionErrorN)Command)config_fileedit_configoption_basesetoptc                 \   | dk(  ry| dk(  rKt         j                  j                  t         j                  j                  t        j
                        d      S | dk(  rFt         j                  dk(  xr dxs d}t         j                  j                  t        d	|z              S t        d
|       )zGet the filename of the distutils, local, global, or per-user config

    `kind` must be one of "local", "global", or "user"
    localz	setup.cfgglobalzdistutils.cfguserposix. z~/%spydistutils.cfgz7config_file() type must be 'local', 'global', or 'user')
ospathjoindirname	distutils__file__name
expanduserr   
ValueError)kinddots     ;/usr/lib/python3/dist-packages/setuptools/command/setopt.pyr   r      s    
 wxww||BGGOOI,>,>?QQv~gg (S.Bww!!,/Ds/J"KLL
NPT
UU    c           	      t   t        j                  d|        t        j                         }d |_        |j                  | g       |j                         D ]  \  }}|)t        j                  d||        |j                  |       2|j                  |      s(t        j                  d||        |j                  |       |j                         D ]  \  }}|et        j                  d|||        |j                  ||       |j                  |      rDt        j                  d||        |j                  |       mt        j                  d||||        |j                  |||         t        j                  d	|        |s't        | d
      5 }|j                  |       ddd       yy# 1 sw Y   yxY w)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 %sc                     | S N )xs    r   <lambda>zedit_config.<locals>.<lambda>&   s     r   Nz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   debugconfigparserRawConfigParseroptionxformreaditemsinforemove_sectionhas_sectionadd_sectionremove_optionoptionssetopenwrite)	filenamesettingsdry_runoptssectionr1   optionvaluefs	            r   r   r      s    II-x8'')D"DIIxj$NN, 5?HH4gxH(##G,		97HM  )!( 5=II6R&&w7<<0A7H ++G4II3WfeX HHWfe455. HH\8$(C  	AJJqM	 	 	 	s   F..F7c                   ,    e Zd ZdZg dZddgZd Zd Zy)r	   z<Abstract base class for commands that mess with config files))global-configgz0save options to the site-wide distutils.cfg file)user-configuz7save options to the current user's pydistutils.cfg file)z	filename=r<   z-configuration file to use (default=setup.cfg)r>   r@   c                 .    d | _         d | _        d | _        y r!   )global_configuser_configr5   selfs    r   initialize_optionszoption_base.initialize_optionsS   s    !r   c                 l   g }| j                   r|j                  t        d             | j                  r|j                  t        d             | j                  |j                  | j                         |s|j                  t        d             t        |      dkD  rt        d|      |\  | _        y )Nr   r   r      z/Must specify only one configuration file option)rC   appendr   rD   r5   lenr   )rF   	filenamess     r   finalize_optionszoption_base.finalize_optionsX   s    	[23[01==$T]]+[12y>A&A9  %r   N)__name__
__module____qualname____doc__user_optionsboolean_optionsrG   rM   r"   r   r   r	   r	   E   s%    FL 	O

%r   r	   c                   h    e Zd ZdZdZg dej                  z   Zej                  dgz   Zd Zd Z	d Z
y)	r
   z#Save command-line options to a filez1set an option in setup.cfg or another config file))zcommand=czcommand to set an option for)zoption=ozoption to set)z
set-value=szvalue of the option)removerzremove (unset) the valuerX   c                 f    t         j                  |        d | _        d | _        d | _        d | _        y r!   )r	   rG   commandr:   	set_valuerX   rE   s    r   rG   zsetopt.initialize_optionsw   s,    &&t,r   c                     t         j                  |        | j                  | j                  t	        d      | j
                  | j                  st	        d      y y )Nz%Must specify --command *and* --optionz$Must specify --set-value or --remove)r	   rM   r[   r:   r   r\   rX   rE   s    r   rM   zsetopt.finalize_options~   sS    $$T*<<4;;#6&'NOO>>!$++&'MNN +6!r   c                     t        | j                  | j                  | j                  j	                  dd      | j
                  ii| j                         y )N-_)r   r5   r[   r:   replacer\   r7   rE   s    r   runz
setopt.run   s>    MM\\DKK//S94>>JKLL	
r   N)rN   rO   rP   rQ   descriptionr	   rR   rS   rG   rM   rb   r"   r   r   r
   r
   i   sE    -EK
 	  !L "11XJ>OO
r   r
   )r   )F)distutils.utilr   r   r   distutils.errorsr   r   r'   
setuptoolsr   __all__r   r   r	   r
   r"   r   r   <module>rh      sD    '  1  	  
AV&R!%' !%H!
[ !
r   