| 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 |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 """This module is used to find files used by run-webkit-tests and | 29 """A utility module used to find files. It exposes one public function: find(). |
| 30 perftestrunner. It exposes one public function - find() - which takes | |
| 31 an optional list of paths, optional set of skipped directories and optional | |
| 32 filter callback. | |
| 33 | 30 |
| 34 If a list is passed in, the returned list of files is constrained to those | 31 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"]) | 32 found under the paths passed in. i.e. calling find(["LayoutTests/fast"]) |
| 36 will only return files under that directory. | 33 will only return files under that directory. |
| 37 | 34 |
| 38 If a set of skipped directories is passed in, the function will filter out | 35 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"])) | 36 the files lying in these directories i.e. find(["LayoutTests"], set(["fast"])) |
| 40 will return everything except files in fast subfolder. | 37 will return everything except files in the "fast" subdirectory. |
| 41 | 38 |
| 42 If a callback is passed in, it will be called for the each file and the file | 39 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. | 40 will be included into the result if the callback returns True. |
| 41 |
| 44 The callback has to take three arguments: filesystem, dirname and filename. | 42 The callback has to take three arguments: filesystem, dirname and filename. |
| 45 """ | 43 """ |
| 46 | 44 |
| 47 import itertools | 45 import itertools |
| 48 | 46 |
| 49 | 47 |
| 50 def find(filesystem, base_dir, paths=None, skipped_directories=None, file_filter
=None, directory_sort_key=None): | 48 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. | 49 """Finds the set of tests under a given list of sub-paths. |
| 52 | 50 |
| 53 Args: | 51 Args: |
| 54 paths: a list of path expressions relative to base_dir | 52 filesystem: A FileSystem instance. |
| 55 to search. Glob patterns are ok, as are path expressions with | 53 base_dir: A base directory to search under. |
| 56 forward slashes on Windows. If paths is empty, we look at | 54 paths: A list of path expressions relative to |base_dir|. Glob patterns |
| 57 everything under the base_dir. | 55 are OK, as are path expressions with forward slashes on Windows. |
| 56 If paths is not given, we look at everything under |base_dir|. |
| 57 file_filter: A predicate function which takes three arguments: |
| 58 filesystem, dirname and filename. |
| 59 directory_sort_key: A sort key function. |
| 60 |
| 61 Returns: |
| 62 An iterable of absolute paths that were found. |
| 58 """ | 63 """ |
| 59 | |
| 60 paths = paths or ['*'] | 64 paths = paths or ['*'] |
| 61 skipped_directories = skipped_directories or set(['.svn', '_svn']) | 65 skipped_directories = skipped_directories or set(['.svn', '_svn']) |
| 62 return _normalized_find(filesystem, _normalize( | 66 absolute_paths = _normalize(filesystem, base_dir, paths) |
| 63 filesystem, base_dir, paths), skipped_directories, file_filter, director
y_sort_key) | 67 return _normalized_find(filesystem, absolute_paths, skipped_directories, fil
e_filter, directory_sort_key) |
| 64 | 68 |
| 65 | 69 |
| 66 def _normalize(filesystem, base_dir, paths): | 70 def _normalize(filesystem, base_dir, paths): |
| 67 return [filesystem.normpath(filesystem.join(base_dir, path)) for path in pat
hs] | 71 return [filesystem.normpath(filesystem.join(base_dir, path)) for path in pat
hs] |
| 68 | 72 |
| 69 | 73 |
| 70 def _normalized_find(filesystem, paths, skipped_directories, file_filter, direct
ory_sort_key): | 74 def _normalized_find(filesystem, paths, skipped_directories, file_filter, direct
ory_sort_key): |
| 71 """Finds the set of tests under the list of paths. | 75 """Finds the set of tests under the given list of paths.""" |
| 72 | |
| 73 Args: | |
| 74 paths: a list of absolute path expressions to search. | |
| 75 Glob patterns are ok. | |
| 76 """ | |
| 77 | |
| 78 paths_to_walk = itertools.chain(*(filesystem.glob(path) for path in paths)) | 76 paths_to_walk = itertools.chain(*(filesystem.glob(path) for path in paths)) |
| 79 | 77 |
| 80 def sort_by_directory_key(files_list): | 78 def sort_by_directory_key(files_list): |
| 81 if directory_sort_key: | 79 if directory_sort_key: |
| 82 files_list.sort(key=directory_sort_key) | 80 files_list.sort(key=directory_sort_key) |
| 83 return files_list | 81 return files_list |
| 84 | 82 |
| 85 all_files = itertools.chain(*(sort_by_directory_key(filesystem.files_under(p
ath, skipped_directories, file_filter)) | 83 return itertools.chain(*(sort_by_directory_key( |
| 86 for path in paths_to_walk)) | 84 filesystem.files_under(path, skipped_directories, file_filter)) for path
in paths_to_walk)) |
| 87 return all_files | |
| OLD | NEW |