
    e                         d dl Z d dlZd dlmZm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 ddlmZ dd	Zd
 Zd Zd Z G d d          Z G d d          ZdS )    N)ArgumentParserRawDescriptionHelpFormatter)dirname)urlparse   )errors)_setup_loggingconfigfile_or_tokenget_ssl_verify_option)RepoApic                 T    t          | |t                    }t          ||           |S )N)descriptionepilogformatter_class)r   r   add_parser_default_arguments)r   r   versionparsers       6lib/python3.11/site-packages/repo_cli/commands/base.pycreate_parserr      s6    3  F !111M    c           	      D   |                      d          }|                    dddd           |                    dddd	d
           |                    ddd           |                    dddddt          j        t          j                   |                    dddddt          j                   |r|                     dddd|d           |                      d          }|                    d d!t          d"#           |                    d$d%d&'           d S )(Noutputz--disable-ssl-warnings
store_trueFz+Disable SSL warnings (default: %(default)s))actiondefaulthelpz-kz
--insecureinsecurez:Allow to perform "insecure" SSL connections and transfers.)r   destr   z--show-tracebackzGShow the full traceback for chalmers user errors (default: %(default)s))r   r   z-vz	--verbosestore_constz&print debug information on the console	log_level)r   r   r   r   constz-qz--quietz+Only show warnings or errors on the console)r   r   r   r"   z-Vz	--versionr   z&%(prog)s Command line client (version ))r   r   zrepo-client optionsz-tz--tokenzRAuthentication token to use. May be a token or a path to a file containing a token)typer   z-sz--sitez&select the anaconda-client site to user   )add_argument_groupadd_argumentloggingINFODEBUGWARNINGr   )r   r   output_groupbgroups       r   r   r      s   ,,X66L :	     I     V    
 5m     :o      
9DKGGM	 	 	
 	
 	
 &&'<==F
@	     h-UVVVVVr   c                 d    d t          j        t          | j                  g          D             S )Nc                 D    g | ]\  }}}|                     d           |S )_)
startswith).0r0   names      r   
<listcomp>z)get_sub_command_names.<locals>.<listcomp>T   s@       AtQs##  r   )pkgutiliter_modulesr   __file__)modules    r   get_sub_command_namesr9   S   s;     !.0H0H/IJJ   r   c              #      K   t          |           }t          | j        p| j        |          }|D ]4}t	          ||          }t          |d          rt	          |d          V  5d S )N)fromlist
SubCommand)r9   
__import____package____name__getattrhasattr)r8   namesthis_moduler3   subcmd_modules        r   get_sub_commandsrE   [   s      !&))EV/B6?USSSK 7 7T22=,// 	7-666667 7r   c                       e Zd ZdZdZdZdZdZdZ e	j
        d          ZddZd Zed             Zd Zd	 Zd
 Zd Zd ZdS )RepoCommandN z6.1.0repo_clic                    || _         d | _        || _        |pi | _        | j                            d          | _        |                                  | j                            |          | _	        t          | j        | j	        j        | j	        j        | j	        j                   t          j        | j	        j                  | _        | j                            d          | _        | j	        j        pd | _        t+          | j        | j	        j        | j                  | _        | j        s| j                            d           t3          | j        | j        | j                  | _        d S )Nr   )r!   show_tracebackdisable_ssl_warnings)siteurlzSSL verification disabled)base_url
user_token
verify_ssl)_argsauth_manager_commands_modulemetadatagetr   init_parserr   
parse_argsargsr	   logr!   rK   rL   r
   
