Commit 9e3dc4e9 authored by Greg Ward's avatar Greg Ward

Reformat docstrings.

Standardize use of whitespace on function calls.
parent 4a751580
...@@ -18,11 +18,11 @@ _copy_action = { None: 'copying', ...@@ -18,11 +18,11 @@ _copy_action = { None: 'copying',
def _copy_file_contents (src, dst, buffer_size=16*1024): def _copy_file_contents (src, dst, buffer_size=16*1024):
"""Copy the file 'src' to 'dst'; both must be filenames. Any error """Copy the file 'src' to 'dst'; both must be filenames. Any error
opening either file, reading from 'src', or writing to 'dst', opening either file, reading from 'src', or writing to 'dst', raises
raises DistutilsFileError. Data is read/written in chunks of DistutilsFileError. Data is read/written in chunks of 'buffer_size'
'buffer_size' bytes (default 16k). No attempt is made to handle bytes (default 16k). No attempt is made to handle anything apart from
anything apart from regular files.""" regular files.
"""
# Stolen from shutil module in the standard library, but with # Stolen from shutil module in the standard library, but with
# custom error-handling added. # custom error-handling added.
...@@ -43,7 +43,7 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): ...@@ -43,7 +43,7 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
while 1: while 1:
try: try:
buf = fsrc.read (buffer_size) buf = fsrc.read(buffer_size)
except os.error, (errno, errstr): except os.error, (errno, errstr):
raise DistutilsFileError, \ raise DistutilsFileError, \
"could not read from '%s': %s" % (src, errstr) "could not read from '%s': %s" % (src, errstr)
...@@ -74,31 +74,29 @@ def copy_file (src, dst, ...@@ -74,31 +74,29 @@ def copy_file (src, dst,
verbose=0, verbose=0,
dry_run=0): dry_run=0):
"""Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' """Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is
is copied there with the same name; otherwise, it must be a copied there with the same name; otherwise, it must be a filename. (If
filename. (If the file exists, it will be ruthlessly clobbered.) the file exists, it will be ruthlessly clobbered.) If 'preserve_mode'
If 'preserve_mode' is true (the default), the file's mode (type is true (the default), the file's mode (type and permission bits, or
and permission bits, or whatever is analogous on the current whatever is analogous on the current platform) is copied. If
platform) is copied. If 'preserve_times' is true (the default), 'preserve_times' is true (the default), the last-modified and
the last-modified and last-access times are copied as well. If last-access times are copied as well. If 'update' is true, 'src' will
'update' is true, 'src' will only be copied if 'dst' does not only be copied if 'dst' does not exist, or if 'dst' does exist but is
exist, or if 'dst' does exist but is older than 'src'. If older than 'src'. If 'verbose' is true, then a one-line summary of the
'verbose' is true, then a one-line summary of the copy will be copy will be printed to stdout.
printed to stdout.
'link' allows you to make hard links (os.link) or symbolic links '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 (os.symlink) instead of copying: set it to "hard" or "sym"; if it is
is None (the default), files are copied. Don't set 'link' on None (the default), files are copied. Don't set 'link' on systems that
systems that don't support it: 'copy_file()' doesn't check if don't support it: 'copy_file()' doesn't check if hard or symbolic
hard or symbolic linking is available. linking is available.
Under Mac OS, uses the native file copy function in macostools;
on other systems, uses '_copy_file_contents()' to copy file
contents.
Return the name of the destination file, whether it was actually Under Mac OS, uses the native file copy function in macostools; on
copied or not.""" other systems, uses '_copy_file_contents()' to copy file contents.
Return the name of the destination file, whether it was actually copied
or not.
"""
# XXX if the destination file already exists, we clobber it if # XXX if the destination file already exists, we clobber it if
# copying, but blow up if linking. Hmmm. And I don't know what # copying, but blow up if linking. Hmmm. And I don't know what
# macostools.copyfile() does. Should definitely be consistent, and # macostools.copyfile() does. Should definitely be consistent, and
...@@ -109,17 +107,17 @@ def copy_file (src, dst, ...@@ -109,17 +107,17 @@ def copy_file (src, dst,
from stat import * from stat import *
from distutils.dep_util import newer from distutils.dep_util import newer
if not os.path.isfile (src): if not os.path.isfile(src):
raise DistutilsFileError, \ raise DistutilsFileError, \
"can't copy '%s': doesn't exist or not a regular file" % src "can't copy '%s': doesn't exist or not a regular file" % src
if os.path.isdir (dst): if os.path.isdir(dst):
dir = dst dir = dst
dst = os.path.join (dst, os.path.basename (src)) dst = os.path.join(dst, os.path.basename(src))
else: else:
dir = os.path.dirname (dst) dir = os.path.dirname(dst)
if update and not newer (src, dst): if update and not newer(src, dst):
if verbose: if verbose:
print "not copying %s (output up-to-date)" % src print "not copying %s (output up-to-date)" % src
return dst return dst
...@@ -142,7 +140,7 @@ def copy_file (src, dst, ...@@ -142,7 +140,7 @@ def copy_file (src, dst,
if os.name == 'mac': if os.name == 'mac':
import macostools import macostools
try: try:
macostools.copy (src, dst, 0, preserve_times) macostools.copy(src, dst, 0, preserve_times)
except os.error, exc: except os.error, exc:
raise DistutilsFileError, \ raise DistutilsFileError, \
"could not copy '%s' to '%s': %s" % (src, dst, exc[-1]) "could not copy '%s' to '%s': %s" % (src, dst, exc[-1])
...@@ -150,25 +148,25 @@ def copy_file (src, dst, ...@@ -150,25 +148,25 @@ def copy_file (src, dst,
# If linking (hard or symbolic), use the appropriate system call # If linking (hard or symbolic), use the appropriate system call
# (Unix only, of course, but that's the caller's responsibility) # (Unix only, of course, but that's the caller's responsibility)
elif link == 'hard': elif link == 'hard':
if not (os.path.exists (dst) and os.path.samefile (src, dst)): if not (os.path.exists(dst) and os.path.samefile(src, dst)):
os.link (src, dst) os.link(src, dst)
elif link == 'sym': elif link == 'sym':
if not (os.path.exists (dst) and os.path.samefile (src, dst)): if not (os.path.exists(dst) and os.path.samefile(src, dst)):
os.symlink (src, dst) os.symlink(src, dst)
# Otherwise (non-Mac, not linking), copy the file contents and # Otherwise (non-Mac, not linking), copy the file contents and
# (optionally) copy the times and mode. # (optionally) copy the times and mode.
else: else:
_copy_file_contents (src, dst) _copy_file_contents(src, dst)
if preserve_mode or preserve_times: if preserve_mode or preserve_times:
st = os.stat (src) st = os.stat(src)
# According to David Ascher <da@ski.org>, utime() should be done # According to David Ascher <da@ski.org>, utime() should be done
# before chmod() (at least under NT). # before chmod() (at least under NT).
if preserve_times: if preserve_times:
os.utime (dst, (st[ST_ATIME], st[ST_MTIME])) os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
if preserve_mode: if preserve_mode:
os.chmod (dst, S_IMODE (st[ST_MODE])) os.chmod(dst, S_IMODE(st[ST_MODE]))
return dst return dst
...@@ -180,13 +178,13 @@ def move_file (src, dst, ...@@ -180,13 +178,13 @@ def move_file (src, dst,
verbose=0, verbose=0,
dry_run=0): dry_run=0):
"""Move a file 'src' to 'dst'. If 'dst' is a directory, the file """Move a file 'src' to 'dst'. If 'dst' is a directory, the file will
will be moved into it with the same name; otherwise, 'src' is be moved into it with the same name; otherwise, 'src' is just renamed
just renamed to 'dst'. Return the new full name of the file. to 'dst'. Return the new full name of the file.
Handles cross-device moves on Unix using
'copy_file()'. What about other systems???"""
Handles cross-device moves on Unix using 'copy_file()'. What about
other systems???
"""
from os.path import exists, isfile, isdir, basename, dirname from os.path import exists, isfile, isdir, basename, dirname
if verbose: if verbose:
...@@ -195,25 +193,25 @@ def move_file (src, dst, ...@@ -195,25 +193,25 @@ def move_file (src, dst,
if dry_run: if dry_run:
return dst return dst
if not isfile (src): if not isfile(src):
raise DistutilsFileError, \ raise DistutilsFileError, \
"can't move '%s': not a regular file" % src "can't move '%s': not a regular file" % src
if isdir (dst): if isdir(dst):
dst = os.path.join (dst, basename (src)) dst = os.path.join(dst, basename(src))
elif exists (dst): elif exists(dst):
raise DistutilsFileError, \ raise DistutilsFileError, \
"can't move '%s': destination '%s' already exists" % \ "can't move '%s': destination '%s' already exists" % \
(src, dst) (src, dst)
if not isdir (dirname (dst)): if not isdir(dirname(dst)):
raise DistutilsFileError, \ raise DistutilsFileError, \
"can't move '%s': destination '%s' not a valid path" % \ "can't move '%s': destination '%s' not a valid path" % \
(src, dst) (src, dst)
copy_it = 0 copy_it = 0
try: try:
os.rename (src, dst) os.rename(src, dst)
except os.error, (num, msg): except os.error, (num, msg):
if num == errno.EXDEV: if num == errno.EXDEV:
copy_it = 1 copy_it = 1
...@@ -222,12 +220,12 @@ def move_file (src, dst, ...@@ -222,12 +220,12 @@ def move_file (src, dst,
"couldn't move '%s' to '%s': %s" % (src, dst, msg) "couldn't move '%s' to '%s': %s" % (src, dst, msg)
if copy_it: if copy_it:
copy_file (src, dst) copy_file(src, dst)
try: try:
os.unlink (src) os.unlink(src)
except os.error, (num, msg): except os.error, (num, msg):
try: try:
os.unlink (dst) os.unlink(dst)
except os.error: except os.error:
pass pass
raise DistutilsFileError, \ raise DistutilsFileError, \
...@@ -242,9 +240,9 @@ def move_file (src, dst, ...@@ -242,9 +240,9 @@ def move_file (src, dst,
def write_file (filename, contents): def write_file (filename, contents):
"""Create a file with the specified name and write 'contents' (a """Create a file with the specified name and write 'contents' (a
sequence of strings without line terminators) to it.""" sequence of strings without line terminators) to it.
"""
f = open (filename, "w") f = open(filename, "w")
for line in contents: for line in contents:
f.write (line + "\n") f.write(line + "\n")
f.close () f.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment