| OLD | NEW |
| 1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 If a list is passed in, the returned list of files is constrained to those | 34 If a list is passed in, the returned list of files is constrained to those |
| 35 found under the paths passed in. i.e. calling find(["LayoutTests/fast"]) | 35 found under the paths passed in. i.e. calling find(["LayoutTests/fast"]) |
| 36 will only return files under that directory. | 36 will only return files under that directory. |
| 37 | 37 |
| 38 If a set of skipped directories is passed in, the function will filter out | 38 If a set of skipped directories is passed in, the function will filter out |
| 39 the files lying in these directories i.e. find(["LayoutTests"], set(["fast"])) | 39 the files lying in these directories i.e. find(["LayoutTests"], set(["fast"])) |
| 40 will return everything except files in fast subfolder. | 40 will return everything except files in fast subfolder. |
| 41 | 41 |
| 42 If a callback is passed in, it will be called for the each file and the file | 42 If a callback is passed in, it will be called for the each file and the file |
| 43 will be included into the result if the callback returns True. | 43 will be included into the result if the callback returns True. |
| 44 The callback has to take three arguments: filesystem, dirname and filename. | 44 The callback has to take three arguments: filesystem, dirname and filename.""" |
| 45 """ | |
| 46 | 45 |
| 47 import itertools | 46 import itertools |
| 48 | 47 |
| 49 | 48 |
| 50 def find(filesystem, base_dir, paths=None, skipped_directories=None, file_filter
=None, directory_sort_key=None): | 49 def find(filesystem, base_dir, paths=None, skipped_directories=None, file_filter
=None, directory_sort_key=None): |
| 51 """Finds the set of tests under a given list of sub-paths. | 50 """Finds the set of tests under a given list of sub-paths. |
| 52 | 51 |
| 53 Args: | 52 Args: |
| 54 paths: a list of path expressions relative to base_dir | 53 paths: a list of path expressions relative to base_dir |
| 55 to search. Glob patterns are ok, as are path expressions with | 54 to search. Glob patterns are ok, as are path expressions with |
| 56 forward slashes on Windows. If paths is empty, we look at | 55 forward slashes on Windows. If paths is empty, we look at |
| 57 everything under the base_dir. | 56 everything under the base_dir. |
| 58 """ | 57 """ |
| 59 | 58 |
| 60 paths = paths or ['*'] | 59 paths = paths or ['*'] |
| 61 skipped_directories = skipped_directories or set(['.svn', '_svn']) | 60 skipped_directories = skipped_directories or set(['.svn', '_svn']) |
| 62 return _normalized_find(filesystem, normalize( | 61 return _normalized_find(filesystem, _normalize( |
| 63 filesystem, base_dir, paths), skipped_directories, file_filter, director
y_sort_key) | 62 filesystem, base_dir, paths), skipped_directories, file_filter, director
y_sort_key) |
| 64 | 63 |
| 65 | 64 |
| 66 def normalize(filesystem, base_dir, paths): | 65 def _normalize(filesystem, base_dir, paths): |
| 67 return [filesystem.normpath(filesystem.join(base_dir, path)) for path in pat
hs] | 66 return [filesystem.normpath(filesystem.join(base_dir, path)) for path in pat
hs] |
| 68 | 67 |
| 69 | 68 |
| 70 def _normalized_find(filesystem, paths, skipped_directories, file_filter, direct
ory_sort_key): | 69 def _normalized_find(filesystem, paths, skipped_directories, file_filter, direct
ory_sort_key): |
| 71 """Finds the set of tests under the list of paths. | 70 """Finds the set of tests under the list of paths. |
| 72 | 71 |
| 73 Args: | 72 Args: |
| 74 paths: a list of absolute path expressions to search. | 73 paths: a list of absolute path expressions to search. |
| 75 Glob patterns are ok. | 74 Glob patterns are ok. |
| 76 """ | 75 """ |
| 77 | 76 |
| 78 paths_to_walk = itertools.chain(*(filesystem.glob(path) for path in paths)) | 77 paths_to_walk = itertools.chain(*(filesystem.glob(path) for path in paths)) |
| 79 | 78 |
| 80 def sort_by_directory_key(files_list): | 79 def sort_by_directory_key(files_list): |
| 81 if directory_sort_key: | 80 if directory_sort_key: |
| 82 files_list.sort(key=directory_sort_key) | 81 files_list.sort(key=directory_sort_key) |
| 83 return files_list | 82 return files_list |
| 84 | 83 |
| 85 all_files = itertools.chain(*(sort_by_directory_key( | 84 all_files = itertools.chain(*(sort_by_directory_key(filesystem.files_under(p
ath, |
| 86 filesystem.files_under(path, skipped_directories, file_filter)) for path
in paths_to_walk)) | 85 s
kipped_directories, file_filter)) for path in paths_to_walk)) |
| 87 return all_files | 86 return all_files |
| OLD | NEW |