get_configrM   rN   token_access_tokenr   r   rQ   warningr   api)selfcommands_modulerY   rU   s       r   __init__zRepoCommand.__init__m   sE   
  / B}((33K**400	Hi)93!%!?		
 	
 	
 	
 'TY^<<<;??5))!Y_4/K+TX
 
  	:H8999X$*<
 
 
r   c                    |                                   	 	 t          | j        d          s| j                            d           | j                                        S # t          j        $ r | j        j        r)| j	        
                    d           t          d          | j	        
                    d           | j                                        | _        | j                                        cY S w xY w# t          j        $ r8 | j        j                                         t$          rt          d          Y dS w xY w)NmainzWA sub command must be given. To show all available sub commands, run:

	 conda repo -h
z?The provided token does not allow you to perform this operation   zFThe action you are performing requires authentication, please sign in:)check_tokenrA   rY   r   errorrd   r   Unauthorizedr\   rZ   info
SystemExitrS   loginr]   ShowHelp
sub_parser
print_helpexitr`   s    r   runzRepoCommand.run   sX   	,ty&11 K%%Y   y~~'''& , , ,9? ,HMMY   %Q--'HMM*   *.):)@)@)B)BD&9>>+++++,  	 	 	I ++---  mm#qq	s,   AA BC74C: 6C77C: :AE Ec                     | j         j        S N)rY   rM   rp   s    r   rM   zRepoCommand.site   s    y~r   c                 r    | j         s*t          j        | j                  x| j        _         | _         | j         S rs   )r]   r
   
load_tokenrM   r_   rp   s    r   rf   zRepoCommand.check_token   s6    ! 	W:@:KDI:V:VVDH"T%7!!r   c                     d S rs    rp   s    r   init_configzRepoCommand.init_config   s    r   c                 x    t          | j        | j        | j                  | _        |                                  d S rs   )r   r   r   r   r   add_parser_subcommandsrp   s    r   rW   zRepoCommand.init_parser   s4    #D$4dk4<PP##%%%%%r   c                     i | _         | j                            d          | _        t	          | j                  D ]}|                     |           d S )Nzsub-command helpr%   )_sub_commandsr   add_subparsers
subparsersrE   rT   register_sub_command)r`   sub_cmds     r   rz   z"RepoCommand.add_parser_subcommands   s`    +44:L4MM'(=>> 	/ 	/G%%g....	/ 	/r   c                      ||           }|| j         |j        <   |                    | j                   |j        r	|| _        d S d S rs   )r|   r3   
add_parserr~   manages_authrS   )r`   sub_commandr   s      r   r   z RepoCommand.register_sub_command   sY    +d##+27<(4?+++ 	( 'D	( 	(r   rs   )r?   
__module____qualname__r   r   r   r   min_api_versionmax_api_versionr(   	getLoggerrZ   rb   rq   propertyrM   rf   rx   rW   rz   r   rw   r   r   rG   rG   d   s        FKFGOO
'
J
'
'C
 
 
 
<  @   X" " "  & & &/ / /( ( ( ( (r   rG   c                       e Zd ZdZd Zed             Zed             Zed             Zed             Z	ed             Z
dS )	SubCommandBaseFc                     || _         d S rs   )parent)r`   r   s     r   rb   zSubCommandBase.__init__   s    r   c                     | j         j        S rs   )r   rY   rp   s    r   rY   zSubCommandBase.args   s    {r   c                     | j         j        S rs   )r   r_   rp   s    r   r_   zSubCommandBase.api       {r   c                     | j         j        S rs   )r   rZ   rp   s    r   rZ   zSubCommandBase.log   r   r   c                     | j         j        S rs   )r   r]   rp   s    r   access_tokenzSubCommandBase.access_token   s    {((r   c                     | j         j        S rs   )r   rQ   rp   s    r   rQ   zSubCommandBase.verify_ssl   s    {%%r   N)r?   r   r   r   rb   r   rY   r_   rZ   r   rQ   rw   r   r   r   r      s        L       X    X   X ) ) X) & & X& & &r   r   )NNN)r(   r5   argparser   r   os.pathr   six.moves.urllib.parser   rH   r   utilsr	   r
   r   r   	utils.apir   r   r   r9   rE   rG   r   rw   r   r   <module>r      sC     @ @ @ @ @ @ @ @       + + + + + +       P P P P P P P P P P P P         6W 6W 6Wv  7 7 7d( d( d( d( d( d( d( d(N& & & & & & & & & &r   