o
     JAfF                     @   s`   	 d dl Z d dl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 G dd dZdS )    N)DistutilsOptionError)utildir_util	file_utilarchive_utildep_utillogc                   @   s0  e Zd Z	 g Zdd Zdd Zdd Zdd Zd	d
 ZdBddZ	dd Z
dCddZdd ZdDddZdDddZdd Z	dDddZdd Zd d! Zd"d# Zd$d% ZdCd&d'ZdEd)d*Zd+d, Zd-d. Zd/d0 ZdFd1d2ZdGd4d5Z		dHd6d7Z		dId8d9ZdCd:d;ZdJd<d=Z		dKd>d?Z 	dLd@dAZ!dS )MCommandc                 C   sd   	 ddl m} t||std| jtu rtd|| _|   d | _	|j
| _
d | _d| _d| _d S )Nr   )Distributionz$dist must be a Distribution instancezCommand is an abstract class)Zdistutils.distr   
isinstance	TypeError	__class__r
   RuntimeErrordistributioninitialize_optionsZ_dry_runverboseforcehelp	finalized)selfdistr    r   $/usr/lib/python3.10/distutils/cmd.py__init__/   s   



zCommand.__init__c                 C   s6   |dkrt | d| }|d u rt | j|S |S t|)Ndry_run_)getattrr   AttributeError)r   attrZmyvalr   r   r   __getattr___   s   zCommand.__getattr__c                 C   s   | j s|   d| _ d S N   )r   finalize_optionsr   r   r   r   ensure_finalizedi   s   
zCommand.ensure_finalizedc                 C      	 t d| j Nz,abstract method -- subclass %s must overrider   r   r$   r   r   r   r   {      	zCommand.initialize_optionsc                 C   r&   r'   r(   r$   r   r   r   r#      s   
zCommand.finalize_optionsN c                 C   s   ddl m} |d u rd|   }| j|| tjd |d }| jD ])\}}}||}|d dkr7|d d }t| |}| j|d||f  tjd q!d S )	Nr   )longopt_xlatezcommand options for '%s':)levelz  =z%s = %s)	Zdistutils.fancy_getoptr+   get_command_nameannouncer	   INFOZuser_options	translater   )r   headerindentr+   optionr   valuer   r   r   dump_options   s   

zCommand.dump_optionsc                 C   r&   r'   r(   r$   r   r   r   run   r)   zCommand.runr"   c                 C   s   	 t  || d S Nr   )r   msgr,   r   r   r   r0      s   zCommand.announcec                 C   s,   	 ddl m} |rt| tj  d S d S )Nr   )DEBUG)Zdistutils.debugr;   printsysstdoutflush)r   r:   r;   r   r   r   debug_print   s   zCommand.debug_printc                 C   sB   t | |}|d u rt| || |S t|tstd|||f |S )Nz'%s' must be a %s (got `%s`))r   setattrr   strr   )r   r5   whatdefaultvalr   r   r   _ensure_stringlike   s   

zCommand._ensure_stringlikec                 C   s   	 |  |d| d S )Nstring)rF   )r   r5   rD   r   r   r   ensure_string   s   zCommand.ensure_stringc                 C   st   	 t | |}|d u rd S t|trt| |td| d S t|tr,tdd |D }nd}|s8td||f d S )Nz,\s*|\s+c                 s   s    | ]}t |tV  qd S r9   )r   rB   ).0vr   r   r   	<genexpr>   s    z-Command.ensure_string_list.<locals>.<genexpr>Fz''%s' must be a list of strings (got %r))	r   r   rB   rA   resplitlistallr   )r   r5   rE   okr   r   r   ensure_string_list   s    


zCommand.ensure_string_listc                 C   s:   |  |||}|d ur||std| ||f d S d S )Nzerror in '%s' option: )rF   r   )r   r5   ZtesterrC   Z	error_fmtrD   rE   r   r   r   _ensure_tested_string   s   zCommand._ensure_tested_stringc                 C   s   	 |  |tjjdd d S )Nfilenamez$'%s' does not exist or is not a file)rR   ospathisfiler   r5   r   r   r   ensure_filename   s
   zCommand.ensure_filenamec                 C   s   |  |tjjdd d S )Nzdirectory namez)'%s' does not exist or is not a directory)rR   rT   rU   isdirrW   r   r   r   ensure_dirname  s   zCommand.ensure_dirnamec                 C   s   t | dr| jS | jjS )Ncommand_name)hasattrr[   r   __name__r$   r   r   r   r/   	  s   
zCommand.get_command_namec                 G   sH   	 | j |}|  |D ]\}}t| |d u r!t| |t|| qd S r9   )r   get_command_objr%   r   rA   )r   Zsrc_cmdZoption_pairsZsrc_cmd_objZ
src_optionZ
dst_optionr   r   r   set_undefined_options  s   zCommand.set_undefined_optionsc                 C   s   	 | j ||}|  |S r9   )r   r^   r%   )r   commandZcreateZcmd_objr   r   r   get_finalized_command$  s   zCommand.get_finalized_commandr   c                 C   s   | j ||S r9   )r   reinitialize_command)r   r`   Zreinit_subcommandsr   r   r   rb   0  s   zCommand.reinitialize_commandc                 C   s   	 | j | d S r9   )r   run_command)r   r`   r   r   r   rc   4  s   zCommand.run_commandc                 C   s4   	 g }| j D ]\}}|d u s|| r|| q|S r9   )sub_commandsappend)r   commandsZcmd_namemethodr   r   r   get_sub_commands;  s   
zCommand.get_sub_commandsc                 C   s   t d|  | d S )Nzwarning: %s: %s
)r	   warnr/   )r   r:   r   r   r   ri   K     zCommand.warnc                 C   s   t j|||| jd d S Nr   )r   executer   )r   funcargsr:   r,   r   r   r   rm   N  s   zCommand.execute  c                 C   s   t j||| jd d S rk   )r   mkpathr   )r   namemoder   r   r   rq   Q  rj   zCommand.mkpathc              	   C   s    	 t j||||| j || jdS rk   )r   	copy_filer   r   )r   infileoutfilepreserve_modepreserve_timeslinkr,   r   r   r   rt   T  s
   

zCommand.copy_filec              	   C   s    	 t j|||||| j | jdS rk   )r   	copy_treer   r   )r   ru   rv   rw   rx   Zpreserve_symlinksr,   r   r   r   rz   ]  s
   

zCommand.copy_treec                 C   s   	 t j||| jdS rk   )r   	move_filer   )r   srcdstr,   r   r   r   r{   f  s   zCommand.move_filec                 C   s"   	 ddl m} |||| jd d S )Nr   )spawnrl   )Zdistutils.spawnr~   r   )r   cmdZsearch_pathr,   r~   r   r   r   r~   j  s   zCommand.spawnc              	   C   s   t j||||| j||dS )N)r   ownergroup)r   make_archiver   )r   	base_nameformatroot_dirbase_dirr   r   r   r   r   r   o  s   zCommand.make_archivec                 C   s   	 |d u r	d| }t |tr|f}nt |ttfstd|d u r*d|d|f }| js3t||r=| 	|||| d S t
| d S )Nzskipping %s (inputs unchanged)z9'infiles' must be a string, or a list or tuple of stringszgenerating %s from %sz, )r   rB   rN   tupler   joinr   r   Znewer_grouprm   r	   debug)r   Zinfilesrv   rn   ro   Zexec_msgZskip_msgr,   r   r   r   	make_fileu  s   
zCommand.make_file)Nr*   )r"   r9   )r   r!   )rp   )r"   r"   Nr"   )r"   r"   r   r"   )r"   r"   )NNNN)NNr"   )"r]   
__module____qualname__rd   r   r    r%   r   r#   r7   r8   r0   r@   rF   rH   rQ   rR   rX   rZ   r/   r_   ra   rb   rc   rh   ri   rm   rq   rt   rz   r{   r~   r   r   r   r   r   r   r
      sR    0











	

	

r
   )r=   rT   rL   Zdistutils.errorsr   Z	distutilsr   r   r   r   r   r	   r
   r   r   r   r   <module>   s    