
    wBf                     ~   d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZm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 d	dlmZ d	dlm Z  d	dl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d	dl*m+Z+m,Z, d	dl-m.Z.m/Z/m0Z0m1Z1m2Z2 d	dl3m4Z4 d	dl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> d	dl?m@Z@ d	dlAmBZB d	dlCmDZDmEZEmFZFmGZG d	dlHmIZImJZJ d	dlKmLZL d	dlMmNZN d	dlOmPZPmQZQmRZR d	dlSmTZT d	dlUmVZVmWZWmXZXmYZYmZZZm[Z[ ddl\m]Z]m^Z^m_Z_ dd l`maZambZb dd!lcmdZd 	 ee  eeh      Zi ej                  d"ej                        Zld#Zm G d$ d%e&      Zn G d' d(ene&      Zo G d) d*ene&      Zp G d+ d,eoe&      Zq G d- d.eqe&      Zr G d/ d0er      Zs G d1 d2es      Zt G d3 d4er      Zu G d5 d6er      Zv G d7 d8ep      Zw G d9 d:ew      Zx G d; d<er      Zy G d= d>er      Zz G d? d@er      Z{ G dA dBeo      Z| G dC dDeqe&      Z} G dE dFe}      Z~ G dG dHe}      Z G dI dJe~      Z G dK dLeo      Z G dM dNeo      Z G dO dPeo      Zy# ef$ r egZeY /w xY w)QzJAtomic actions that make up a package installation or removal transaction.    N)ABCMetaabstractmethodabstractproperty)chain)JSONDecodeError)	getLogger)basenamedirnamegetsizeisdirjoin)uuid4   )
CondaError)dals)CONDA_TEMP_EXTENSION)context)on_win)TRACE)get_bin_directory_short_pathget_leaf_directoriesget_python_noarch_target_pathget_python_short_pathparse_entry_point_defpyc_pathurl_to_pathwin_path_ok)has_platformpath_to_url)CondaUpgradeErrorCondaVerificationErrorNotWritableErrorPaddingErrorSafetyError)download)	compile_multiple_pyccopycreate_hard_link_or_copycreate_linkcreate_python_entry_pointextract_tarball	make_menumkdir_pwrite_as_json_to_file)rm_rf)make_writable)compute_sumislinklexistsread_index_json)backoff_renametouch)History)Channel)LinkType
NoarchTypePathType)	MatchSpec)LinkPackageCacheRecordPackageRecord
PathDataV1	PathsDataPrefixRecord   )get_user_environments_txt_fileregister_envunregister_env)_PaddingErrorupdate_prefix)
PrefixDataz^menu/.*\.json$)transaction_contextpackage_info	hold_pathc                   f    e Zd ZdZed        Zed        Zed        Zed        Ze	d        Z
d Zy)	_ActionFc                     t               NNotImplementedErrorselfs    7lib/python3.12/site-packages/conda/core/path_actions.pyverifyz_Action.verifyX   s    
 "##    c                     t               rP   rQ   rS   s    rU   executez_Action.execute_       !##rW   c                     t               rP   rQ   rS   s    rU   reversez_Action.reversec   rZ   rW   c                     t               rP   rQ   rS   s    rU   cleanupz_Action.cleanupg   rZ   rW   c                     | j                   S rP   	_verifiedrS   s    rU   verifiedz_Action.verifiedk   s    ~~rW   c                     d t        |       j                         D        }dj                  | j                  j                  dj                  |            S )Nc              3   @   K   | ]  \  }}|t         vr	| d |  yw)=N)REPR_IGNORE_KWARGS).0keyvalues      rU   	<genexpr>z#_Action.__repr__.<locals>.<genexpr>p   s0      
U,, e1UI
s   z{}({})z, )varsitemsformat	__class____name__r   )rT   argss     rU   __repr__z_Action.__repr__o   sC    
"4j..0

 t~~66		$HHrW   N)ro   
__module____qualname__ra   r   rV   rY   r\   r^   propertyrb   rq    rW   rU   rN   rN   U   so    I$ $ $ $ $ $ $ $  IrW   rN   )	metaclassc                       e Zd Zed        Zy)
PathActionc                     t               rP   rQ   rS   s    rU   target_full_pathzPathAction.target_full_pathy   rZ   rW   N)ro   rr   rs   r   rz   ru   rW   rU   rx   rx   x       $ $rW   rx   c                       e Zd Zed        Zy)MultiPathActionc                     t               rP   rQ   rS   s    rU   target_full_pathsz!MultiPathAction.target_full_paths   rZ   rW   N)ro   rr   rs   r   r   ru   rW   rU   r}   r}   ~   r{   rW   r}   c                   2    e Zd Zd Zed        Zed        Zy)PrefixPathActionc                 .    || _         || _        || _        y rP   )rJ   target_prefixtarget_short_path)rT   rJ   r   r   s       rU   __init__zPrefixPathAction.__init__   s    #6 *!2rW   c                     | j                   fS rP   r   rS   s    rU   target_short_pathsz#PrefixPathAction.target_short_paths   s    &&((rW   c                 f    | j                   | j                  }}||t        |t        |            S y rP   )r   r   r   r   )rT   trgtshrt_pths      rU   rz   z!PrefixPathAction.target_full_path   s7    ++T-C-Ch 4k(344rW   N)ro   rr   rs   r   rt   r   rz   ru   rW   rU   r   r      s/    3
 ) )  rW   r   c                   :     e Zd Z fdZd Zd Zed        Z xZS )CreateInPrefixPathActionc                 R    t         |   |||       || _        || _        || _        y rP   )superr   rK   source_prefixsource_short_path)rT   rJ   rK   r   r   r   r   rn   s          rU   r   z!CreateInPrefixPathAction.__init__   s0     	,m=NO(*!2rW   c                     d| _         y NTr`   rS   s    rU   rV   zCreateInPrefixPathAction.verify   	    rW   c                      y rP   ru   rS   s    rU   r^   z CreateInPrefixPathAction.cleanup       rW   c                 h    | j                   | j                  }}|r|rt        |t        |            S d S rP   )r   r   r   r   )rT   prfxr   s      rU   source_full_pathz)CreateInPrefixPathAction.source_full_path   s2    ++T-C-Ch48XtD+h/0O4OrW   )	ro   rr   rs   r   rV   r^   rt   r   __classcell__rn   s   @rU   r   r      s(    3 P PrW   r   c                   `     e Zd Zed        Zed        Zed        Z fdZd Zd Z	d Z
 xZS )LinkPathActionc                 z    fdfdt        fdj                  j                  D              S )Nc                 0   | j                   t        j                  k(  rt        j                  }d\  }}n^| j
                  r)t        j                  }| j
                  }| j                  }n)| j                  rt        j                  }d\  }}n}d\  }}|||fS )N) N)	path_typer;   softlinkr9   r'   prefix_placeholder	file_modeno_link)source_path_data	link_typeprefix_placehoderr   requested_link_types       rU   get_prefix_replacezCLinkPathAction.create_file_link_actions.<locals>.get_prefix_replace   s    ))X->->>$MM	/7,!9!44$MM	$4$G$G!,66	!))$MM	/7,!9/	/7,!9/::rW   c                 6   j                   j                  }|0j                  $j                  j                  }||j                  }|t        j
                  k(  r,d   }|t        d
z        t        | j                  |      }n6||t        j                  k(  r| j                  }nt        t        d             |       \  }}}|r(t        j                  | j                  
|	||| 
      S t        j                  | j                  
|||       S )Ntarget_site_packages_short_pathziUnable to determine python site-packages dir in target_prefix!
Please make sure python is installed in %szv
                The current version of conda is too old to install this package.
                Please update conda.)repodata_recordnoarchpackage_metadatatyper:   pythonr   r   pathgenericr    r   PrefixReplaceLinkActionextracted_package_dirr   )r   r   sp_dirr   r   placeholderfmoder   rK   r   r   rJ   s          rU   make_file_link_actionzFLinkPathAction.create_file_link_actions.<locals>.make_file_link_action   sQ   !1188F~,"?"?"K%66==%#[[F***,-NO>$46CD 
 %B$))6%! 6Z-?-?#?$4$9$9!'(  -??O,P)I{E.'  66$))!%'$  &'  66$))!%$	 	rW   c              3   .   K   | ]  } |        y wrP   ru   )rg   spir   s     rU   rj   z:LinkPathAction.create_file_link_actions.<locals>.<genexpr>
  s      
+.!#&
s   )tuple
paths_datapaths)clsrJ   rK   r   r   r   r   s    ````@@rU   create_file_link_actionsz'LinkPathAction.create_file_link_actions   s;    	;"7	 7	r  
2>2I2I2O2O
 
 	
rW   c                 \     t        d |D              }t         fd|D              S )Nc              3   4   K   | ]  }|j                     y wrP   r   )rg   axns     rU   rj   z:LinkPathAction.create_directory_actions.<locals>.<genexpr>  s      0
&)C!!0
s   c              3   X   K   | ]!  } d d |t         j                  d        # y wrP   )r9   	directory)rg   directory_short_pathr   rK   r   rJ   s     rU   rj   z:LinkPathAction.create_directory_actions.<locals>.<genexpr>  s>      
 % #$""	
s   '*)r   r   )r   rJ   rK   r   r   file_link_actionsleaf_directoriess   ````   rU   create_directory_actionsz'LinkPathAction.create_directory_actions  s;     0 0
->0
 
  
 )9
 
 	
rW   c           
          t         j                  }d}t        |      \  }}	}	d|z  }
t        |
t        j
                        } | ||||||
||      S )NzScripts/conda.exezScripts/%s.exe_pathr   )r   conda_prefixr   r@   r;   windows_python_entry_point_exe)r   rJ   rK   r   r   entry_point_defsource_directoryr   command_r   r   s               rU   ,create_python_entry_point_windows_exe_actionz;LinkPathAction.create_python_entry_point_windows_exe_action(  so     #///-o>A,w6%#==
 	
 		
rW   c	                 f    t         	|   ||||||       || _        d| _        || _        d | _        y NF)r   r   r   _execute_successfulr   prefix_path_data)
rT   rJ   rK   r   r   r   r   r   r   rn   s
            rU   r   zLinkPathAction.__init__D  sE     	!	
 ##(  0 $rW   c                 V   | j                   t        j                  k7  rot        | j                        sZt        t        d| j                  j                  j                   d| j                  j                   d| j                   d            S | j                  }	 |j                  }|t        j                   v rd }| j                   t        j                  k(  rd | _        d| _         y | j                   t        j$                  k(  r@t'        j(                  | j                  |xs t        j$                        | _        d| _         y | j                   t        j*                  k(  r]|j                  t        j$                  k(  r@t'        j(                  | j                  |xs t        j$                        | _        d| _         y |j                  t        j,                  k(  rd	 |j.                  }d}|rzt1        | j                        }||k7  r`t3        t        d| j                  j                  j                   d| j                  j                   d| j                   d	| d
| d            S 	 |j4                  }|r||k(  rt6        j8                  r}t;        | j                  d      }|re||k7  r`t3        t        d| j                  j                  j                   d| j                  j                   d| j                   d| d| d            S t'        j(                  ||||xs t        j,                        | _        d| _         y |j                  t        j<                  k(  r|| _        d| _         y t?               # t        $ r d }Y w xY w# t        $ r d }Y w xY w# t        $ r d }Y 4w xY w)Nz
            The package for z located at z0
            appears to be corrupted. The path 'zM'
            specified in the package manifest cannot be found.
            )r   r   z%
                    The package for z8
                    appears to be corrupted. The path 'zR'
                    has an incorrect size.
                      reported size: z* bytes
                      actual size: z bytes
                    sha256zR'
                    has a sha256 mismatch.
                    reported sha256: z$
                    actual sha256: z
                    )r   sha256_in_prefixr   T)!r   r9   r   r3   r   r!   r   rK   r   namer   r   r   r   AttributeErrorr;   basic_typesr   r   r@   from_objectsr'   hardlinksize_in_bytesr   r$   r   r   extra_safety_checksr1   r   rR   ra   )rT   r   source_path_typereported_size_in_bytessource_size_in_bytesreported_sha256source_sha256s          rU   rV   zLinkPathAction.verify\  s   >>X///!!9
 *!..>>CCDLQUQbQbQxQxPy z0040F0F/G H   00	$/99 x333#>>X///$(D!N M ^^x000$.$;$;%%*?h.?.?%D!J A NNhmm+ **h.?.??$.$;$;%%*?h.?.?%D!z q ''8+<+<<.)9)G)G& $% %'.t/D/D'E$)-AA&!%%)%6%6%F%F%K%K$LLY]YjYj  ZA  ZA  YB B88<8N8N7O P&&<%= >$$8#9 :
 
'"2"9"9
 %*.BB// +D,A,A8 L"-'G&!%%)%6%6%F%F%K%K$LLY]YjYj  ZA  ZA  YB B88<8N8N7O P&&5%6 7$$1? 3
 
 %/$;$; &!0*?h.?.?	%D!  ''8+R+RR$4D!  &''Y  	$#	$2 " .)-&.( " '"&'s6   M5 N 'N 5NNNNN('N(c                     t         j                  t        d| j                  | j                         t	        | j                  | j                  | j
                  t        j                         d| _        y )Nlinking %s => %sforceT)	logr   r   rz   r)   r   r   r   r   rS   s    rU   rY   zLinkPathAction.execute  sS    )4+@+@$BWBWX!!!!NN--		
 $( rW   c                     | j                   rSt        j                  t        d| j                         t	        | j
                        st        | j
                  d       y y y )Nzreversing link creation %sTclean_empty_parents)r   r   r   r   r   rz   r/   rS   s    rU   r\   zLinkPathAction.reverse  sJ    ##GGE79K9KL../d++F 0 $rW   )ro   rr   rs   classmethodr   r   r   r   rV   rY   r\   r   r   s   @rU   r   r      sW    O
 O
b 
 
2 
 
6%0_B(GrW   r   c                   .     e Zd Z fdZ fdZd Z xZS )r   c           
          |t         j                  k(  rt         j                  nt         j                  }t        |   ||||||||
       || _        |	| _        d | _        y rP   )r9   r'   r   r   r   r   r   intermediate_path)rT   rJ   rK   r   r   r   r   r   r   r   r   rn   s              rU   r   z PrefixReplaceLinkAction.__init__  s_     &/(--%?HMMXEVEV	!		
 #5"!%rW   c                    t         |          }|r|S t        | j                        r,t        j	                  t
        d| j                         J d       t        | j                  d          t        | j                  d   t        t                           | _        t        j	                  t
        d| j                  | j                         t        | j                  | j                  t        j                         t        | j                         	 t        j	                  t
        d| j                          t#        | j                  t$        j&                  xs | j(                  | j*                  | j,                  | j.                  j0                  j2                         t;        | j                  d      }t=        j>                  | j@                  | j,                  tB        jD                  | j*                  |      | _         d	| _#        y # t4        $ r5 t7        | j                   | j*                  t9        | j*                              w xY w)
Nz6ignoring prefix update for symlink with source path %sz4I don't think this is the right place to ignore thistemp_dirzcopying %s => %szrewriting prefixes in %s)subdirr   )r   r   r   r   T)$r   rV   r2   r   r   r   r-   rJ   r   strr   r   r)   r9   r'   r0   rz   rH   r   target_prefix_overrider   r   r   rK   r   r   rG   r#   lenr1   r@   r   r   r;   r   ra   )rT   validation_errorr   rn   s      rU   rV   zPrefixReplaceLinkAction.verify  s    7>+##$''(GGH%% QPP5((45!%$$Z0#eg,"
 	%t'<'<d>T>T	
 	D))4+A+A8==Qd,,-	GGE5t7L7LM&&..D$2D2D''((88?? 't'='=xH * 7 7!!nn''#66-!
 #  	%%''D++, 	s   BH >Ic                    | j                   s| j                          | j                  xs | j                  }t        j	                  t
        d|| j                         t        || j                  | j                         d| _	        y )Nr   T)
ra   rV   r   r   r   r   rz   r)   r   r   )rT   source_paths     rU   rY   zPrefixReplaceLinkAction.execute!  s_    ~~KKM,,E0E0E);8M8MNK!6!6G#' rW   )ro   rr   rs   r   rV   rY   r   r   s   @rU   r   r     s    &:3j(rW   r   c                   :     e Zd Zed        Z fdZd Zd Z xZS )MakeMenuActionc                 F    t         j                  xs dD cg c]  }|j                          }}t         j                  rYt         j                  r|rGj                  j                         |v r+t         fdj                  j                  D              S yc c}w )Nru   c              3      K   | ]A  }t        t        j                  |j                              r |j                         C y wrP   )bool_MENU_REmatchr   )rg   r   r   rK   r   rJ   s     rU   rj   z0MakeMenuAction.create_actions.<locals>.<genexpr>4  s>      sxx01 '}chhOs   AA
)r   shortcuts_onlylower	shortcutsr   r   r   r   )r   rJ   rK   r   r   r   shorcuts_lowers   ````   rU   create_actionszMakeMenuAction.create_actions+  s     5<4J4J4PbR4$**,RR&&<#4#4#:#:#<#N '2288    Ss   Bc                 <    t         |   ||d d ||       d| _        y r   )r   r   r   )rT   rJ   rK   r   r   rn   s        rU   r   zMakeMenuAction.__init__<  s.     		
 $) rW   c                     t         j                  t        d| j                         t        | j                  | j
                  d       d| _        y )Nzmaking menu for %sFremoveT)r   r   rz   r,   r   r   r   rS   s    rU   rY   zMakeMenuAction.executeI  s9    +T-B-BC$$$d&<&<UK#' rW   c                     | j                   rHt        j                  t        d| j                         t	        | j
                  | j                  d       y y )Nzremoving menu for %sTr
  )r   r   r   rz   r,   r   r   rS   s    rU   r\   zMakeMenuAction.reverseN  s?    ##GGE143H3HId(($*@*@N $rW   	ro   rr   rs   r   r  r   rY   r\   r   r   s   @rU   r   r   *  s%      )(
OrW   r   c                   :     e Zd Zed        Z fdZd Zd Z xZS )CreateNonadminActionc                 l    t         r.t        t        t        j                  d            r | |||      fS y)N	.nonadminru   )r   r3   r   r   root_prefix)r   rJ   rK   r   r   s        rU   r  z#CreateNonadminAction.create_actionsU  s1     gd7#6#6DE+\=IKKrW   c                 <    t         |   ||d d |d       d| _        y )Nr  F)r   r   _file_created)rT   rJ   rK   r   rn   s       rU   r   zCreateNonadminAction.__init__^  s'    tT=+	
 #rW   c                     t         j                  t        d| j                         t        | j                        | _        y )Nztouching nonadmin %s)r   r   rz   r6   r  rS   s    rU   rY   zCreateNonadminAction.executed  s,    -t/D/DE"4#8#89rW   c                     | j                   r;t        j                  t        d| j                         t	        | j                         y y )Nzremoving nonadmin file %s)r  r   r   rz   r/   rS   s    rU   r\   zCreateNonadminAction.reverseh  s5    GGE68M8MN$''( rW   r  r   s   @rU   r  r  T  s$     #:)rW   r  c                   Z    e Zd Zed        Zd Zed        Zed        Zd Z	d Z
d Zd Zy	)
CompileMultiPycActionc                 ,  	
 |j                   xr |j                   j                  }|l|j                  t        j                  k(  rOt        j                  d      	|d   
t        	fd|D              }t        
fd|D              } | |||||      fS y)Nz&^site-packages[/\\][^\t\n\r\f\v]+\.py$target_python_versionc              3      K   | ]7  }t        |d       r)j                  |j                        r|j                   9 yw)r   N)getattrr  r   r   )rg   r   noarch_py_file_res     rU   rj   z7CompileMultiPycAction.create_actions.<locals>.<genexpr>|  s>      3 34%++C,A,AB %%s   =A c              3   6   K   | ]  }t        |        y wrP   )r   )rg   pfpy_vers     rU   rj   z7CompileMultiPycAction.create_actions.<locals>.<genexpr>  s     Frhr62Fs   ru   )r   r   r   r:   r   recompiler   )r   rJ   rK   r   r   r   r   py_files	pyc_filesr  r   s            @@rU   r  z$CompileMultiPycAction.create_actionso  s     ..W<3P3P3W3W&++1B1B"B "

+T U()@AF , H FXFFI' !  rW   c                     || _         || _        || _        || _        || _        d | _        | j                  D cg c]  }t        |t        j                         c}| _	        d| _
        y c c}w Nr   F)rJ   rK   r   source_short_pathsr   r   r@   r;   pyc_fileprefix_paths_datar   )rT   rJ   rK   r   r'  r   ps          rU   r   zCompileMultiPycAction.__init__  sy     $7 (*"4"4 $ ,,"

 	 "++"
 $) "
s   "A+c                 8     d  fd j                   D        S )Nc                 6    | |y t        | t        |            S rP   r   r   prefix
short_paths     rU   join_or_nonez=CompileMultiPycAction.target_full_paths.<locals>.join_or_none  !    ~!3FK
$;<<rW   c              3   D   K   | ]  } j                   |        y wrP   r   rg   r*  r1  rT   s     rU   rj   z:CompileMultiPycAction.target_full_paths.<locals>.<genexpr>       UT//3U    )r   rT   r1  s   `@rU   r   z'CompileMultiPycAction.target_full_paths      	= VT=T=TUUrW   c                 8     d  fd j                   D        S )Nc                 6    | |y t        | t        |            S rP   r-  r.  s     rU   r1  z=CompileMultiPycAction.source_full_paths.<locals>.join_or_none  r2  rW   c              3   D   K   | ]  } j                   |        y wrP   r4  r5  s     rU   rj   z:CompileMultiPycAction.source_full_paths.<locals>.<genexpr>  r6  r7  )r'  r8  s   `@rU   source_full_pathsz'CompileMultiPycAction.source_full_paths  r9  rW   c                     d| _         y r   r`   rS   s    rU   rV   zCompileMultiPycAction.verify  r   rW   c                      y rP   ru   rS   s    rU   r^   zCompileMultiPycAction.cleanup  r   rW   c                 `   t         j                  t        ddj                  | j                               | j                  d   }t        |      }t        | j                  t        |            }t        || j                  | j                  | j                  | j                  d          d| _
        y )Nzcompiling %s r  T)r   r   r   r   rJ   r   r   r   r&   r=  r   )rT   r  python_short_pathpython_full_paths       rU   rY   zCompileMultiPycAction.execute  s    
 	~sxx0F0F'GH $ 8 89P Q12GH 2 2K@Q4RS""""$$%<=	
 $( rW   c                     | j                   rQt        j                  t        ddj                  | j                               | j                  D ]  }t        |        y y )Nzreversing pyc creation %srA  )r   r   r   r   r   r/   )rT   rz   s     rU   r\   zCompileMultiPycAction.reverse  sT    ##GG2CHHT=S=S4T %)$:$: ( &'(	 $rW   N)ro   rr   rs   r   r  r   rt   r   r=  rV   r^   rY   r\   ru   rW   rU   r  r  n  sY     >). V V V V($(rW   r  c                   "     e Zd ZdZ fdZ xZS )AggregateCompileMultiPycActionzBunch up all of our compile actions, so that they all get carried out at once.
    This avoids clobbering and is faster when we have several individual packages requiring
    compilation.
    c                 (   |d   j                   }|d   j                  }|d   j                  }t               }t               }|D ]8  }|j	                  |j
                         |j	                  |j                         : t        	| !  |||||       y )Nr   )	rJ   rK   r   setupdater'  r   r   r   )
rT   individualskwrJ   rK   r   r'  r   
individualrn   s
            rU   r   z'AggregateCompileMultiPycAction.__init__  s    )!n@@"1~22#A44 U U% 	EJ%%j&C&CD%%j&C&CD	E 		
rW   )ro   rr   rs   __doc__r   r   r   s   @rU   rF  rF    s    

 
rW   rF  c                   :     e Zd Zed        Z fdZd Zd Z xZS )CreatePythonEntryPointActionc                 H    j                   xr j                   j                  }|v|j                  t        j                  k(  rYd t         fd|j                  xs dD              }t        r(|t        fd|j                  xs dD              z  }|S y)Nc                 ^    t        |       \  }}}t                d| }t        r|dz  }|||fS )N/z
-script.py)r   r   r   )r   r   modulefuncr   s        rU   this_tripletzACreatePythonEntryPointAction.create_actions.<locals>.this_triplet  sC    (=o(N%'C'E&Fay$Q!%5%(&$66rW   c              3   @   K   | ]  } g |         y wrP   ru   )rg   ep_defr   rK   r   rU  rJ   s     rU   rj   z>CreatePythonEntryPointAction.create_actions.<locals>.<genexpr>  s8        ' ! "&)	s   ru   c              3   P   K   | ]  }t         j                  |        y wrP   )r   r   )rg   rW  rK   r   r   rJ   s     rU   rj   z>CreatePythonEntryPointAction.create_actions.<locals>.<genexpr>  s5      	!  #OO+$%+	!s   #&)r   r   r   r:   r   r   entry_pointsr   )r   rJ   rK   r   r   r   actionsrU  s   `````  @rU   r  z+CreatePythonEntryPointAction.create_actions  s     ..W<3P3P3W3W&++1B1B"B7   %117R G 5 	! #)"5"5";	! 	 	 NrW   c                     t         |   ||d d ||       || _        || _        t        rt
        j                  }nt
        j                  }t        | j                  |      | _
        d| _        y r&  )r   r   rS  rT  r   r;   !windows_python_entry_point_scriptunix_python_entry_pointr@   r   r   r   )	rT   rJ   rK   r   r   rS  rT  r   rn   s	           rU   r   z%CreatePythonEntryPointAction.__init__  sp     		
 	 BBI 88I *((!

 $) rW   c                 \   t         j                  t        d| j                         t        rd }nK| j                  d   }t        |      }t        t        j                  xs | j                  t        |            }t        | j                  || j                  | j                         d| _        y )Nzcreating python entry point %sr  T)r   r   rz   r   rJ   r   r   r   r   r   r   r*   rS  rT  r   )rT   rC  r  rB  s       rU   rY   z$CreatePythonEntryPointAction.execute>  s    79N9NO#$($<$<=T$U! 56K L#..D$2D2D-. 
 	"!!#3T[[$))	
 $( rW   c                     | j                   r;t        j                  t        d| j                         t	        | j                         y y )Nz(reversing python entry point creation %s)r   r   r   rz   r/   rS   s    rU   r\   z$CreatePythonEntryPointAction.reverseO  s:    ##GGA4CXCX $''(	 $rW   r  r   s   @rU   rO  rO    s%    % %N)>(")rW   rO  c                   :     e Zd Zed        Z fdZd Zd Z xZS )CreatePrefixRecordActionc           	      T    |j                   }dt        |      z  } | |||||||      fS )Nzconda-meta/%s.json)r   r	   )	r   rJ   rK   r   r   requested_specall_link_path_actionsr   r   s	            rU   r  z'CreatePrefixRecordAction.create_actionsZ  sH     !- B B08<Q3RR#!#%

 
	
