B
    T[                 @   s   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZmZ dd	lmZmZ ed
ZddiZdd Zdd Zdd Zdd ZdS )a  
anaconda-client configuration

Get, Set, Remove or Show the anaconda-client configuration.

###### anaconda-client sites

anaconda-client sites are a mechanism to allow users to quickly switch
between Anaconda repository instances. This is primarily used for testing
the anaconda alpha site. But also has applications for the
on-site [Anaconda Enterprise](http://continuum.io/anaconda-server).

anaconda-client comes with two pre-configured sites `alpha` and
`binstar` you may use these in one of two ways:

  * Invoke the anaconda command with the `-s/--site` option
    e.g. to use the alpha testing site:

        anaconda -s alpha whoami

  * Set a site as the default:

        anaconda config --set default_site alpha
        anaconda whoami

###### Add a anaconda-client site

After installing [Anaconda Enterprise](http://continuum.io/anaconda-server)
you can add a site named **site_name** like this:

    anaconda config --set sites.site_name.url "http://<anaconda-enterprise-ip>:<port>/api"
    anaconda config --set default_site site_name

###### Site Options VS Global Options

All options can be set as global options - affecting all sites,
or site options - affecting only one site

By default options are set globally e.g.:

    anaconda config --set OPTION VALUE

If you want the option to be limited to a single site,
prefix the option with `sites.site_name` e.g.

    anaconda config --set sites.site_name.OPTION VALUE

###### Common anaconda-client configuration options

  * `url`: Set the anaconda api url (default: https://api.anaconda.org)
  * `ssl_verify`: Perform ssl validation on the https requests.
    ssl_verify may be `True`, `False` or a path to a root CA pem file.


###### Toggle auto_register when doing anaconda upload

The default is yes, automatically create a new package when uploading.
If no, then an upload will fail if the package name does not already exist on the server.

    anaconda config --set auto_register yes|no

    )print_functionN)RawDescriptionHelpFormatter)	text_type)ShowHelp)SEARCH_PATHUSER_CONFIGSYSTEM_CONFIGCONFIGURATION_KEYS
get_configsave_configload_configload_file_configs   )	yaml_dump	safe_loadzbinstar.configZ
verify_sslzPlease use ssl_verify insteadc             C   st   x(d|kr(| dd\}}| |i } qW |tkr>td| |t krdd|t| }t| ||| |< d S )N.   z%"%s" is not a known configuration keyz{} is deprecated: {})split
setdefaultr	   loggerZwarning
DEPRECATEDkeysformat)config_datakeyvalueZtype_prefixmessage r   ]lib/python3.7/site-packages/anaconda_client-1.7.2-py3.7.egg/binstar_client/commands/config.pyrecursive_setS   s    

r    c             C   s<   x0d|kr0| sd S | dd\}}| |i } qW | |= d S )Nr   r   )r   get)r   r   r   r   r   r   recursive_removeb   s    
r"   c          	   C   sZ  t  }| jrtt| d S | jr\tt}x*|D ]"}td| tt||  q2W d S | jr| j|kr~t|| j  ntd| j  d S | j	rtdt
  tdt  d S | jrt
nt}t|}x"| jD ]\}}t|||| j qW xB| jD ]8}yt|| W q tk
r0   td|  Y qX qW | jsL| jsLt t|| d S )Nz
==> %s <==zThe value of '%s' is not set.zUser Config: %szSystem Config: %szKey %s does not exist)r
   Zshowr   infor   Zshow_sourcesr   r   r!   filesr   r   userr   setr    typeremover"   KeyErrorerrorr   r   )argsconfigZconfig_filespathZconfig_filer   r   r   r   r   mainl   s>    

r.   c             C   s   d}| j d||ttd}|jdtdd |d}|jdd	d
g ddd |jdddd |jdd
g dd |jddddd |jddddd |jdddd |d}|jd d!dd"d#d$d% |jd&d'd(d)d"d*d+ |jt|d, d S )-NzAnaconda client configurationr,   )helpdescriptionZepilogZformatter_classz--typez*The type of the values in the set commands)defaultr/   Zactionsz--setr   appendzsets a new variable: name value)namer   )nargsactionr1   r/   metavarz--getr3   zget value: name)r6   r/   z--removezremoves a variable)r5   r1   r/   z--show
store_trueFzshow all variablesz-fz--fileszshow the config file names)r5   r/   z--show-sourcesz%Display all identified config sourceslocationz-uz--userr%   Tzset a variable for this user)r5   destr1   r/   z-sz--systemz--siteZstore_falsez,set a variable for all users on this machine)r5   r9   r/   )r.   Z
sub_parser)
add_parser__doc__r   add_argumentr   Zadd_argument_groupZset_defaultsr.   )Z
subparsersr0   parserZagroupZlgroupr   r   r   r:      s6    





r:   )r;   Z
__future__r   Zloggingargparser   Zsixr   Zbinstar_client.errorsr   Zbinstar_client.utils.configr   r   r   r	   r
   r   r   r   Z
utils.yamlr   r   Z	getLoggerr   r   r    r"   r.   r:   r   r   r   r   <module>>   s   (

-