U iab@spdZddlZddlZddlmZmZddlmZiadddZ dd d Z dd d Z d dZ dddZ ddZdS)zWdistutils.dir_util Utility functions for manipulating directories and directory trees.N)DistutilsFileErrorDistutilsInternalError)logc Csft|tstd|ftj|}g}tj|s<|dkr@|Sttj |rV|Stj |\}}|g}|r|rtj|stj |\}}| d|ql|D]}tj ||}tj |} t| rq|dkrt d||sXzt||WnVtk rL} z6| jtjkr&tj|stk rt} z |rRg} ntd|| jfW5d} ~ XYnX|st ||dg} | D]} tj || } tj || }| drq|r tj | r t | }|dkrtd |||st||| |qtj| r8| t| |||||||d q|| ||||||d | |q| S) aCopy 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'. r) copy_filez&cannot copy tree '%s': not a directoryzerror listing files in '%s': %sN)rz.nfsrzlinking %s -> %sr*)distutils.file_utilr5r r rrlistdirrstrerrorr)r startswithislinkreadlinkrrsymlinkrextend copy_tree)srcdst preserve_modepreserve_timespreserve_symlinksupdaterrr5nameseoutputsnsrc_namedst_name link_destr'r'r(r>cs\        r>cCsft|D]F}tj||}tj|r@tj|s@t||q |tj|fq |tj |fdS)zHelper for remove_tree().N) r r7r rrr:_build_cmdtuplerremovermdir)r cmdtuplesfreal_fr'r'r(rLs  rLc Cs|dkrtd||rdSg}t|||D]h}z2|d|dtj|d}|tkrbt|=Wq.tk r}ztd||W5d}~XYq.Xq.dS)zRecursively remove an entire directory tree. Any errors are ignored (apart from being reported to stdout if 'verbose' is true). rz'removing '%s' (and everything under it)Nrzerror removing %s: %s) rrrLr r rrrwarn) directoryrrrOcmdrr&r'r'r( remove_trees   rUcCs6tj|\}}|ddtjkr2||dd}|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(). rrN)r r splitdrivesep)r driver'r'r(ensure_relativesrY)rrr)rrr)rrrrrr)rr)__doc__r rdistutils.errorsrr distutilsrrr)r4r>rLrUrYr'r'r'r(s   ?  E