î Ôê[Ôã@sœdZddlZddlmZddlmZidd6dd6dd 6Zdd d „Zdddddddd„Zdddd„Z dd„Z dS)zFdistutils.file_util Utility functions for operating on single files. éN)ÚDistutilsFileError)ÚlogZcopyingz hard linkingÚhardzsymbolically linkingÚsyméicNCsd}d}zÊyt|dƒ}Wn>tk rb}ztd||jfƒ‚WYdd}~XnXtjj|ƒrÊytj|ƒWqÊtk rÆ}ztd||jfƒ‚WYdd}~XqÊXnyt|dƒ}Wn>tk r}ztd||jfƒ‚WYdd}~XnXx´y|j|ƒ}Wn>tk rt}ztd||jfƒ‚WYdd}~XnX|sPny|j |ƒWq!tk rÐ}ztd||jfƒ‚WYdd}~Xq!Xq!WWd|rì|j ƒn|rÿ|j ƒnXdS) a5Copy the file 'src' to 'dst'; both must be filenames. Any error opening either file, reading from 'src', or writing to 'dst', raises DistutilsFileError. Data is read/written in chunks of 'buffer_size' bytes (default 16k). No attempt is made to handle anything apart from regular files. NÚrbzcould not open '%s': %szcould not delete '%s': %sÚwbzcould not create '%s': %szcould not read from '%s': %szcould not write to '%s': %s) ÚopenÚOSErrorrÚstrerrorÚosÚpathÚexistsÚunlinkÚreadÚwriteÚclose)ÚsrcÚdstZ buffer_sizeZfsrcZfdstÚeZbuf©rú)/usr/lib/python3.4/distutils/file_util.pyÚ_copy_file_contentssF ,,))1 récCsÄddlm}ddlm} m} m} m} tjj |ƒsWt d|ƒ‚ntjj |ƒr“|} tjj |tjj |ƒƒ}ntjj|ƒ} |rä|||ƒ rä|dkrÚtjd|ƒn|dfSyt|}Wn"tk rtd|ƒ‚YnX|dkrytjj |ƒtjj |ƒkr`tjd||| ƒqytjd|||ƒn|r‰|dfS|d krõtjj|ƒo¹tjj||ƒsEytj||ƒ|dfSWqòtk rîYqòXqEnP|d krEtjj|ƒo%tjj||ƒsEtj||ƒ|dfSnt||ƒ|s^|rºtj|ƒ}|r”tj||| || fƒn|rºtj|| || ƒƒqºn|dfS) aCopy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is copied there with the same name; otherwise, it must be a filename. (If the file exists, it will be ruthlessly clobbered.) If 'preserve_mode' is true (the default), the file's mode (type and permission bits, or whatever is analogous on the current platform) is copied. If 'preserve_times' is true (the default), the last-modified and last-access times are copied as well. If 'update' is true, 'src' will only be copied if 'dst' does not exist, or if 'dst' does exist but is older than 'src'. 'link' allows you to make hard links (os.link) or symbolic links (os.symlink) instead of copying: set it to "hard" or "sym"; if it is None (the default), files are copied. Don't set 'link' on systems that don't support it: 'copy_file()' doesn't check if hard or symbolic linking is available. If hardlink fails, falls back to _copy_file_contents(). Under Mac OS, uses the native file copy function in macostools; on other systems, uses '_copy_file_contents()' to copy file contents. Return a tuple (dest_name, copied): 'dest_name' is the actual name of the output file, and 'copied' is true if the file was copied (or would have been copied, if 'dry_run' true). r)Únewer)ÚST_ATIMEÚST_MTIMEÚST_MODEÚS_IMODEz4can't copy '%s': doesn't exist or not a regular filerz"not copying %s (output up-to-date)z&invalid value '%s' for 'link' argumentz %s %s -> %srr)Zdistutils.dep_utilrÚstatrrrrr r ÚisfilerÚisdirÚjoinÚbasenameÚdirnamerÚdebugÚ _copy_actionÚKeyErrorÚ ValueErrorÚinforÚsamefileÚlinkr ÚsymlinkrÚutimeÚchmod)rrZ preserve_modeZpreserve_timesÚupdater+ÚverboseÚdry_runrrrrrÚdirÚactionÚstrrrÚ copy_fileCsT!"$    $  '   '   ! r5c(Cs%ddlm}m}m}m}m}ddl} |dkrVtjd||ƒn|r`|S||ƒst d|ƒ‚n||ƒr©t j j |||ƒƒ}n%||ƒrÎt d||fƒ‚n|||ƒƒsùt d||fƒ‚nd } yt j ||ƒWnetk rz} zE| j\} } | | jkrOd } nt d ||| fƒ‚WYdd} ~ XnX| r!t||d |ƒyt j|ƒWq!tk r} zV| j\} } yt j|ƒWntk rîYnXt d |||| fƒ‚WYdd} ~ Xq!Xn|S)a%Move a file 'src' to 'dst'. If 'dst' is a directory, the file will be moved into it with the same name; otherwise, 'src' is just renamed to 'dst'. Return the new full name of the file. Handles cross-device moves on Unix using 'copy_file()'. What about other systems??? r)rr r!r#r$Nrzmoving %s -> %sz#can't move '%s': not a regular filez0can't move '%s': destination '%s' already existsz2can't move '%s': destination '%s' not a valid pathFTzcouldn't move '%s' to '%s': %sr0zAcouldn't move '%s' to '%s' by copy/delete: delete '%s' failed: %s)Úos.pathrr r!r#r$Úerrnorr)rr r r"Úrenamer ÚargsZEXDEVr5r)rrr0r1rr r!r#r$r7Zcopy_itrZnumÚmsgrrrÚ move_file¦sR (      ) ,r;c CsGt|dƒ}z&x|D]}|j|dƒqWWd|jƒXdS)z{Create a file with the specified name and write 'contents' (a sequence of strings without line terminators) to it. ÚwÚ N)r rr)ÚfilenameÚcontentsÚfÚlinerrrÚ write_fileås  rBi@) Ú__doc__r Zdistutils.errorsrZ distutilsrr&rr5r;rBrrrrÚs   3 c=