rW   c                 x    t         |   ||d d ||       || _        || _        t	        |      | _        d| _        y r   )r   r   r   rc  listrd  r   )	rT   rJ   rK   r   r   r   rc  rd  rn   s	           rU   r   z!CreatePrefixRecordAction.__init__r  sL     		
 $7 ,%)*?%@"#( rW   c                 "   t        | j                  j                  | j                        }| j                  j                  }| j                  j                  }d d t        t        j                  fd| j                  D                    }t        dt        j                  fd| j                  D                    }t        j                  | j                  j                  | j                  j                  t        | j                        |||| j                  j                   ||	      | _        t$        j%                  t&        d	| j(                         t+        | j,                        j/                  | j"                         d
| _        y )N)sourcer   c                     t        | t              r| j                  S t        | t              r6t	        | d      r| j
                  t        j                  k7  r| j                  fS dS )Nr   ru   )	
isinstancer  r   r   hasattrr   r9   r   r   link_path_actions    rU   files_from_actionz;CreatePrefixRecordAction.execute.<locals>.files_from_action  sd    *,AB'::: ""24LM#$4kB+559K9KK	 &779 rW   c                     t        | t              r| j                  S t        | d      r| j                  y| j                  fS )Nr   ru   )rj  r  r)  rk  r   rl  s    rU   paths_from_actionz;CreatePrefixRecordAction.execute.<locals>.paths_from_action  sF    *,AB'999   02DE'88@,==??rW   c              3   4   K   | ]  }|s |        y wrP   ru   )rg   xrn  s     rU   rj   z3CreatePrefixRecordAction.execute.<locals>.<genexpr>  s       )*A!!$    rC   c              3   4   K   | ]  }|s |        y wrP   ru   )rg   rr  rp  s     rU   rj   z3CreatePrefixRecordAction.execute.<locals>.<genexpr>  s      &)*A!!$&rs  )paths_versionr   )rc  r   fileslinkurlr   package_tarball_full_pathz!creating linked package record %sT)r=   rK   r   r   ry  rf  r   from_iterablerd  rA   rB   r   r   r   r   rc  rx  prefix_recordr   r   rz   rI   r   insertr   )rT   rw  r   ry  rv  r   rn  rp  s         @@rU   rY   z CreatePrefixRecordAction.execute  sR   $$::))
 !% 1 1 G G$($5$5$O$O!	
	@   .2.H.H  

 %% &.2.H.H& 

 *66--..t223!!!%%"7&?
 	:D<Q<QR4%%&--d.@.@A#' rW   c                     t         j                  t        d| j                         | j                  rCt	        | j
                        j                  | j                  j                  j                         y y )Nz+reversing linked package record creation %s)
