
    e                         d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
  ej        d          Z G d	 d
e
          ZdS )a  
Download artifact download reports from anaconda server

conda repo report

This command will download a report of all artifact downloads from the anaconda server and save it in the current working directory.
If you want to chane the download directory, use the --filename option.
    N)Path   )check_date_format   )SubCommandBaserepo_clic                   F    e Zd ZdZd Z	 ddZedd            Zd Zd Z	dS )	
SubCommandreportc                     |                      | j        j        | j        j        | j        j        | j        j        | j        j        | j        j        r| j        j        nd            d S N)download_reportargs	date_fromdate_to	file_type
user_nameschannelsfilename)selfs    8lib/python3.11/site-packages/repo_cli/commands/report.pymainzSubCommand.main   sc    IIII I"&)"4>DI$	
 	
 	
 	
 	
    Nc                    ||k    rt          d| d| d          |r|                    d          nd }|r|                    d          nd }|                     |           t                              d|d|           | j                            |||||          }|st                              d           d S t          | 	                    ||||                    }t                              d|            |d	k    r+|
                    t          j        |          d
           d S |dk    r|
                    |d
           d S d S )Nz&Invalid date range: The starting date z& must be earlier than the ending date .,zDownloading report for z to z'No report available for the given dateszSaving report to jsonzutf-8)encodingcsv)
ValueErrorsplitvalidate_channelsloggerinfoapi
get_reporterrorr   get_filename
write_textr   dumps)	r   r   r   r   	usernamesr   r   report_datafilepaths	            r   r   zSubCommand.download_report"   s    wtttjqttt   -6?IOOC(((4	*2<8>>#&&&x(((GGLMMMh))w	8Y
 
  	LLBCCCF)))WiRRSS222333
; 7 7'JJJJJ%g>>>>>  r   c                 L   |rgt          |          }|                                st          j                            |          S t
                              d| d           t          d|  d| d| }t          j                            t          j	                    |          S )NzFile z5 already exists. Please specify a different filename.artifact_download_report__r   )
r   is_fileospathabspathr#   r'   FileExistsErrorjoingetcwd)r   r   r   r   files        r   r(   zSubCommand.get_filename?   s     	&>>D<<>> &wx000[H[[[   &%PyPP7PPYPPw||BIKK222r   c                     |sdS d | j                                         d         D             }|D ]}||vrt          d| d          d S )NTc                 .    g | ]}|d          
|d          S )name ).0channels     r   
<listcomp>z0SubCommand.validate_channels.<locals>.<listcomp>Q   s6     
 
 
v
FO
 
 
r   itemszChannel z does not exist)r%   list_channelsr    )r   r   all_channelsr>   s       r   r"   zSubCommand.validate_channelsM   s     	4
 
81133G<
 
 
   	F 	FGl** !DG!D!D!DEEE +	F 	Fr   c                    |                     ddt                    | _        | j                            dt          d dd           | j                            dt          t
          j                                                            d	          d
           | j                            dt          dddgd           | j                            dt          d           | j                            dt          d           | j                            dt          d           | j        	                    | j
                   d S )Nr   zdownload reports)helpdescriptionz--date_fromz'starting date YYYY-mm-dd for the reportT)typedefaultrD   requiredz	--date_toz%Y-%m-%dz"end date YYYY-mm-dd for the report)rF   rG   rD   z--file-typer   r   zformat of the report)rF   rG   choicesrD   z--user_nameszcomma separated list of users)rF   rD   z
--channelsz comma separated list of channelsz
--filenamezbfilename to save the report. Can contain full path for report to be saved in a different directory)r   )
add_parser__doc__	subparseradd_argumentr   datetimenowstrftimestrset_defaultsr   )r   
subparserss     r   rJ   zSubCommand.add_parser[   su   #..-7 / 
 
 	##": 	$ 	
 	
 	
 	##"%))++44Z@@5	 	$ 	
 	
 	
 	##UO' 	$ 	
 	
 	
 	##0 	$ 	
 	
 	
 	##3 	$ 	
 	
 	
 	##u 	$ 	
 	
 	
 	###33333r   r   )
__name__
__module____qualname__r;   r   r   staticmethodr(   r"   rJ   r<   r   r   r
   r
      s        D
 
 
 LP? ? ? ?: 3 3 3 \3F F F.4 .4 .4 .4 .4r   r
   )rK   rN   r   loggingr2   pathlibr   utils.validatorsr   baser   	getLoggerr#   r
   r<   r   r   <module>r]      s        				       0 0 0 0 0 0            		:	&	&t4 t4 t4 t4 t4 t4 t4 t4 t4 t4r   