
    e                          d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
 ddlmZ ddlmZ d Z G d d	e          ZdS )
z(
Configure Conda to use Anaconda Server
    N)abspathexists
expanduserjoin)urljoin   )SubCommandBasec                      t          j        dd                                          } t          j        |                               dd          S )Nzconda config --show --jsonT)shellroot_prefix )
subprocesscheck_outputdecodejsonloadsget)outputs    8lib/python3.11/site-packages/repo_cli/commands/wizard.pyr   r      sD    $%ANNNUUWWF:f!!-444    c                   r   e Zd ZdZ e ed                    Ze                    dd          Z e e	 e
            d                                        dd          Z e e	 ej        d          d                                        dd          Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )
SubCommandwizardz
~/.condarc%z%%z.condarcCONDA_PREFIXc                 	   | j         j        rd| _        | j        | _        ne| j         j        r&d| j         j        z  | _        | j         j        | _        n3| j         j        rd| _        | j        | _        nd| _        | j        | _        | j        dz   | _	        | j         j
        r|                                  d S | j                            d           | j                            d| j        j                            d                      | j                            d           | j                            d	| j                    | j                            d           |                                 }| j                            d
           |                                 }|                                 }t)          dddddd           t)          d           |D ]@}t)          |d         dd|d         ddd                    |d                               A|D ]@}t)          |d         dd|d         ddd                    |d                               A|                     |          }| j                            d           | j                            d           t/          d          }g }|r&|                                                                }| j                            d           | j                            dt3          | j        j        d                      | j                            d           |D ]}| j                            d|             | j                            d            | j                            d!           |r"|D ]}| j                            d|             | j                            d"| j                    t/          d#          }|                                d$k    s|s|                                  |                     d%d&t3          | j        j        d                     |                     d'd(           |D ]}|                     d)d(|           |                     d'd*           |                     d)d*d+           |D ]}|                     d,d*|           d S d S )-N--systemz	--file %s--envr   z.backupzConda configuration wizard.zAThis wizard will configure your CondaRC file using channels from z/apizThe CondaRC path is z%The following channels are available:Namez<30sz | Mirror | Privacy15sz	 | OwnerszK---------------------------------------------------------------------------nameu    |  ︎ ✔    | privacyz |  ownersu    |  ︎      | zlIf you wish to add channels to the "channels" list
