in awscli/customizations/s3/filegenerator.py [0:0]
def list_files(self, path, dir_op):
"""
This function yields the appropriate local file or local files
under a directory depending on if the operation is on a directory.
For directories a depth first search is implemented in order to
follow the same sorted pattern as a s3 list objects operation
outputs. It yields the file's source path, size, and last
update
"""
join, isdir, isfile = os.path.join, os.path.isdir, os.path.isfile
error, listdir = os.error, os.listdir
if not self.should_ignore_file(path):
if not dir_op:
stats = self._safely_get_file_stats(path)
if stats:
yield stats
else:
# We need to list files in byte order based on the full
# expanded path of the key: 'test/1/2/3.txt' However,
# listdir() will only give us contents a single directory
# at a time, so we'll get 'test'. At the same time we don't
# want to load the entire list of files into memory. This
# is handled by first going through the current directory
# contents and adding the directory separator to any
# directories. We can then sort the contents,
# and ensure byte order.
listdir_names = listdir(path)
names = []
for name in listdir_names:
if not self.should_ignore_file_with_decoding_warnings(
path, name):
file_path = join(path, name)
if isdir(file_path):
name = name + os.path.sep
names.append(name)
self.normalize_sort(names, os.sep, '/')
for name in names:
file_path = join(path, name)
if isdir(file_path):
# Anything in a directory will have a prefix of
# this current directory and will come before the
# remaining contents in this directory. This
# means we need to recurse into this sub directory
# before yielding the rest of this directory's
# contents.
for x in self.list_files(file_path, dir_op):
yield x
else:
stats = self._safely_get_file_stats(file_path)
if stats:
yield stats