a
    ϑ`i                     @   sn   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 dd
dZ
dZG dd deZG dd de	ZdS )a  
Remove an object from your Anaconda Team Edition.

Example::


    # Remove specific package by providing version and package filename
    conda repo remove mychannel::mypackage/1.2.0/mypackage.tar.gz

    # Remove specific package by providing package filename
    conda repo remove mychannel::mypackage//mypackage.tar.gz

    # Remove all package files
    conda repo remove mychannel::mypackage

    )urlparseN)RawTextHelpFormatter   )errors   )SubCommandBaseTc                 C   sv   |rdnd}t d| |f }| dv r0|s0dS | dv rD|sDdS | dv rTdS | d	v rddS tjd
 qd S )Nz[Y|n]z[y|N]z%s %s: )yyesT) nnoF)r
   r   r	   )r   r   zplease enter yes or no
)inputlowersysstderrwrite)promptdefaultZdefault_strZinpt r   7lib/python3.9/site-packages/repo_cli/commands/remove.py
bool_input   s    r      c                   @   sn   e Zd ZdddZedd Zdd Zdd	 Zed
d Z	edd Z
edd Zedd Zedd ZdS )PackageSpecNc                 C   sl   || _ || _|| _|| _|| _|r*|| _n>t|}|rBd||f }|rRd||f }|rbd||f }|| _d S )Nz%s/%s)_user_package_version	_filenameattrsspec_strstr)selfchannelpackageversionfilenamer   r   r   r   r   __init__,   s    zPackageSpec.__init__c                 C   s   |}d  } }}i }d|v r,| dd\}}|rHd|v rH| dd\}}|rdd|v rd| dd\}}|rd|v r|dd\}}tt|}t||||||S )Nz::r   /?)splitrsplitdictr   	parse_qslr   )clsZspec_stringr!   r"   r#   r$   r   Zqslr   r   r   from_string>   s    zPackageSpec.from_stringc                 C   s   | j S )Nr   r    r   r   r   __str__Q   s    zPackageSpec.__str__c                 C   s
   d| j  S )Nz<PackageSpec %r>r.   r/   r   r   r   __repr__T   s    zPackageSpec.__repr__c                 C   s"   | j d u rtd| jf | j S )Nz,user not given (got %r expected <username> ))r   r   	UserErrorr   r/   r   r   r   r!   W   s    
zPackageSpec.channelc                 C   s"   | j d u rtd| jf | j S NzApackage not given in spec (got %r expected <username>/<package> )r   r   r2   r   r/   r   r   r   name]   s    
zPackageSpec.namec                 C   s"   | j d u rtd| jf | j S r3   r4   r/   r   r   r   r"   c   s    
zPackageSpec.packagec                 C   s"   | j d u rtd| jf | j S )NzKversion not given in spec (got %r expected <username>/<package>/<version> ))r   r   r2   r   r/   r   r   r   r#   i   s    
zPackageSpec.versionc                 C   s"   | j d u rtd| jf | j S )NzWfilename not given in spec (got %r expected <username>/<package>/<version>/<filename> ))r   r   r2   r   r/   r   r   r   r$   o   s    
zPackageSpec.filename)NNNNN)__name__
__module____qualname__r%   classmethodr-   r0   r1   propertyr!   r5   r"   r#   r$   r   r   r   r   r   +   s   





r   c                   @   s*   e Zd ZdZdd Zd	ddZdd ZdS )

SubCommandremovec              	   C   s   | j jD ]}z|jr6| |j| j j|j|j|j| nV|j	r\| j|j| j j|j|j|d n0|j
r~| j|j| j j|j|d n| jd| W q tjy   | j jr| jjddd Y qn Y q0 qd S )N)specz!Invalid package specification: %sr
   T)exc_info)argsspecsr   remove_artifactr!   familyr"   r#   r$   r   r   logerrorr   ZNotFoundforcewarning)r    r=   r   r   r   mainx   s    " zSubCommand.mainNc                 C   s   ||d}g }|s|r| j |||||\}	}
|	sF| jd|  d S g }|	D ]8}|djf i | t|}|d |d< || qNd|}d||f }nd|f }|g}| jj	st
|dr| j |d	| | jd
|  n| jd|  d S )N)r5   rB   z6No files matches were found for the provided spec: %s
zFPACKAGE: {name}:{version}-{ckey}; PLATFORM: {platform}; FILENAME: {fn}Zckey
zhAre you sure you want to remove the package release %s ? The following will be affected: 

 %s

Confirm?zHAre you sure you want to remove the package %s ? (and all data with it?)FdeletezSpec %s succesfully removed
zNot removing release %s
)ZapiZget_channel_artifacts_filesrC   rF   appendformatr*   joinr?   rE   r   Zchannel_artifacts_bulk_actionsinfo)r    r!   rB   Zartifactr#   r$   r=   Z	base_itemitemsZpackagesZtotal_countZfiles_descrZfilepitemZaffected_filesmsgr   r   r   rA      s2    

zSubCommand.remove_artifactc                 C   sZ   |j ddttd}|jddtjdd |jdd	d
dd |jdddd |j| jd d S )Nr<   a  Remove an object from your Anaconda Team Edition repository. Must refer to the formal package name as it appears in the URL of the package. Also use anaconda show <USERNAME> to see list of package names. Example: anaconda remove continuumio/empty-example-notebook)helpdescriptionformatter_classr@   zOPackage written as <channel>/<subchannel>[::<package>[/<version>[/<filename>]]]+)rQ   typenargsz-fz--forcezDo not prompt removal
store_true)rQ   actionz--familyZcondazVartifact family (i.e.: conda, python, cran, anaconda_project, anaconda_env, nootebook))r   rQ   )rG   )
add_parser__doc__r   add_argumentr   r-   set_defaultsrG   )r    Z
subparsersparserr   r   r   rY      s    zSubCommand.add_parser)NNN)r6   r7   r8   r5   rG   rA   rY   r   r   r   r   r;   u   s   
%r;   )T)rZ   Zsix.moves.urllib.parser   r   argparser   r
   r   baser   r   ZWAIT_SECONDSobjectr   r;   r   r   r   r   <module>   s   
J