
    edL                         d Z ddlmZmZ ddlZddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZmZmZmZ dd	lmZ d
Zddddddddddd
Z G d de          ZdS )z+
Manage your Anaconda repository channels.
    )print_functionunicode_literalsN   )errors)AllMirrorFormatterMirrorFormatterSyncStateFormattercomma_string_to_liststring_to_bool)check_cve_scorecheck_date_formatcheck_proxy_url	check_url   )SubCommandBasez	0 0 * * *	mirror_idmirror_namesource_rootmirror_modemirror_typecronproxylast_run_at
created_at
updated_at)
idnamesourcemodetyper   r   r   r   r   c                   t    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZddZd Zd ZdS )
SubCommandmirrorc                    | j         }|j        s|j        s|j        r7|j        s0d}| j                            |           t          j        |          |j        r| 	                    |j        |j
        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j                   d S |j        r|                     |j        |j
        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        |j                   d S |j        r"|                     |j        |j                   d S |j        r|                     |j                   d S |j        r|                                   d S |j!        r| !                    |j!                   d S |j"        r"| "                    |j"        |j                   d S |j#        r| #                    |j#                   d S |j$        r| $                    |j$                   d S tK                      )NzdChannel name not specified. Please use -c or --channel to specify your channel.
Use --help for help.)&argscreateupdatedeletechannelloginfor   RepoCLIErrorcreate_mirrorr   r   r    licensessubdirsprojects	only_specexclude_specinclude_spec	cve_scoreexclude_uncurated_cve_packagesonly_signed	date_fromdate_tor   run_nowr   update_mirrorr   list	show_listlist_allshow_all_list
sync_stateshowstoprestartNotImplementedError)selfr%   msgs      8lib/python3.11/site-packages/repo_cli/commands/mirror.pymainzSubCommand.main,   s   yK 	+4; 	+$+ 	+t| 	+'  HMM#%c***; <	(		!!3 	
'    * [ &	(			!!3 	
)    , [ 	(KKdk22222Y 	(NN49%%%%%] 	(     _ 		(OODO,,,,,Y 	(IIdi.....Y 	(IIdi     \ 	(LL&&&&&%'''    c                    |                      ||          }|r| j                            d|           d S i }|rt          |          |d<   |rt          |          |d<   |ryg |d<   g |d<   t          |          D ]_}d}|                    d          rd}|dd          }|                    d          r
|dd          }||                             |           `|	r|	|d	<   |
r|
|d
<   |r||d<   |r||d<   |r||d<   |||d<   |r||d<   |r||d<   |                     |           | j                            |||||||||	  	         | j                            d||           d S )Nz)Mirror with the name '%s' already exists.r/   r0   include_licensesexclude_licenses-r   +
only_specsexclude_specsinclude_specsr7   r8   cve_score_thresholdexclude_non_curated_cver6   z,Mirror %s successfully created on channel %s)	_get_by_namer*   r+   r
   
startswithappendvalidate_mirror_filtersapir-   )rD   r)   r   r   r   type_filter_licensesfilter_subdirsfilter_projectsfilter_only_specsfilter_exclude_specsfilter_include_specsr4   exclude_uncurrated_cve_packagesfilter_only_signedfilter_date_fromfilter_date_tor   r9   r   r#   filterslicensegroups                           rF   r-   zSubCommand.create_mirrort   s   , ""411 	HMMEtLLLF 	F!5n!E!EGI 	H"6"G"GGJ 
	/*,G&'*,G&'/@@ / /*%%c** *.E%abbkG%%c** *%abbkG%%g.... 	6$5GL! 	<';GO$ 	<';GO$ 	4#3GK  	0!/GI -6G)** 	Q1PG-. 	8%7GM"$$W---VT4%w	
 	
 	
 	DdGTTTTTrH   c                    |                      ||          }|s| j                            d           d S |d         }|t          |          |d<   |	t          |	          |d<   |yg |d<   g |d<   t          |          D ]_}d}|                    d          rd}|dd          }|                    d	          r
|dd          }||                             |           `|
|
|d
<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |                     |           |r||d<   |r||d<   |	|r|nd |d<   ||t          k    r||d<   | j        	                    |d         ||d         |d         |d         ||d         |d         ||d         
  
         | j                            d||           d S )NMirror not foundrc   r/   r0   rJ   rK   rL   r   rM   rN   rO   rP   r7   r8   rQ   rR   r6   r   r   r   r   r   r   r   z+Mirror %s successfully update on channel %s)
rS   r*   r+   r
   rT   rU   rV   DEFAULT_MIRROR_CRONrW   r:   )rD   r)   r   r   new_namer   rX   rY   rZ   r[   r\   r]   r^   r4   r_   r`   ra   rb   r   r9   r   r#   rc   rd   re   s                            rF   r:   zSubCommand.update_mirror   sy   . ""411 	HMM,---F#%!5n!E!EGI&"6"G"GGJ&*,G&'*,G&'/@@ / /*%%c** *.E%abbkG%%c** *%abbkG%%g....($5GL!+';GO$+';GO$'#3GK %!/GI -6G)**61PG-.)%7GM"$$W--- 	+$*F=! 	-$,F=!',6ee$F7O(; ; ;!F6N;=!=!=!=!6N7O	
 	
 	
 	CT7SSSSSrH   c                     |                     d          r>|                     d          s|                     d          rt          j        d          d S d S )NrN   rO   rP   z=Can't combine only_specs with exclude_specs and include_specs)getr   r,   )rD   rc   s     rF   rV   z"SubCommand.validate_mirror_filters  sl    ;;|$$ 	KK((	,3KK,H,H	 %O  	 	 	 	rH   c                     | j                             |          }| j                            t	          j        |d                              | j                            d           d S Nitems )rW   get_mirrorsr*   r+   r   format_list)rD   r)   datas      rF   r<   zSubCommand.show_list  sT    x##G,,o1$w-@@AAAbrH   c                     | j                                         }| j                            t	          j        |d                              | j                            d           d S rm   )rW   get_all_mirrorsr*   r+   r   format_list_all)rD   rr   s     rF   r>   zSubCommand.show_all_list  sS    x''))(8gGGHHHbrH   c                     | j                                         }| j                            t	          j        |d         |                     | j                            d           d S rm   )rW   rt   r*   r+   r	   format_sync_state)rD   r#   rr   s      rF   r?   zSubCommand.sync_state#  sU    x''))(:4=&QQRRRbrH   c                    |                      |d         |          }|s| j                            d           d S t          |          dk    rH| j                            t	          j        |                     | j                            d           d S |                     ||                     |                     d S )Nr   rg   r   ro   )rS   r*   r+   lenr   format_detailshow_detailconvert_show_args)rD   	show_argsr)   r#   s       rF   r@   zSubCommand.show(  s    ""9Q<99 	HMM,---Fy>>QHMM/7??@@@HMM"VT%;%;I%F%FGGGGGrH   c                 b    t          |          D ]\  }}|t          v rt          |         ||<   |S N)	enumerateMIRROR_ARGS_MAPPING)rD   r}   indexargs       rF   r|   zSubCommand.convert_show_args4  s?    #I.. 	< 	<JE3)))#6s#;	% rH   c                    t          |          dk    rN|d         |v r(| j                            ||d                             d S | j                            d           d S d}|dd          D ]}||v r|d||         z  z  }t          |          dk    r| j                            d           n
|d d         }| j                            d	|           d S )
Nr   r   zInvalid fieldro   z%s, r   zInvalid fieldsz%s)ry   r*   r+   )rD   r#   r}   retkeys        rF   r{   zSubCommand.show_detail;  s    y>>Q|v%%fYq\233333o.....C } 0 0&==6F3K//C3xx1}}.////#2#hHMM$$$$$$rH   c                     |                      |          }|s| j                            d           d S | j                            ||d         |           | j                            d||           d S )Nrg   r   z+Mirror %s successfully delete on channel %s)rS   r*   r+   rW   delete_mirror)rD   r)   r   r#   s       rF   r(   zSubCommand.deleteN  su    ""4(( 	HMM,---Fw{(;TBBBCT7SSSSSrH   c                    | j                                         }|d         D ]}|d         |k    r|d         dv rP| j                            d|           | j                             |                     |          |d                    n"| j                            d||d                     d S | j                            d|           d S )	Nrn   r   state)runningpendingzStopping mirror %sr   z4Mirror %s cannot be stopped in its current state: %sMirror %s not found)rW   rt   r*   r+   stop_mirror_get_channel_string)rD   r   rr   r#   s       rF   rA   zSubCommand.stopV  s    x''))7m 	 	Ff~,,'?&<<<HMM"6DDDH(()A)A&)I)I6RV<XXXXHMMN#w  
  - 	+[99999rH   c                    | j                                         }|d         D ]}|d         |k    r| j                            d|           | j                             |d         |                     |          |d         |d         |d         d|v r|d         ni |d         d	|v r|d	         nt          d
d|v r|d         nd 
  
          d S | j                            d|           d S )Nrn   r   zRestarting mirror %sr   r   r   rc   r    r   Tr   r   )rW   rt   r*   r+   r:   r   rh   )rD   r   rr   r#   s       rF   rB   zSubCommand.restartf  s   x''))7m 	 	Ff~%%4d;;;&&4L,,V44=)6N6N)2f)<)<F9%%"6N&,&6&6F6NN<O'.&'8'8F7OOd    & 	+T222rH   Nc                    |5| j                             |          }|d         D ]}|d         |k    r|c S | j                                         }|d         D ]}|d         |k    rd|v r8| j                             |d         d          d|d         d                    }n&| j                             |d         d                   }|d         D ]}|d         |k    r|c c S d S )Nrn   r   r   
subchannelr)   /)rW   rp   rt   )rD   r   r)   rr   r#   s        rF   rS   zSubCommand._get_by_name{  s/   8''00Dw- " "-(D00!MMM 1 x''))7m 	& 	&Ff~%%6))8//!),V4UUvl7KF7SUU DD  8//y0A&0IJJD"7m & &Fm,44% 5	& 	&rH   c                 d    d|v r|d         d          d|d         d          S |d         d         S )Nr   r)   r   r    )rD   r#   s     rF   r   zSubCommand._get_channel_string  sE    6!!Y'/PP&2Fv2NPPP)$V,,rH   c                 R	   |                     | j        d                    | j                  t          j        t
                    }|                    ddd           |                    d          }|                    d	| j                                        d
                    | j                             |                    d| j                                        d                    | j                             |                    d| j                                        d                    | j                             |                    d| j                                        d                    | j                             |                    d| j                                        d                    | j                             |                    dd| j                                        d                    | j                             |                    d| j                                        d                    | j                  d           |                    ddd           |                    dd            |                    d!d"t          d#$           |                    d%d&d'           |                    d(d)d*+           |                    d,d-d.+           |                    d/t          d0+           |                    d1d t          d23           |                    d4d56          }|                    d7d d8+           |                    d9d d:+           |                    d;d d<+           |                    d=d>d d?@           |                    dAd>d dB@           |                    dCd>d dD@           |                    dEt          d dFG           |                    dHd ddFI           |                    dJt          d dKG           |                    dLt          d dMG           |                    dNt          dOdd dPQ           |                    dRddS           |                    | j        T           d S )UNz#Manage your Anaconda repository {}s)helpformatter_classdescriptionz	--channelz-czChannel to mirror to.)r   T)requiredz--createzCreate a new {})metavarr   z--updatezUpdate a {}z--deletezDelete a {}z--stopz	Stop a {}z	--restartzRestart a {}z--listz-lzlist all {}s for a userz--showzShow all of properties of {} or specify a property. Possible values: id, name, source, type, mode, state, proxy, cron, last_run_at, created_at, updated_at*)r   r   nargsz
--list-all
store_truezlist all mirrors)actionr   z--sync-statezshow sync state of mirrorz--sourcez-szQPath to the source channel to mirror. I.e.: https://conda.anaconda.org/conda-test)r    r   z--namez-nzName of the mirrorz--modepassivezMirror mode. If "active", will download all the files from the source channel immediately else, if "passive", download JSON immediately and files on demand later. Default is "passive")defaultr   z--typecondaz@Mirror type. Possible types: "conda", "python_simple" and "CRAN"z--cronz(Cron string to configure the mirror job.z--proxyzaProxy to use for the mirroring in format "http://<PROXYURL>" or "http://<USER>:<PASS>@<PROXYURL>")r   r    r   zmirror filtersz}Filters are used to filter specific subset of packages from the original index. Some filters are specific to artifact family.)r   z	--subdirsza[conda] List of conda subdirs, I.e.: linux-64, osx-64, linux-32, etc. Use comma-separated string.z
--projectszE[python] List of pypi projects to mirror. Use comma-separated string.z
--licenseszList of licenses to filter for. Use comma-separated string, prepent with "-" to exclude, or just a license to include. The allowed license values are: agpl, gpl2, gpl3, lgpl, bsd, mit, apache, psf, public_domain, proprietary, other, nonez--only_specrU   zJMatchSpec to only spec. Use multiple times the option for multiple entries)r   r   r   z--exclude_speczHMatchSpec to exclude. Use multiple times the option for multiple entriesz--include_speczHMatchSpec to include. Use multiple times the option for multiple entriesz--cve_scorezGOnly mirror files with CVE score less or equal to this value. I.e.: 9.5)r    r   r   z --exclude_uncurated_cve_packages)r   r   r   z--date_fromz9[conda] bottom date YYYY-mm-dd when package was publishedz	--date_toz8[conda] upper date YYYY-mm-dd when package was publishedz--only_signed?zOnly mirror signed packages)r    r   constr   r   z	--run_nowzZDetermines whether the mirror job should run immediately or according to the cron schedule)rG   )
add_parserr   formatargparseRawDescriptionHelpFormatter__doc__add_argumentadd_mutually_exclusive_groupupperr   rh   r   add_argument_groupr   r   r   set_defaultsrG   )rD   
subparsers	subparserre   filters_groups        rF   r   zSubCommand.add_parser  s   ))I6==diHH$@	 * 
 
	 	{D7NOOO666EEIOO%%"))$)44 	 	
 	
 	
 		 1 18L8LTY8W8W 	 	
 	
 	
 		 1 18L8LTY8W8W 	 	
 	
 	
 	dioo//k6H6H6S6S 	 	
 	
 	
 	IOO%%&&ty11 	 	
 	
 	
 	IOO%%*11$)<<	 	 	
 	
 	
 	IOO%%LLRF	M M  	 	
 	
 	
 	<CUVVV>0KLLL:	 	 	
 	
 	
 	x4HIII* 	 	
 	
 	
 	S 	 	
 	
 	

 	'; 	 	
 	
 	

 	 t	 	 	
 	
 	
 "44C 5 
 

 	""* 	# 	
 	
 	
 	""X 	# 	
 	
 	

 	""M 	# 	
 	
 	
 	""]	 	# 	
 	
 	
 	""[	 	# 	
 	
 	
 	""[	 	# 	
 	
 	
 	"" Z	 	# 	
 	
 	
 	"".Z	 	# 	
 	
 	
 	"""L	 	# 	
 	
 	
 	"""K	 	# 	
 	
 	
 	"". 	# 	
 	
 	
 	- 	 	
 	
 	
 	DI.....rH   r   )__name__
__module____qualname__r   rG   r-   r:   rV   r<   r>   r?   r@   r|   r{   r(   rA   rB   rS   r   r   r   rH   rF   r"   r"   )   s+       DE( E( E(PAU AU AUFXT XT XTt    
  
  

H 
H 
H  % % %&T T T: : :   *& & & &*- - -h/ h/ h/ h/ h/rH   r"   )r   
__future__r   r   r   ro   r   utils.formatr   r   r	   r
   r   utils.validatorsr   r   r   r   baser   rh   r   r"   r   rH   rF   <module>r      sK    8 7 7 7 7 7 7 7                                !          !     U/ U/ U/ U/ U/ U/ U/ U/ U/ U/rH   