summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/file_util.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2010-07-22 12:50:05 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2010-07-22 12:50:05 (GMT)
commit3679727939a9d25ccfe057e71e8a4b8be73d47ce (patch)
tree88326b8ec80cf57f51d2e093143e233ec4ce1be5 /Lib/distutils/file_util.py
parent5db0c94072abad10c9d2df99eefd1f51eb84f2bc (diff)
downloadcpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.zip
cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.gz
cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.bz2
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Diffstat (limited to 'Lib/distutils/file_util.py')
-rw-r--r--Lib/distutils/file_util.py58
1 files changed, 33 insertions, 25 deletions
diff --git a/Lib/distutils/file_util.py b/Lib/distutils/file_util.py
index 3a71bfd..65aa7e0 100644
--- a/Lib/distutils/file_util.py
+++ b/Lib/distutils/file_util.py
@@ -10,18 +10,17 @@ from distutils.errors import DistutilsFileError
from distutils import log
# for generating verbose output in 'copy_file()'
-_copy_action = {None: 'copying',
- 'hard': 'hard linking',
- 'sym': 'symbolically linking'}
+_copy_action = { None: 'copying',
+ 'hard': 'hard linking',
+ 'sym': 'symbolically linking' }
def _copy_file_contents(src, dst, buffer_size=16*1024):
- """Copy 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.
+ """Copy 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.
"""
# Stolen from shutil module in the standard library, but with
# custom error-handling added.
@@ -69,16 +68,15 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):
def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
link=None, verbose=1, dry_run=0):
- """Copy 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'.
+ """Copy 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
@@ -132,6 +130,15 @@ def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
if dry_run:
return (dst, 1)
+ # On Mac OS, use the native file copy routine
+ if os.name == 'mac':
+ import macostools
+ try:
+ macostools.copy(src, dst, 0, preserve_times)
+ except os.error as exc:
+ raise DistutilsFileError(
+ "could not copy '%s' to '%s': %s" % (src, dst, exc.args[-1]))
+
# If linking (hard or symbolic), use the appropriate system call
# (Unix only, of course, but that's the caller's responsibility)
elif link == 'hard':
@@ -159,12 +166,13 @@ def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
# XXX I suspect this is Unix-specific -- need porting help!
-def move_file(src, dst, verbose=1, dry_run=0):
- """Move a file 'src' to 'dst'.
+def move_file (src, dst,
+ verbose=1,
+ dry_run=0):
- 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.
+ """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???
@@ -221,7 +229,7 @@ def move_file(src, dst, verbose=1, dry_run=0):
return dst
-def write_file(filename, contents):
+def write_file (filename, contents):
"""Create a file with the specified name and write 'contents' (a
sequence of strings without line terminators) to it.
"""