[ @sdZddlZddlZddlmZmZddlmZiadddddZ dddd d Z ddl Z dZ ddddddd d Z d dZddddZddZdS)zWdistutils.dir_util Utility functions for manipulating directories and directory trees.N)DistutilsFileErrorDistutilsInternalError)logic Cst|ts%td|fntjj|}g}tjj|s[|dkr_|Stjtjj |r~|Stjj |\}}|g}xK|r|rtjj| rtjj |\}}|j d|qWx |D]}tjj ||}tjj |} tj| r6qn|dkrUt jd|n|sytj||Wnitk r} zI| jtjkotjj|std|| jdfnWYdd} ~ XnX|j|ndt|  "  $0r%cCsvt}x6|D].}|jtjj|tjj|qWx-t|D]}t||d|d|qOWdS)aCreate 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()'. rrN)setaddr r rdirnamesortedr%)Zbase_dirZfilesrrrZneed_dirfiledirr#r#r$ create_treePs  ,r,cCsddlm}| r=tjj| r=td|nytj|} WnMtk r} z-|rtg} ntd|| jfWYdd} ~ XnXt j d} d| ddt | ddf} |st |d |ng} x| D]}tjj ||}tjj ||}t r|j| r|j|  rtjj ||j| | }tjd ||j| | n|jd rqn|rtjj|rtj|}|d krtjd ||n|s tj||n| j|qtjj|r^| jt||||||d |d|q||||||d |d|| j|qW| 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': %sNZ EXT_SUFFIXz%s-%s%srzrenaming extension %s -> %sz.nfsrzlinking %s -> %srr/)Zdistutils.file_utilr-r r r rlistdirrstrerror sysconfigZget_config_var _multiarchr%rendswithreplacerr startswithislinkreadlinksymlinkrextend copy_tree)srcZdstZ preserve_modeZpreserve_timesZpreserve_symlinksupdaterrr-nameseZ ext_suffixZ new_suffixZoutputsnZsrc_nameZdst_nameZ link_destr#r#r$r;fsR )' %!"    r;cCsxwtj|D]f}tjj||}tjj|r`tjj| r`t||q|jtj|fqW|jtj |fdS)zHelper for remove_tree().N) r r0r rr r7_build_cmdtuplerremovermdir)r cmdtuplesfZreal_fr#r#r$rAs %rAcCs|dkrtjd|n|r)dSg}t||x|D]}yB|d|dtjj|d}|tkrt|=nWqCtk r}ztjd||WYdd}~XqCXqCWdS)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) rrrAr r rrrwarn)Z directoryrrrDcmdrr"r#r#r$ remove_trees    rHcCsLtjj|\}}|ddtjkrH||dd}n|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 Zdriver#r#r$ensure_relativesrK)__doc__r rZdistutils.errorsrrZ distutilsrrr%r,r2r3r;rArHrKr#r#r#r$s  ? J