provide a space-separated list. You may leave this blank.: z1The following Conda configuration will be appliedzchannel_alias: z	/api/repozdefault_channels:  - z	channels:z  - defaultszConfirm changes to z4(The current condarc file will be archived) [Y, n]: yz--setchannel_aliasz--remove-keydefault_channelsz	--prependchannelsdefaultsz--append)argssystemcondarc_argsescaped_sys_rc_pathcondarcfileenvescaped_env_rc_pathescaped_user_rc_pathcondarc_backuprestorerestore_condarcloginfoapibase_urlstripget_all_channelsget_mirror_channelsget_non_mirror_channelsprintr   get_default_channelsinputsplitr   lowerbackup_condarcconda_config)	selfall_channelsmirror_channelsnon_mirror_channelschannelr*   valuer+   cs	            r   mainzSubCommand.main   s   9 	5 *D3DLLY^ 	5 +din <D9>DLLY] 	5 'D3DLL "D4DL"lY69 	  """F3444?!X.44V<<? ?	
 	
 	
 	b;T\;;<<<b,,..=>>>2244"::<<BBB)BBBBCCCh& 	 	G6?rrr'):LrrrUXU]U]^efn^oUpUprr    + 	 	G6?ppp	8JpppSVS[S[\cdl\mSnSnpp     44\BBbH	
 	
 	
 d 	-{{}}**,,HIJJJQ0A;(O(OQQRRR)***! 	& 	&AHMM***%%%%k"""n%%% 	* * *jQjj)))):DL::;;;LMMKKMMS  % !!!'$(2C[*Q*Q   n.@AAA% F F!!+/A1EEEEnj999k:zBBB = =!!*j!<<<< ! = =r   c                     t          | j                  rC| j                            d| j                    t          j        | j        | j                   d S d S )Nz(Backing up your current condarc file to )r   r1   r9   r:   r6   shutilcopyrH   s    r   rF   zSubCommand.backup_condarcu   sc    $, 	;HMMP4;NPP   Kd&9:::::		; 	;r   c                 .   t          | j                  rC| j                            d| j                    t	          j        | j        | j                   d S | j                            d| j         d           | j                            d           d S )Nz!Restoring your condarc file from zNo backup file z was found.zThere is nothing to do.)r   r6   r9   r:   rQ   rR   r1   rS   s    r   r8   zSubCommand.restore_condarc|   s    $%&& 	5HMMSd>QSSTTTK+T\:::::HMMLD,?LLLMMMHMM344444r   c                    dd| j         g|}	 t          j        d                    |          dt          j                   d S # t          j        $ r,}d|j                                        v rY d }~d S Y d }~d S d }~ww xY w)Ncondaconfigr$   T)r   stderrCondaKeyError)r/   r   r   r   PIPECalledProcessErrorrX   r   )rH   r-   cmdes       r   rG   zSubCommand.conda_config   s    $"3;d;	#CHHSMMjoVVVVVV, 	 	 	!(//"3"333 433333	s   4A A?A::A?c                 @    | j                                         d         S )Nitems)r;   list_channelsrS   s    r   r>   zSubCommand.get_all_channels   s    x%%''00r   c                 B    |                                  }d |D             S )Nc                 *    g | ]}|d          dk    |S mirror_countr    .0rN   s     r   
<listcomp>z2SubCommand.get_mirror_channels.<locals>.<listcomp>   s'    ===aq'81'<'<'<'<'<r   r>   rH   r+   s     r   r?   zSubCommand.get_mirror_channels   s'    ((**==8====r   c                 B    |                                  }d |D             S )Nc                 *    g | ]}|d          dk    |S rc   re   rf   s     r   rh   z6SubCommand.get_non_mirror_channels.<locals>.<listcomp>   s'    >>>aq'8A'='='='='=r   ri   rj   s     r   r@   z"SubCommand.get_non_mirror_channels   s'    ((**>>8>>>>r   c                    |                     | j        dt          j        t                    }|                    dd| j        z            }|                                }|                    ddd| j	        z             |                    d	dd
| j
        z             |                    ddd           |                    ddd           |                    | j                   d S )Nz&Configure Conda to use Anaconda Server)helpformatter_classdescriptionzConfig File Location SelectionzAWithout one of these flags, the user config file at '%s' is used.r   
store_truez*Write to the system .condarc file at '%s'.)actionrn   r   z:Write to the active conda environment .condarc file (%s). z--filestorezWrite to the given file.z	--restorezRestore condarc from backup.)rn   rr   )rO   )
add_parserr"   argparseRawDescriptionHelpFormatter__doc__add_argument_groupr5   add_mutually_exclusive_groupadd_argumentr0   r4   set_defaultsrO   )rH   
subparsers	subparserconfig_file_location_grouplocations        r   rt   zSubCommand.add_parser   s3   ))I9$@	 * 
 
	 &/%A%A,S+,&
 &
" .JJLL=&' 	 	
 	
 	
 	*, 	 	
 	
 	
 	hw=WXXX<\ 	 	
 	
 	
 	DI.....r   c                 x   |                                                                 }d |D             }g }g }|D ]1}||v r|                    |           |                    |           2t          |          dk    r<| j                            d           |D ]}| j                            d|             |S )Nc                     g | ]
}|d          S )r"   re   rf   s     r   rh   z-SubCommand.purge_channels.<locals>.<listcomp>   s    >>>Aai>>>r   r   z:The following channels do not exist and will not be saved:r'   )r=   rD   appendlenr9   warning)rH   input_valuerI   channel_listall_channels_namesvalid_channelsinvalid_channelsrN   s           r   purge_channelszSubCommand.purge_channels   s    "((**0022>>>>> 	+ 	+A&&&%%a(((( ''****  1$$HL   & - -  ,,,,r   c                    	 | j                             d           | j                             d           t          d          }|                     ||          }t	          |          dk    rn| j                             d           |S )NTr   zoProvide a space-separated list of channels to set as default_channels
It is common to add mirror channels here.r&   r   zFAt least one channel should be added to default channels! Try again...)r9   r:   rC   r   r   r   )rH   rI   rM   r*   s       r   rB   zSubCommand.get_default_channels   s    	HMM"HMM<  
 $KKE#225,GG#$$q((  \  	"  r   N)__name__
__module____qualname__r"   r   r   user_rc_pathreplacer5   r   r   r0   osgetenvr4   rO   rF   r8   rG   r>   r?   r@   rt   r   rB   re   r   r   r   r      sS       D7::l3344L'//T::!'$${{}}j"A"ABBJJ3PTUU!'$$yry'@'@*"M"MNNVVT 
T= T= T=l; ; ;5 5 5  1 1 1> > >? ? ?!/ !/ !/F  *         r   r   )rw   ru   r   r   rQ   r   os.pathr   r   r   r   urllib.parser   baser	   r   r   re   r   r   <module>r      s       				      5 5 5 5 5 5 5 5 5 5 5 5                        5 5 5
L  L  L  L  L  L  L  L  L  L r   