
    e.                     z    d Z ddlmZ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 d	d
lmZ  G d de          ZdS )z+
Manage your Anaconda repository channels.
    )print_functionunicode_literalsN)pformat   )errors)format)SimplePackageSpec   )SubCommandBasec                   `    e Zd ZdZd ZddZd Zd ZddZd	 Z	dd
Z
d Zd Zd Zd Zd ZdS )
SubCommandchannelc                 J   | j                             d           | j        j        rw| j        j        }|s0d}| j                             |           t	          j        |          | j                            |           | j                             d|z             d S | j        j        r&| j        	                    | j        j                   d S | j        j
        r|                                  d S | j        j        rU| j        j        D ]F}|                     || j        j        r| j        j        nd | j        j        | j        j                   Gd S | j        j        r=| j        j        D ].}|                     || j        j        | j        j                   /d S | j        j        r-|                     | j        j        | j        j                   d S | j        j        rB|                     | j        j        | j        j        | j        j        | j        j                   d S | j        j        rX| j        j        }d                    | j                                        |          }| j                            |d|           d S | j        j        rX| j        j        }d	                    | j                                        |          }| j                            |d
|           d S | j        j        rX| j        j        }d                    | j                                        |          }| j                            |d|           d S | j        j        rX| j        j        }d                    | j                                        |          }| j                            |d|           d S | j        j         rX| j        j         }d                    | j                                        |          }| j                            |d|           d S tC                      )N z]Channel name not specified. Please use -n or -o to specify your channel.
Use --help for help.zChannel %s successfully created)familyfull_details)r   z{} {} is now lockedprivate)privacysuccess_messagez{} {} is now soft-lockedauthenticatedz{} {} is now unlockedpublicz{} {} is now frozenfrozen)indexing_behaviorr   z{} {} is now unfrozendefault)"loginfoargscreater   RepoCLIErrorapicreate_channelremoveremove_channellistlist_user_channelslist_packagesshow_channel_packagesoffsetlimitr   
list_filesshow_channel_filesr   showshow_channelhistoryshow_channel_historylockr   nametitleupdate_channel	soft_lockunlockfreezeunfreezeNotImplementedError)selfr   msgchannel_namespecs        9lib/python3.11/site-packages/repo_cli/commands/channel.pymainzSubCommand.main   sE   b9 A	(i&G /+  c""")#...H##G,,,HMM;gEFFFFFY 5	(H##DI$455555Y^ 3	(##%%%%%Y$ 1	( $	 7  ** (,	(8BDI$$dIOI*	     Y! )	(	,  ''!1	@V (      Y^ $	(din49;QRRRRRY "	(%%	!	 		&	     Y^ 	(inG'..ty/@/@'JJCH##GYPS#TTTTTY  	(i)G,33DIOO4E4EwOOCH### $      Y 	(i&G)001B1BGLLCH##GXs#SSSSSY 	(i&G'..ty/@/@'JJCH##8S $      Y 	(i(G)001B1BGLLCH##9c $      &'''    Nc                 (    |||||z   nd          }|S N )r9   datar(   r)   filtered_datas        r=   filter_responsezSubCommand.filter_responseY   s%    V9Juv~~PTUVr?   c                    | j                             |||          }|                    dg           }| j                            d           | j                            d|dt          |          d           |r6|D ]}|                     |           | j                            d           d S t          j        | j                  }|                    |||d         dd	
           d S )Nitemsr   zTotal packages matching spec z found: 
)r   total_count)r(   rI   T)packagesmetadatasimple)	r    get_channel_artifactsgetr   r   lenshow_package_detailr   PackagesFormatter)	r9   r;   r(   r)   r   rC   rJ   package	formatters	            r=   r'   z SubCommand.show_channel_packages]   s   x--lFEJJ88GR((b||S]]]],	
 	
 	

  
	# 2 2((1111HMM"0TX>>>I!$*4;NOO      r?   c                 Z   ddd}t          |          }|                    |d                    dg}dD ]H}|                    ||          }|                    |d          }|                    |d|           I| j                            d	                    |                     d S )
N# of downloadsz
# of files)download_count
file_countrK   z---------------)r1   rW   rV   licensedescriptionr   : rH   )dictupdaterN   appendr   r   join)r9   rR   keymappackrespkeylabelvalues           r=   rP   zSubCommand.show_package_details   s    .&
 
 G}}GJ'(((!"U 	3 	3CJJsC((EHHS"%%EKKEEE5512222diioo&&&&&r?   Fc                    | j                             |j        ||j        |j        |j                  \  }}|s| j                            d|z             d S t          j	        }d|d         v rt          j
        }|                     || j        j        | j        j                  }t          |          }| j                            d|d|d           |r|                     |           d S | j                            d           | j                            |                    |                     | j                            d           d S )	N)r   rR   versionfilenamez6No files matches were found for the provided spec: %s
	cve_scorer   zFound z# files matching the specified spec :r   )r    get_channel_artifacts_filesr   rR   rf   rg   r   warningr   PackageFilesFormatterPackageFilesFormatterWithCVErE   r   r(   r)   rO   r   _show_channel_files_full_formatformat_list)r9   r<   r   r   rJ   rI   rS   s          r=   r+   zSubCommand.show_channel_files   sV    $ D DLLL] !E !
 !
+  	HITR   F0	(1+%%;I''$)2BDIOTT(mm@KTTTR	
 	
 	
  	00:::::HMM"HMM)//99:::HMM"r?   c                     |D ]C}| j                             d           | j                             t          |                     Dd S )Nz----------------)r   r   r   )r9   rJ   rR   s      r=   rn   z*SubCommand._show_channel_files_full_format   sO     	, 	,GHMM,---HMM''**++++	, 	,r?   c                     | j                             |          }|r7| j                             |          s| j                             |          |d<   |                     |           d S )Nsubchannels)r    get_channelis_subchannelget_channel_subchannelsshow_channel_detail)r9   r   r   channel_datas       r=   r-   zSubCommand.show_channel   sl    x++G44 	T 6 6w ? ? 	T*.(*J*J7*S*SL'  .....r?   c                     | j                             |||          }| j                            t          j                            |d         |                      | j                            d           d S )NrG   r   )r    get_channel_historyr   r   r   HistoryFormatterro   )r9   r   r(   r)   r   rC   s         r=   r/   zSubCommand.show_channel_history   sl    x++GVUCC#//W<?OPP	
 	
 	
 	br?   c                 R   ddg}ddddd}dD ]I}|                     ||          }|                     |d          }|                    d	|d
|           J	 d                    |                     ddg                    }n# t          $ r d}Y nw xY w|                    d|z             d|v r|                    d           |                    d           |                    d           |                    t          j                                                   |d         d         D ]4}|                    t          j                            |                     5|                    d           | j        	                    d                    |                     d S )NzChannel details:r   rU   z# of artifactsz	# mirrorsz# of subchannels)rV   artifact_countmirror_countsubchannel_count)
r1   rY   r   r|   rV   r}   r~   createdupdatedr   	rZ   z, ownersz	owners: %srr   z	Subchannels:z	------------rG   rH   )
rN   r]   r^   	TypeErrorr   rQ   format_channel_headerformat_channelr   r   )	r9   rC   ra   r_   rb   rc   rd   r   
subchannels	            r=   rv   zSubCommand.show_channel_detail   s   "B'..' 2	
 

 	5 	5C JJsC((EHHS"%%EKKKeeeUU34444	YYtxx2$7788FF 	 	 	FFF	NV+,,,D  KKOOOKK()))KK()))KK0FFHHIII"=1': Q Q
F4CCJOOPPPPBdiioo&&&&&s   *B BBc                 ^    |                      | j                                                   d S rA   )show_list_channelsr    r%   )r9   s    r=   r%   zSubCommand.list_user_channels   s*     ; ; = =>>>>>r?   c                    ddg}dddg d}fd|D             }|                     d                    |                     |d	         D ]6|                     d                    fd
|D                                  7|                     d           | j                            d                    |                     d S )NzChannels available to the user:r   	downloads	artifacts)rV   r|   )r1   r   rY   r|   rV   c                 <    g | ]}                     ||          S rB   )rN   ).0rb   r_   s     r=   
<listcomp>z1SubCommand.show_list_channels.<locals>.<listcomp>   s'    666

3$$666r?   r   rG   c                 V    g | ]%}t                              |d                     &S )r   )strrN   )r   rb   chs     r=   r   z1SubCommand.show_list_channels.<locals>.<listcomp>   s-    "I"I"IC3rvvc2#7#7"I"I"Ir?   rH   )r]   r^   r   r   )r9   rC   ra   cols_colsr   r_   s        @@r=   r   zSubCommand.show_list_channels   s    126$/;OOVVV6666666DIIdOO$$$w- 	L 	LBKK		"I"I"I"I5"I"I"IJJKKKKBdiioo&&&&&r?   c                    |                     | j        d                    | j                  t          j        t
                    }|                    dd d           |                    dddd	
           |                    dddt          d           |                    dddt          d           |                    d          }|                    d| j        	                                d                    | j                             |                    ddd                    | j                             |                    dddd            |                    d!d"d#t          j        d$           |                    d%| j        	                                d&                    | j                             |                    d'| j        	                                d(                    | j                             |                    d)| j        	                                d*                    | j                             |                    d+| j        	                                d,                    | j                             |                    d-| j        	                                d.                    | j                             |                    d/| j        	                                d0                    | j                             |                    d1| j        	                                d2                    | j                             |                    d3| j        	                                d4                    | j                             |                    | j        5           d S )6Nz#Manage your Anaconda repository {}s)helpformatter_classrY   z--familyzArtifact family (i.e.: conda, python, cran, anaconda_project, anaconda_env, notebook). ONLY USED IN COMBINATION WITH --list-files, ignored otherwise.)r   r   z--full-detailszrPrints full file details. ONLY USED IN COMBINATION WITH --list-files, --list-packages or --show ignored otherwise.
store_trueF)r   actionr   z-oz--offsetr   z"Offset when displaying the results)r   typer   z-lz--limit2   z!Limit when displaying the resultsT)requiredz--createzCreate a new {})metavarr   z--listzList all {}s for a user)r   r   z--list-packagesz+Channel written as <channel>[/<subchannel>]CHANNEL+)r   r   nargsz--list-fileszOPackage written as <channel>[/<subchannel>]::<package>[/<version>[/<filename>]]PACKAGE)r   r   r   r   z--showzShow information about the {}z	--historyz#Show historical events about the {}z--lockz	Lock a {}z--soft-lockz<Soft Lock a {}, so that only authenticated users can see it.z--unlockzUnlock a {}z--removezRemove a {}z--freezezFreeze a {}z
--unfreezezUnfreeze a {})r>   )
add_parserr1   r   argparseRawDescriptionHelpFormatter__doc__add_argumentintadd_mutually_exclusive_groupupperr	   from_stringset_defaultsr>   )r9   
subparsers	subparsergroups       r=   r   zSubCommand.add_parser   s   ))I6==diHH$@	 * 
 
	 	M 	 	
 	
 	
 	+ 	 	
 	
 	
 	5 	 	
 	
 	
 	4 	 	
 	
 	
 666EEIOO%%"))$)44	 	 	
 	
 	
 	*11$)<< 	 	
 	
 	

 	>	 	 	
 	
 	
 	b". 	 	
 	
 	
 	IOO%%077	BB 	 	
 	
 	

 	IOO%%6==diHH 	 	
 	
 	

 	dioo//k6H6H6S6S 	 	
 	
 	
 	IOO%%OVV	  	 	
 	
 	
 		 1 18L8LTY8W8W 	 	
 	
 	
 		 1 18L8LTY8W8W 	 	
 	
 	
 		 1 18L8LTY8W8W 	 	
 	
 	
 	IOO%% ''	22 	 	
 	
 	
 	DI.....r?   )NN)F)__name__
__module____qualname__r1   r>   rE   r'   rP   r+   rn   r-   r/   rv   r%   r   r   rB   r?   r=   r   r      s        DC( C( C(J     ,' ' '    >, , ,
/ / / /  (' (' ('T? ? ?' ' '`/ `/ `/ `/ `/r?   r   )r   
__future__r   r   r   pprintr   r   r   utilsr   utils.artifactsr	   baser   r   rB   r?   r=   <module>r      s     8 7 7 7 7 7 7 7                    / / / / / /            / / / / / / / / / /r?   