
    wgD                     \   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
mZ  G d de      Z e       j                  Zej                   edd	ej"                  d
dfd              Zej&                  d	efd       Zej&                  dd       ZddZ	 	 	 	 	 	 ddZd Zd ZddZd Zy)zWdistutils.dir_util

Utility functions for manipulating directories and directory trees.    N   )	file_util)log)DistutilsFileErrorDistutilsInternalErrorc                   8     e Zd ZdZd Ze fd       Zd Z xZS )SkipRepeatAbsolutePathsz
    Cache for mkpath.

    In addition to cheapening redundant calls, eliminates redundant
    "creating /foo/bar/baz" messages in dry-run mode.
    c                     | t         _        y N)r	   instance)selfs    c/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/setuptools/_distutils/dir_util.py__init__z SkipRepeatAbsolutePaths.__init__   s    +/(    c                 6    t         | | j                            y r   )superr   clear)cls	__class__s    r   r   zSkipRepeatAbsolutePaths.clear   s    c3<<&(r   c                 F     t        j                         fd       }|S )Nc                     | j                         v ry  | g|i |}j                  | j                                |S r   )absoluteadd)pathargskwargsresultfuncr   s       r   wrapperz-SkipRepeatAbsolutePaths.wrap.<locals>.wrapper   s?    }}$&$000FHHT]]_%Mr   )	functoolswraps)r   r   r   s   `` r   wrapzSkipRepeatAbsolutePaths.wrap   s%    			 
	 r   )	__name__
__module____qualname____doc__r   classmethodr   r"   __classcell__)r   s   @r   r	   r	      s&    0 ) )	r   r	   namereturnc                     |r&| j                         st        j                  d|        	 |xs | j                  |dd       y y# t        $ r#}t        d|  d|j                  d          d}~ww xY w)a  Create a directory and any missing ancestor directories.

    If the directory already exists (or if 'name' is the empty string, which
    means the current directory, which of course exists), then do nothing.
    Raise DistutilsFileError if unable to create some directory along the way
    (eg. some sub-path exists, but is a file rather than a directory).
    If 'verbose' is true, log the directory created.
    zcreating %sT)modeparentsexist_okzcould not create '': N)is_dirr   infomkdirOSErrorr   r   )r)   r,   verbosedry_runexcs        r   mkpathr8   .   sp     t{{}%OE4::4:EE O #5dV3sxx|n!MNNOs   A A 	A1A,,A1c                 F    t        t        j                  |       g|i |S r   )r8   pathlibPathr)   r   r   s      r   _r=   B   s     ',,t$6t6v66r   c                      t        d| d      )z.
    Detect a common bug -- name is None.
    z%mkpath: 'name' must be a string (got ))r   r<   s      r   r=   r=   G   s    
 !#HPQ!R
SSr   c                 l     t         fd|D              }t        |      D ]  }t        ||||        y)a  Create all the empty directories under 'base_dir' needed to put 'files'
    there.

    'base_dir' is just the name of a directory which doesn't necessarily
    exist yet; 'files' is a list of filenames to be interpreted relative to
    'base_dir'.  'base_dir' + the directory portion of every file in 'files'
    will be created if it doesn't already exist.  'mode', 'verbose' and
    'dry_run' flags are as for 'mkpath()'.
    c              3      K   | ]A  }t         j                  j                  t         j                  j                  |             C y wr   )osr   joindirname).0filebase_dirs     r   	<genexpr>zcreate_tree.<locals>.<genexpr>Z   s-     ST277<<"''//$*?@Ss   AA
