
    e&                         d Z ddlmZ ddlZddlmZ ddlmZ ddl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 dd
lmZmZ ddlmZ i Z G d de          ZdS )a	  
`conda repo` configuration

Get, Set, Remove or Show the `conda repo` configuration.

###### Add a `conda repo` site

You can add a site like this:

    conda repo config --set-site "url.of.new_site.com"

    The site will be available under the site name `new_site.com`

You can add a site named **site_name** like this:

    conda repo config --set sites.site_name.url "http://url_of_new_site/api"
    conda repo config --set default_site site_name

    The site will be available under the site name `site_name`.
    Notice that the url explicitly has the `/api` suffix and http / https needs to be specified.

###### `conda repo` sites

`conda repo` sites are a mechanism to allow users to quickly switch
between Anaconda repository instances, from anaconda.org to on-site
[Anaconda Repo](https://server-docs.anaconda.com/en/latest/) installations.

`conda repo` comes one two pre-configured site: `anaconda`. If you
have configured more than one site, you can operate between them
in 2 ways:

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

        conda repo -s mysite whoami

  * Set a site as the default:

        conda repo config --set default_site mysite
        conda repo whoami

  * Show sources:
        conda repo config --show-sources

###### 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.:

    conda repo 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.

    conda repo config --set sites.site_name.OPTION VALUE

###### Common `conda repo` configuration options

  * `url`: Set the conda repo 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.


###### Other `conda repo` configuration options
  * `auto_register`: Toggle auto_register when doing conda repo upload
  * 'default_site': Default site set to be used by default
  * 'sites': Sites namespace that can be used to add new sites (for
    more information, check the dedicated section above.


###### Toggle auto_register when doing conda repo 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.

    conda repo config --set auto_register yes|no

    )print_functionN)RawDescriptionHelpFormatter)urlparse   )errors)CONFIGURATION_KEYSSEARCH_PATHSYSTEM_CONFIGUSER_CONFIG
get_configload_configload_file_configssave_config)	check_urlcheck_url_exists)	safe_load	yaml_dump   )SubCommandBasec                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )

SubCommandconfigc                    t                      }| j        j        r)| j                            t          |                     d S | j        j        rct          t                    }|D ]J}| j                            d|           | j                            t          ||                              Kd S | j        j	        rb| j        j	        |v r+| j                            || j        j	                            n'| j                            d| j        j	        z             d S | j        j
        riddlm} | j                            d|           | j                            dt          z             | j                            dt          z             d S | j        j        rt          nt          }t!          |          }t!          t                    }| j        j        D ]l\  }}|                     ||           | j        j        r#|                     |||| j        j                   J|                     |||| j        j                   m| j        j        D ]F}	 |                     ||           # t.          $ r  | j                            d|z             Y Cw xY w| j        j        D ];}	| j        j        r|                     ||	           %|                     ||	           <| j        j        s+| j        j        s| j        j        st5          j                    | j        j        rt9          ||           d S t9          |t                     d S )	Nz
==> %s <==zThe value of '%s' is not set.r   )
CONDA_ROOTzConda_root: zUser Config: %szSystem Config: %szKey %s does not exist)r   argsshowloginfor   show_sourcesr   r	   getfilesutils.configr   r   r
   userr   set_validate_url_keyrecursive_settyperemoverecursive_removeKeyErrorerrorset_siter   ShowHelpr   )
selfr   config_filespathr   config_fileconfig_systemkeyvaluesites
             8lib/python3.11/site-packages/repo_cli/commands/config.pymainzSubCommand.maino   sA   9> 	HMM)F++,,,F9! 	,[99L$ = =lD111iT(:;;<<<<F9= 	y}&&fTY]34444=	MNNNF9? 	111111HMMMjj:;;;HMM+k9:::HMM-=>>>F%)Y^Fkk[))#M22)- 	N 	NJC""3...y~ N""63ty~FFFF""=#udinMMMM9# 	> 	>C>%%fc2222 > > >6<=====> I& 	3 	3Dy~ 3fd++++mT2222	 	$!1 	$TY5G 	$/###9> 	6,,,,,}55555s   I22'JJc                     d|v r7|sd S |                     dd          \  }}|                    |i           }d|v 7||= d S )N.r   )splitr    )r.   config_datar3   prefixs       r6   r)   zSubCommand.recursive_remove   s]    Sjj ))C++KFC%//&"55K	 Sjj     c                    d|v r3|                     dd          \  }}|                    |i           }d|v 3|t          vr| j                            d|           |t
                                          v r;d                    |t
          |                   }| j                            |            ||          ||<   d S )Nr9   r   z%"%s" is not a known configuration keyz{} is deprecated: {})r:   
