a
    zeF                     @   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                   @   s  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dEddZdd ZdFddZdd Zd d! Zd"d# Zd$d% ZdGd&d'ZdHd)d*Zd+d, Zd-d. Zd/d0 ZdId1d2ZdJd4d5ZdKd6d7ZdLd8d9ZdMd:d;ZdNd<d=ZdOd>d?Z dPd@dAZ!dS )QCommandc                 C   sb   ddl m} t||std| jtu r0t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.9/distutils/cmd.py__init__/   s    


zCommand.__init__c                 C   s<   |dkr0t | d| }|d u r*t | j|S |S nt|d S )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   s   t d| j d S Nz,abstract method -- subclass %s must overrider   r   r#   r   r   r   r   {   s    
zCommand.initialize_optionsc                 C   s   t d| j d S 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 ]R\}}}||}|d dkrn|d d }t| |}| j|d||f  tjd qBd 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   s   t d| j d S r%   r&   r#   r   r   r   run   s    
zCommand.runr!   c                 C   s   t  || d S Nr   )r   msgr)   r   r   r   r-      s    zCommand.announcec                 C   s&   ddl m} |r"t| tj  d S )Nr   )DEBUG)Zdistutils.debugr8   printsysstdoutflush)r   r7   r8   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   r2   whatdefaultvalr   r   r   _ensure_stringlike   s    

zCommand._ensure_stringlikec                 C   s   |  |d| d S )Nstring)rC   )r   r2   rA   r   r   r   ensure_string   s    zCommand.ensure_stringc                 C   sp   t | |}|d u rd S t|tr6t| |td| n6t|trTtdd |D }nd}|sltd||f d S )Nz,\s*|\s+c                 s   s   | ]}t |tV  qd S r6   )r   r?   ).0vr   r   r   	<genexpr>       z-Command.ensure_string_list.<locals>.<genexpr>Fz''%s' must be a list of strings (got %r))	r   r   r?   r>   resplitlistallr   )r   r2   rB   okr   r   r   ensure_string_list   s    


zCommand.ensure_string_listc                 C   s6   |  |||}|d ur2||s2td| ||f d S )Nzerror in '%s' option: )rC   r   )r   r2   Ztesterr@   Z	error_fmtrA   rB   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)rP   ospathisfiler   r2   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)rP   rR   rS   isdirrU   r   r   r   ensure_dirname  s    zCommand.ensure_dirnamec                 C   s   t | dr| jS | jjS d S )Ncommand_name)hasattrrY   r   __name__r#   r   r   r   r,   	  s    
zCommand.get_command_namec                 G   sF   | j |}|  |D ](\}}t| |d u rt| |t|| qd S r6   )r   get_command_objr$   r   r>   )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 r6   )r   r\   r$   )r   commandZcreateZcmd_objr   r   r   get_finalized_command$  s    zCommand.get_finalized_commandr   c                 C   s   | j ||S r6   )r   reinitialize_command)r   r^   Zreinit_subcommandsr   r   r   r`   0  s    zCommand.reinitialize_commandc                 C   s   | j | d S r6   )r   run_command)r   r^   r   r   r   ra   4  s    zCommand.run_commandc                 C   s2   g }| j D ]"\}}|d u s"|| r
|| q
|S r6   )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   r7   r   r   r   rg   K  s    zCommand.warnc                 C   s   t j|||| jd d S Nr   )r   executer   )r   funcargsr7   r)   r   r   r   rj   N  s    zCommand.execute  c                 C   s   t j||| jd d S rh   )r   mkpathr   )r   namemoder   r   r   rn   Q  s    zCommand.mkpathc              	   C   s   t j||||| j || jdS rh   )r   	copy_filer   r   )r   infileoutfilepreserve_modepreserve_timeslinkr)   r   r   r   rq   T  s    

zCommand.copy_filec              	   C   s   t j|||||| j | jdS rh   )r   	copy_treer   r   )r   rr   rs   rt   ru   Zpreserve_symlinksr)   r   r   r   rw   ]  s    

zCommand.copy_treec                 C   s   t j||| jdS rh   )r   	move_filer   )r   srcdstr)   r   r   r   rx   f  s    zCommand.move_filec                 C   s    ddl m} |||| jd d S )Nr   )spawnri   )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s8td|d u rRd|d|f }| jsdt||rv| 	|||| n
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   r?   rL   tupler   joinr   r   Znewer_grouprj   r	   debug)r   Zinfilesrs   rk   rl   Zexec_msgZskip_msgr)   r   r   r   	make_fileu  s    

zCommand.make_file)Nr'   )r!   )N)N)N)r!   )r   )Nr!   )rm   )r!   r!   Nr!   )r!   r!   r   r!   )r!   )r!   r!   )NNNN)NNr!   )"r[   
__module____qualname__rb   r   r    r$   r   r"   r4   r5   r-   r=   rC   rE   rO   rP   rV   rX   r,   r]   r_   r`   ra   rf   rg   rj   rn   rq   rw   rx   r{   r   r   r   r   r   r   r
      sN   0





 




  
	  
	

  
 r
   )r:   rR   rJ   Zdistutils.errorsr   Z	distutilsr   r   r   r   r   r	   r
   r   r   r   r   <module>   s   