r   r   rz   r   rI   r   r  rK   r   r   rS   s    rU   r\   z CreatePrefixRecordAction.reverse  sZ    @$BWBW	
 ##t))*11!!1166 $rW   r  r   s   @rU   ra  ra  W  s'     
 
.).=(~rW   ra  c                   @     e Zd Zed        Z fdZd Zd Zd Z xZ	S )UpdateHistoryActionc                 6    t        dd      } | ||||||      fS )Nz
conda-metahistory)r   )r   rJ   r   remove_specsupdate_specsneutered_specsr   s          rU   r  z"UpdateHistoryAction.create_actions  s5     !y9#!	
 		
rW   c                     t         |   |d d d ||       || _        || _        || _        | j
                  t        z   | _        y rP   )r   r   r  r  r  rz   r   rL   )rT   rJ   r   r   r  r  r  rn   s          rU   r   zUpdateHistoryAction.__init__  sM     	tT=BS	
 )(,..1EErW   c                 d   t         j                  t        d| j                         t        | j                        r t	        | j                  | j
                         t        | j                        }|j                          |j                  | j                  | j                  | j                         y )Nzupdating environment history %s)r   r   rz   r3   r'   rL   r7   r   rI  write_specsr  r  r  )rT   hs     rU   rY   zUpdateHistoryAction.execute  sv    8$:O:OP4(()&&7D&&'	
	d''):):D<O<OPrW   c                     t        | j                        rSt        j                  t        d| j                  | j                         t        | j                  | j                  d       y y Nmoving %s => %sTr   r3   rL   r   r   rz   r5   rS   s    rU   r\   zUpdateHistoryAction.reverse  F    4>>"GGE,dnnd>S>ST4>>4+@+@M #rW   c                 .    t        | j                         y rP   r/   rL   rS   s    rU   r^   zUpdateHistoryAction.cleanup	      dnnrW   