r5   r6   N)setsortedr8   )rG   filesr,   r5   r6   need_dirdirs   `      r   create_treerO   O   s9     SUSSH h <sD'7;<r   c                    |s.t         j                  j                  |       st        d|  d      	 t        j                  |       }|st        ||       t        j                  t        | |||||||	      }
t        t        j                  j                  t        |
|                  S # t
        $ r*}	|rg }nt        d|  d|	j                         Y d}	~	d}	~	ww xY w)a  Copy an entire directory tree 'src' to a new location 'dst'.

    Both 'src' and 'dst' must be directory names.  If 'src' is not a
    directory, raise DistutilsFileError.  If 'dst' does not exist, it is
    created with 'mkpath()'.  The end result of the copy is that every
    file in 'src' is copied to 'dst', and directories under 'src' are
    recursively copied to 'dst'.  Return the list of files that were
    copied or might have been copied, using their output name.  The
    return value is unaffected by 'update' or 'dry_run': it is simply
    the list of all files under 'src', with the names changed to be
    under 'dst'.

    'preserve_mode' and 'preserve_times' are the same as for
    'copy_file'; note that they only apply to regular files, not to
    directories.  If 'preserve_symlinks' is true, symlinks will be
    copied as symlinks (on platforms that support them!); otherwise
    (the default), the destination of the symlink will be copied.
    'update' and 'verbose' are the same as for 'copy_file'.
    zcannot copy tree 'z': not a directoryzerror listing files in 'r/   N)r5   )srcdstpreserve_symlinksr5   r6   preserve_modepreserve_timesupdate)rB   r   isdirr   listdirr4   strerrorr8   r    partial	_copy_onelist	itertoolschainfrom_iterablemap)rQ   rR   rT   rU   rS   rV   r5   r6   namesecopy_ones              r   	copy_treerd   a   s    : 277==- #5cU:L!MNNV

3 sG$  +#%
H 	--c(E.BCDD)  VE$'?uC

|%TUU Vs   B* *	C3 CCc          
   #   H  K   t         j                  j                  ||       }	t         j                  j                  ||       }
| j                  d      ry |rmt         j                  j	                  |	      rNt        j
                  |	      }|dk\  rt        j                  d|
|       |st        j                  ||
       |
 y t         j                  j                  |	      rt        |	|
||||||      E d {    y t        j                  |	|
|||||       |
 y 7 &w)Nz.nfsr   zlinking %s -> %srI   )rB   r   rC   
startswithislinkreadlinkr   r2   symlinkrW   rd   r   	copy_file)r)   rQ   rR   rS   r5   r6   rT   rU   rV   src_namedst_name	link_dests               r   r[   r[      s      ww||C&Hww||C&HvRWW^^H5KK)	a<HH'9=JJy(+	x	 	
 		
 		
 		
 )		
s   C7D"9D :'D"c                    t        j                  |       D ]  }t         j                  j                  | |      }t         j                  j	                  |      r,t         j                  j                  |      st        ||       n|j                  t         j                  |f        |j                  t         j                  | f       y)zHelper for remove_tree().N)
rB   rX   r   rC   rW   rg   _build_cmdtupleappendremovermdir)r   	cmdtuplesfreal_fs       r   ro   ro      s    ZZ 2dA&77== )?FI.bii012 bhh%&r   c                 
   |dk\  rt        j                  d|        |ryg }t        | |       |D ]%  }	  |d   |d          t        j	                          ' y# t
        $ r!}t        j                  d| |       Y d}~Nd}~ww xY w)zRecursively remove an entire directory tree.

    Any errors are ignored (apart from being reported to stdout if 'verbose'
    is true).
    r   z'removing '%s' (and everything under it)Nr   zerror removing %s: %s)r   r2   ro   r	   r   r4   warning)	directoryr5   r6   rs   cmdr7   s         r   remove_treerz      s     !|:IFIIy) A	ACF3q6N#))+	A
  	AKK/C@@	As   "A	B!A==Bc                     t         j                  j                  |       \  }} | dd t         j                  k(  r|| dd z   } | S )zTake the full path 'path', and make it a relative path.

    This is useful to make 'path' the second argument to os.path.join().
    r   r   N)rB   r   
splitdrivesep)r   drives     r   ensure_relativer      sC    
 ''$$T*KE4AayBFFtABxKr   )i  TF)r)   N)TTFFTF)TF)r&   r    r]   rB   r:    r   _logr   errorsr   r   rJ   r	   r"   r   singledispatchr;   r8   registerstrr=   rO   rd   r[   ro   rz   r    r   r   <module>r      s   G   	    >c 8 "
#
(
( O O4 O 	 O$ 7C 7 7 T T<* 5Ep0f'A*r   