setdefaultr   r   warning
DEPRECATEDkeysformat)r.   r;   r3   r4   type_r<   messages          r6   r&   zSubCommand.recursive_set   s    Sjj))C++KFC%00<<K Sjj (((HDcJJJ*//####,33CCIIGHW%%% 5<<Cr=   c                 R    |                     d          rt          |           d S d S )Nz.url)endswithr   )r.   r3   r4   s      r6   r%   zSubCommand._validate_url_key   s4    << 	u	 	r=   c                 j   |                     d          sLt          d|z             rd|z   }n4t          d|z             rd|z   }n| j                            d           d S |                    d          s|                    d          dz   }t          |           t          j        |dz             }|j	        dk    r	 |
                                }|                    d	          d
k    r| j                            d|z             d S n8# t          j        j        $ r! | j                            d|z             Y d S w xY w|                     |          }d|vri |d<   d|i|d         |<   ||d<   | j                            d|d|d           d S | j                            d           d S )Nhttpzhttps://zhttp://zURL is not validz/api/z/system   service_namerepozNo Anaconda Server found at %ssitesurldefault_sitezSite z
 added as z to configuration)
startswithr   r   r+   rG   rstripr   requestsr    status_codejsondecoderJSONDecodeErrorextract_domainr   )r.   r;   rO   response	json_datadomain_names         r6   r,   zSubCommand.set_site   s   ~~f%% 	
S 011  3&!)c/22 #o1222||F## 	+**S//F*C#<i003&&$MMOO	
 ==00F::HNN#Cc#IJJJF ;	 </   ?#EFFF --c22Kk))')G$16K -*5K'HMMMCCCUVVVVVHNN-.....s   D 1EEc                     t          |          }|j        p|j        }|                    d          }t	          |          dk    rd                    |dd                    S |S )Nr9   r   )r   netlocr0   r:   lenjoin)r.   rO   parsed_domaindomaindomain_partss        r6   rX   zSubCommand.extract_domain   sa     %;);||C((|q  88L-...r=   c           	         d}|                     d||t          t                    }|                    dt          d           |                    d          }|                    dd	d
g dd           |                    ddd           |                    dd
g d           |                    dddd           |                    dddd           |                    ddd           |                    dd d!g d"#           |                    d$          }|                    d%d&dd'd(d)*           |                    d+d,d-d.d'dd/*           |                    | j        |0           d S )1Nz"Anaconda Repo Client Configurationr   )helpdescriptionepilogformatter_classz--typezThe type of the values in the set commands. NOTE: Thisargument is only used when combined with the `--set`command and is ignored otherwise.)defaultre   actionsz--setr   appendzsets a new variable: name value)namer4   )nargsactionri   re   metavarz--getrl   zget value: name)ro   re   z--removezremoves a variable)rn   ri   re   z--show
store_trueFzshow all variablesz-fz--fileszshow the config file names)rn   re   z--show-sourcesz%Display all identified config sourcesz
--set-siter   storez:sets a new site and sets the default_site to this new site)rm   rn   ri   re   locationz-uz--userr#   Tzset a variable for this user)rn   destri   re   z-sz--systemz--sitestore_falsez,set a variable for all users on this machine)r7   
sub_parser)
add_parser__doc__r   add_argumentr   add_argument_groupset_defaultsr7   )r.   
subparsersrf   parseragrouplgroups         r6   rv   zSubCommand.add_parser   s&   :&&#7 ' 
 
 	0 	 	
 	
 	
 **9552% 	 	
 	
 	
 	GV:KLLLx:N 	 	
 	
 	
 	\5?S 	 	
 	
 	
 	)L7S 	 	
 	
 	
 	8 	 	
 	
 	

 	M 	 	
 	
 	
 **:66/ 	 	
 	
 	
 	 ? 	 	
 	
 	
 	v>>>>>r=   N)__name__
__module____qualname__rl   r7   r)   r&   r%   r,   rX   rv    r=   r6   r   r   k   s        D<6 <6 <6|  ( ( (  %/ %/ %/N  F? F? F? F? F?r=   r   )rw   
__future__r   rU   argparser   urllib.parser   rS    r   r"   r   r	   r
   r   r   r   r   r   utils.validatorsr   r   
utils.yamlr   r   baser   rA   r   r   r=   r6   <module>r      sY  O O` & % % % % %  0 0 0 0 0 0 ! ! ! ! ! !       	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ; : : : : : : : - - - - - - - -            
R? R? R? R? R? R? R? R? R? R?r=   