ro   rr   rs   r   r  r   rY   r\   r^   r   r   s   @rU   r  r    s,    
 
(F$QN
rW   r  c                   :    e Zd Zd Zd Zd Zd Zd Zed        Z	y)!RegisterEnvironmentLocationActionc                 .    || _         || _        d| _        y r   rJ   r   r   rT   rJ   r   s      rU   r   z*RegisterEnvironmentLocationAction.__init__      #6 *#( rW   c                     t               }	 t        |dd       d| _        y # t        $ r t        j                  d|       Y y w xY w)NT)mkdir	sudo_safezRUnable to create environments file. Path not writable.
  environment location: %s
)rD   r6   ra   r"   r   warn)rT   user_environments_txt_files     rU   rV   z(RegisterEnvironmentLocationAction.verify  sG    %C%E"	,DDI!DN 	HH/*	s   " AAc                     t         j                  t        d| j                         t        | j                         d| _        y )Nz%registering environment in catalog %sT)r   r   r   rE   r   rS   s    rU   rY   z)RegisterEnvironmentLocationAction.execute   s/    >@R@RST''(#' rW   c                      y rP   ru   rS   s    rU   r\   z)RegisterEnvironmentLocationAction.reverse&      rW   c                      y rP   ru   rS   s    rU   r^   z)RegisterEnvironmentLocationAction.cleanup)  r  rW   c                     t               rP   rQ   rS   s    rU   rz   z2RegisterEnvironmentLocationAction.target_full_path,  rZ   rW   N
ro   rr   rs   r   rV   rY   r\   r^   rt   rz   ru   rW   rU   r  r    s/    )
( $ $rW   r  c                   $     e Zd Z fdZd Z xZS )RemoveFromPrefixPathActionc                 6    t         |   |||       || _        y rP   )r   r   linked_package_datarT   rJ   r  r   r   rn   s        rU   r   z#RemoveFromPrefixPathAction.__init__7  s      	,m=NO#6 rW   c                     d| _         y r   r`   rS   s    rU   rV   z!RemoveFromPrefixPathAction.verify=  s     rW   )ro   rr   rs   r   rV   r   r   s   @rU   r  r  6  s    7rW   r  c                   H     e Zd Zej                  f fd	Zd Zd Zd Z xZ	S )UnlinkPathActionc                     t         |   ||||       | j                  t        z   | _        | j
                  t        z   | _        || _        y rP   )r   r   r   r   holding_short_pathrz   holding_full_pathr   )rT   rJ   r  r   r   r   rn   s         rU   r   zUnlinkPathAction.__init__D  sN     	!4mEV	
 #'"8"8;O"O!%!6!69M!M"rW   c                     | j                   t        j                  k7  rSt        j                  t        d| j
                  | j                         t        | j                  | j                  d       y y )Nzrenaming %s => %sTr   )
r   r9   r   r   r   r   r  r5   rz   r  rS   s    rU   rY   zUnlinkPathAction.executeS  sX    >>X///GG#&&''	 400$2H2HPTU 0rW   c                    | j                   t        j                  k7  rit        | j                        rSt
        j                  t        d| j                  | j                         t        | j                  | j                  d       y y y )Nzreversing rename %s => %sTr   )r   r9   r   r3   r  r   r   r  r   r5   rz   rS   s    rU   r\   zUnlinkPathAction.reverse]  si    >>X///GD<R<R4SGG+''&&	 41143H3HPTU 5T/rW   c                 ^    t        | j                        st        | j                  d       y y )NTr   )r   r  r/   rS   s    rU   r^   zUnlinkPathAction.cleanupg  s%    T++,$((dC -rW   )
ro   rr   rs   r9   r   r   rY   r\   r^   r   r   s   @rU   r  r  C  s%     ###VVDrW   r  c                   @     e Zd Zed        Z fdZd Zd Zd Z xZ	S )RemoveMenuActionc                 L     t         fdj                  D              S )Nc              3   p   K   | ]-  }t        t        j                  |            r |       / y wrP   )r   r  r  )rg   r   r   r  r   rJ   s     rU   rj   z2RemoveMenuAction.create_actions.<locals>.<genexpr>o  s7      
HNN4() #%8-N
s   36)r   rv  )r   rJ   r  r   s   ````rU   r  zRemoveMenuAction.create_actionsm  s#     
+11
 
 	
rW   c                 *    t         |   ||||       y rP   r   r   r  s        rU   r   zRemoveMenuAction.__init__u       	!4mEV	
rW   c                     t         j                  t        d| j                         t        | j                  | j                  d       y )Nzremoving menu for %s Tr
  r   r   r   r,   r   rS   s    rU   rY   zRemoveMenuAction.execute|  s1    .0B0BC$$$d&<&<TJrW   c                     t         j                  t        d| j                         t        | j                  | j                  d       y )Nzre-creating menu for %s Fr
  r  rS   s    rU   r\   zRemoveMenuAction.reverse  s1    143E3EF$$$d&<&<UKrW   c                      y rP   ru   rS   s    rU   r^   zRemoveMenuAction.cleanup  r  rW   r  r   s   @rU   r  r  l  s+    
 

KLrW   r  c                   2     e Zd Z fdZ fdZ fdZ xZS )RemoveLinkedPackageRecordActionc                 *    t         |   ||||       y rP   r  r  s        rU   r   z(RemoveLinkedPackageRecordAction.__init__  r  rW   c                     t         |           t        | j                        j	                  | j
                  j                         y rP   )r   rY   rI   r   r  r  r   rT   rn   s    rU   rY   z'RemoveLinkedPackageRecordAction.execute  s2    4%%&--d.F.F.K.KLrW   c                 ~    t         |           t        | j                        j	                  | j
                         y rP   )r   r\   rI   r   _load_single_recordrz   r  s    rU   r\   z'RemoveLinkedPackageRecordAction.reverse  s,    4%%&::4;P;PQrW   )ro   rr   rs   r   rY   r\   r   r   s   @rU   r  r    s    
MR RrW   r  c                   :    e Zd Zd Zd Zd Zd Zd Zed        Z	y)#UnregisterEnvironmentLocationActionc                 .    || _         || _        d| _        y r   r  r  s      rU   r   z,UnregisterEnvironmentLocationAction.__init__  r  rW   c                     d| _         y r   r`   rS   s    rU   rV   z*UnregisterEnvironmentLocationAction.verify  r   rW   c                     t         j                  t        d| j                         t        | j                         d| _        y )Nz'unregistering environment in catalog %sT)r   r   r   rF   r   rS   s    rU   rY   z+UnregisterEnvironmentLocationAction.execute  s/    @$BTBTUt))*#' rW   c                      y rP   ru   rS   s    rU   r\   z+UnregisterEnvironmentLocationAction.reverse  r  rW   c                      y rP   ru   rS   s    rU   r^   z+UnregisterEnvironmentLocationAction.cleanup  r  rW   c                     t               rP   rQ   rS   s    rU   rz   z4UnregisterEnvironmentLocationAction.target_full_path  rZ   rW   Nr  ru   rW   rU   r  r    s/    )( $ $rW   r  c                   \    e Zd Z	 	 	 ddZd ZddZ	 ddZddZd Zd Z	e
d	        Zd
 Zy)CacheUrlActionNc                     || _         || _        || _        || _        || _        || _        | j                  t        z   | _        y rP   )	rx  target_pkgs_dirtarget_package_basenamer   sizemd5rz   r   rL   )rT   rx  r  r  r   r  r  s          rU   r   zCacheUrlAction.__init__  sC     .'>$	..1EErW   c                 2    d| j                   vsJ d| _        y )Nz::T)rx  ra   rS   s    rU   rV   zCacheUrlAction.verify  s    488###rW   c                 ~   ddl m}  || j                        }t        j                  t        d| j
                  | j                         t        | j                        rt        | j                         t        | j                        r`| j
                  j                  d      r#| j
                  t        | j                        k(  ry t        | j                  | j                  d       | j
                  j                  d      r)t        | j
                        }| j                  |||       y | j                  ||       y )NrC   PackageCacheDatazcaching url %s => %szfile:/Tr   )package_cache_datar  r  r   r   rx  rz   r3   rL   r/   
startswithr   r5   r   _execute_local_execute_channel)rT   progress_update_callbackr  target_package_cacher   s        rU   rY   zCacheUrlAction.execute  s     	9/0D0DE-txx9N9NO4>>"$..!4(()xx""8,[%%> 2 t44dnnDQ88x(%dhh/K13K !!"68PQrW   c                 $   ddl m} t        |      t        j                  v rt        || j                          |t        |            }|j                  j                  | j                        }|r7t        |t        j                        r|j                  j                  |       y y y t        |d      }| j                  f}|j                  |||      }	|	r&|j                  j                  |	j                         }nd }t#        || j                  t$        j&                  t        j(                         |r6t        |t        j                        r|j                  j                  |       y |j                  j                  | j*                         y )NrC   r  r  )exclude_caches)r   r   )r  r  r
   r   	pkgs_dirsr(   rz   
_urls_dataget_urlr  r   known_subdirsadd_urlr1   r  tarball_file_in_cacher   r)   r9   r'   r   rx  )
rT   r   r  r  r  source_package_cache
origin_urlsource_md5sumr  pc_entrys
             rU   r  zCacheUrlAction._execute_local  sR    	9;7#4#44$[$2G2GH#3GK4H#I 
 .88@@,,J l:w7L7LM$//77
C Nz (U;M"224N'==]> > H 1<<DD22
 "
 %%"--mm	 l:w7L7LM$//77
C$//77ArW   c                 <   i }| j                   | j                   |d<   | j                  r| j                  |d<   n| j                  r| j                  |d<   t        | j                  | j
                  fd|i| |j                  j                  | j                         y )Nr  r   r  r  )r  r   r  r%   rx  rz   r  r  )rT   r  r  kwargss       rU   r  zCacheUrlAction._execute_channel$  s    99 !YYF6N;;#{{F8XX HHF5MHH!!	
 &>	
 		
 	''//9rW   c                     t        | j                        rSt        j                  t        d| j                  | j                         t        | j                  | j                  d       y y r  r  rS   s    rU   r\   zCacheUrlAction.reverse4  r  rW   c                 .    t        | j                         y rP   r  rS   s    rU   r^   zCacheUrlAction.cleanup9  r  rW   c                 B    t        | j                  | j                        S rP   )r   r  r  rS   s    rU   rz   zCacheUrlAction.target_full_path<  s    D(($*F*FGGrW   c                 <    d| j                   d| j                  dS )NzCacheUrlAction<url=, target_full_path=>)rx  rz   rS   s    rU   __str__zCacheUrlAction.__str__@  s$    $TXXL0CDDYDYC\\]^^rW   )NNNrP   )ro   rr   rs   r   rV   rY   r  r  r\   r^   rt   rz   r  ru   rW   rU   r  r    sX     F"R< KO6Bp: N
 H H_rW   r  c                   B    e Zd Zd Zd Zd	dZd Zd Zed        Z	d Z
y)
ExtractPackageActionc                     || _         || _        || _        | j                  t        z   | _        || _        || _        || _        || _	        y rP   )
r   r  target_extracted_dirnamerz   r   rL   record_or_specr   r  r  )rT   r   r  r  r  r   r  r  s           rU   r   zExtractPackageAction.__init__E  sL     !1.(@%..1EE,	rW   c                     d| _         y r   r`   rS   s    rU   rV   zExtractPackageAction.verifyX  r   rW   Nc           	      "   ddl m} t        j                  t        d| j                  | j
                         t        | j
                        rt        | j
                         t        | j                  | j
                  |       	 t        | j
                        }t!        | j"                  t$              r| j"                  j'                  d      }|sJ t)        |t*        j,                        rt/        |      n
t/        d       }t1        |      }| j2                  xs t5        | j                  d      }t7        | j                        }| j8                  "|| j8                  k(  sJ || j8                  f       | j:                  xs t5        | j                  d      }	t=        j>                  ||||||		      }
n t=        j>                  | j"                        }
tA        | j
                  d
d      }tC        ||
        || jD                        }tG        j>                  |
| j                  | j
                        }|jI                  |       y # t        t        t        f$ r1 t        d| j                  z         t        j                  d       Y w xY w)NrC   r  zextracting %s => %s)r  zERROR: Encountered corrupt package tarball at %s. Conda has left it in place. Please report this to the maintainers of the package.rx  r   r  )rx  channelfnr   r  r  infozrepodata_record.json)ry  r   )%r  r  r   r   r   rz   r3   r/   r+   r4   OSErrorr   FileNotFoundErrorprintsysexitrj  r  r<   get_raw_valuer   r   r  r8   r	   r   r1   r   r  r  r?   r   r   r.   r  r>   r|  )rT   r  r  raw_index_jsonrx  r  r  r   r  r  r   repodata_record_pathr  package_cache_records                 rU   rY   zExtractPackageAction.execute[  s@    	9($*?*?AVAV	
 4(()$''(!!!!%=	

	,T-B-BCN d))95%%33E:CJ3  W%:%:; T] 
 #B[[PK0E0Ex$PF4001Dyy$tyy(;4*;;(((Gk$*?*?GC+88O ,88##^O  $!!6+A 
 	2OD/0D0DE1>>&*&;&;"&"7"7 

 	##$89c *;< 	 "$($9$9:
 HHQK	s   I	 	AJJc                 $   t        | j                         t        | j                        rft        j	                  t
        d| j                  | j                         t        | j                         t        | j                  | j                         y y )Nr  )r/   rz   r3   rL   r   r   r5   rS   s    rU   r\   zExtractPackageAction.reverse  s`    d##$4>>"GGE,dnnd>S>ST$''(4>>4+@+@A #rW   c                 .    t        | j                         y rP   r  rS   s    rU   r^   zExtractPackageAction.cleanup  r  rW   c                 B    t        | j                  | j                        S rP   )r   r  r  rS   s    rU   rz   z%ExtractPackageAction.target_full_path  s    D(($*G*GHHrW   c                 <    d| j                   d| j                  dS )Nz&ExtractPackageAction<source_full_path=r  r  )r   rz   rS   s    rU   r  zExtractPackageAction.__str__  s(    78M8M7PPcdhdydyc||}~~rW   rP   )ro   rr   rs   r   rV   rY   r\   r^   rt   rz   r  ru   rW   rU   r  r  D  s:    &E:NB I IrW   r  )rM  r!  r  abcr   r   r   	itertoolsr   jsonr   loggingr   os.pathr	   r
   r   r   r   uuidr   r   r   
auxlib.ishr   base.constantsr   base.contextr   common.compatr   common.constantsr   common.pathr   r   r   r   r   r   r   r   
common.urlr   r   
exceptionsr    r!   r"   r#   r$   gateways.connection.downloadr%   gateways.disk.creater&   r'   r(   r)   r*   r+   r,   r-   r.   gateways.disk.deleter/   gateways.disk.permissionsr0   gateways.disk.readr1   r2   r3   r4   gateways.disk.updater5   r6   r  r7   models.channelr8   models.enumsr9   r:   r;   models.match_specr<   models.recordsr=   r>   r?   r@   rA   rB   envs_managerrD   rE   rF   portabilityrG   rH   prefix_datarI   r  	NameErrorIOErrorro   r   r"  
IGNORECASEr  rf   rN   rx   r}   r   r   r   r   r   r  r  rF  rO  ra  r  r  r  r  r  r  r  r  r  ru   rW   rU   <module>r&     s9   Q 	 
 9 9     ; ;    1 " " $	 	 	 3  4
 
 
 ) 5 N N 8  $ 9 9 )  W V 5 #  2::("--8  I  IF$G $$g $zW 0P/7 P>PG- PGfY(n Y(x'O- 'OT)3 )4l(O l(^
%: 
2^)#; ^)Bx7 xv82 8v!$
 !$R
!1W 
&D1 &DR1 8R&6 R"$* $@H_Z H_Vm: my'    s   
H1 1H<;H<