Kaydet (Commit) 884df454 authored tarafından Greg Ward's avatar Greg Ward

The 'copy_file()' and 'copy_tree()' functions in util.py now have

meaningful return values: respectively, whether the copy was done, and
the list of files that were copied.  This meant some trivial changes in
core.py as well: the Command methods that mirror 'copy_file()' and
'copy_tree()' have to pass on their return values.
üst 0f72695d
...@@ -636,10 +636,10 @@ class Command: ...@@ -636,10 +636,10 @@ class Command:
preserve_mode=1, preserve_times=1, update=1, level=1): preserve_mode=1, preserve_times=1, update=1, level=1):
"""Copy a file respecting verbose and dry-run flags.""" """Copy a file respecting verbose and dry-run flags."""
util.copy_file (infile, outfile, return util.copy_file (infile, outfile,
preserve_mode, preserve_times, preserve_mode, preserve_times,
update, self.distribution.verbose >= level, update, self.distribution.verbose >= level,
self.distribution.dry_run) self.distribution.dry_run)
def copy_tree (self, infile, outfile, def copy_tree (self, infile, outfile,
...@@ -648,10 +648,10 @@ class Command: ...@@ -648,10 +648,10 @@ class Command:
"""Copy an entire directory tree respecting verbose and dry-run """Copy an entire directory tree respecting verbose and dry-run
flags.""" flags."""
util.copy_tree (infile, outfile, return util.copy_tree (infile, outfile,
preserve_mode, preserve_times, preserve_symlinks, preserve_mode,preserve_times,preserve_symlinks,
update, self.distribution.verbose >= level, update, self.distribution.verbose >= level,
self.distribution.dry_run) self.distribution.dry_run)
def make_file (self, infiles, outfile, func, args, def make_file (self, infiles, outfile, func, args,
......
...@@ -164,7 +164,11 @@ def copy_file (src, dst, ...@@ -164,7 +164,11 @@ def copy_file (src, dst,
'update' is true, 'src' will only be copied if 'dst' does not 'update' is true, 'src' will only be copied if 'dst' does not
exist, or if 'dst' does exist but is older than 'src'. If exist, or if 'dst' does exist but is older than 'src'. If
'verbose' is true, then a one-line summary of the copy will be 'verbose' is true, then a one-line summary of the copy will be
printed to stdout.""" printed to stdout.
Return true if the file was copied (or would have been copied),
false otherwise (ie. 'update' was true and the destination is
up-to-date)."""
# XXX doesn't copy Mac-specific metadata # XXX doesn't copy Mac-specific metadata
...@@ -181,14 +185,15 @@ def copy_file (src, dst, ...@@ -181,14 +185,15 @@ def copy_file (src, dst,
dir = os.path.dirname (dst) dir = os.path.dirname (dst)
if update and not newer (src, dst): if update and not newer (src, dst):
print "not copying %s (output up-to-date)" % src if verbose:
return print "not copying %s (output up-to-date)" % src
return 0
if verbose: if verbose:
print "copying %s -> %s" % (src, dir) print "copying %s -> %s" % (src, dir)
if dry_run: if dry_run:
return return 1
_copy_file_contents (src, dst) _copy_file_contents (src, dst)
if preserve_mode or preserve_times: if preserve_mode or preserve_times:
...@@ -198,6 +203,8 @@ def copy_file (src, dst, ...@@ -198,6 +203,8 @@ def copy_file (src, dst,
if preserve_times: if preserve_times:
os.utime (dst, (st[ST_ATIME], st[ST_MTIME])) os.utime (dst, (st[ST_ATIME], st[ST_MTIME]))
return 1
# copy_file () # copy_file ()
...@@ -213,9 +220,12 @@ def copy_tree (src, dst, ...@@ -213,9 +220,12 @@ def copy_tree (src, dst,
"""Copy an entire directory tree 'src' to a new location 'dst'. Both """Copy an entire directory tree 'src' to a new location 'dst'. Both
'src' and 'dst' must be directory names. If 'src' is not a 'src' and 'dst' must be directory names. If 'src' is not a
directory, raise DistutilsFileError. If 'dst' does not exist, it directory, raise DistutilsFileError. If 'dst' does not exist, it
is created with 'mkpath'. The endresult of the copy is that is created with 'mkpath'. The end result of the copy is that
every file in 'src' is copied to 'dst', and directories under every file in 'src' is copied to 'dst', and directories under
'src' are recursively copied to 'dst'. 'src' are recursively copied to 'dst'. Return the list of files
copied (under their output names) -- note that if 'update' is true,
this might be less than the list of files considered. Return
value is not affected by 'dry_run'.
'preserve_mode' and 'preserve_times' are the same as for 'preserve_mode' and 'preserve_times' are the same as for
'copy_file'; note that they only apply to regular files, not to 'copy_file'; note that they only apply to regular files, not to
...@@ -236,6 +246,8 @@ def copy_tree (src, dst, ...@@ -236,6 +246,8 @@ def copy_tree (src, dst,
if not dry_run: if not dry_run:
mkpath (dst, verbose=verbose) mkpath (dst, verbose=verbose)
outputs = []
for n in names: for n in names:
src_name = os.path.join (src, n) src_name = os.path.join (src, n)
dst_name = os.path.join (dst, n) dst_name = os.path.join (dst, n)
...@@ -246,13 +258,19 @@ def copy_tree (src, dst, ...@@ -246,13 +258,19 @@ def copy_tree (src, dst,
print "linking %s -> %s" % (dst_name, link_dest) print "linking %s -> %s" % (dst_name, link_dest)
if not dry_run: if not dry_run:
os.symlink (link_dest, dst_name) os.symlink (link_dest, dst_name)
outputs.append (dst_name)
elif os.path.isdir (src_name): elif os.path.isdir (src_name):
copy_tree (src_name, dst_name, outputs[-1:] = \
preserve_mode, preserve_times, preserve_symlinks, copy_tree (src_name, dst_name,
update, verbose, dry_run) preserve_mode, preserve_times, preserve_symlinks,
update, verbose, dry_run)
else: else:
copy_file (src_name, dst_name, if (copy_file (src_name, dst_name,
preserve_mode, preserve_times, preserve_mode, preserve_times,
update, verbose, dry_run) update, verbose, dry_run)):
outputs.append (dst_name)
return outputs
# copy_tree () # copy_tree ()
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