diff options
| author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-01-10 20:26:24 +0900 |
|---|---|---|
| committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-01-10 20:26:24 +0900 |
| commit | 1bcf5a7521fd432f913b77f0dcb0bc25f2275ca9 (patch) | |
| tree | 99b28b1c1161d3750a737b633663b3054866fbdb | |
| parent | 1abb94f5b98372a860e4dad86c0e2556b625b9bc (diff) | |
| download | buildstream-1bcf5a7521fd432f913b77f0dcb0bc25f2275ca9.tar.gz | |
Trying list_relative_paths() with a single sort.
| -rw-r--r-- | buildstream/utils.py | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py index a811fe2f1..2a0f84d82 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -86,29 +86,26 @@ class FileListResult(): def list_relative_paths(directory): - """A generator for walking directory relative paths + """Recursively list the paths in a directory - This generator is useful for checking the full manifest of - a directory. + Args: + directory (str): The directory to list files in - Note that directories will be yielded only if they are - empty. + Returns: + (list): List of relative filenames in `directory` - Symbolic links will not be followed, but will be included - in the manifest. + .. note:: - Args: - directory (str): The directory to list files in + Directories will be included only if they are empty. - Yields: - Relative filenames in `directory` + .. note:: + + Symbolic links will not be followed, but will be included + in the manifest. """ - for (dirpath, dirnames, filenames) in os.walk(directory): + filelist = [] - # Modifying the dirnames directly ensures that the os.walk() generator - # allows us to specify the order in which they will be iterated. - dirnames.sort() - filenames.sort() + for (dirpath, dirnames, filenames) in os.walk(directory): relpath = os.path.relpath(dirpath, directory) @@ -128,17 +125,19 @@ def list_relative_paths(directory): for d in dirnames: fullpath = os.path.join(dirpath, d) if os.path.islink(fullpath): - yield os.path.join(basepath, d) + filelist.append(os.path.join(basepath, d)) # We've decended into an empty directory, in this case we # want to include the directory itself, but not in any other # case. if not filenames: - yield relpath + filelist.append(relpath) # List the filenames in the walked directory for f in filenames: - yield os.path.join(basepath, f) + filelist.append(os.path.join(basepath, f)) + + return sorted(filelist) def glob(paths, pattern): |
