mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
This commit is contained in:
parent
5db0c94072
commit
3679727939
64 changed files with 1626 additions and 1678 deletions
|
@ -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.
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue