OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """Tool for listing Dart source files. | 6 """Tool for listing Dart source files. |
7 | 7 |
8 Usage: | 8 Usage: |
9 python tools/list_dart_files.py <directory> <root directory pattern> | 9 python tools/list_dart_files.py <directory> <root directory pattern> |
10 """ | 10 """ |
11 | 11 |
12 import os | 12 import os |
13 import re | 13 import re |
14 import sys | 14 import sys |
15 | 15 |
16 | 16 |
17 def main(argv): | 17 def main(argv): |
18 directory = argv[1] | 18 directory = argv[1] |
19 if not os.path.isabs(directory): | |
20 directory = os.path.realpath(directory) | |
21 | 19 |
22 pattern = None | 20 pattern = None |
23 if len(argv) > 2: | 21 if len(argv) > 2: |
24 pattern = re.compile(argv[2]) | 22 pattern = re.compile(argv[2]) |
25 | 23 |
26 for root, directories, files in os.walk(directory): | 24 for root, directories, files in os.walk(directory): |
27 # We only care about actual source files, not generated code or tests. | 25 # We only care about actual source files, not generated code or tests. |
28 for skip_dir in ['.git', 'gen', 'test']: | 26 for skip_dir in ['.git', 'gen', 'test']: |
29 if skip_dir in directories: | 27 if skip_dir in directories: |
30 directories.remove(skip_dir) | 28 directories.remove(skip_dir) |
31 | 29 |
32 # If we are looking at the root directory, filter the immediate | 30 # If we are looking at the root directory, filter the immediate |
33 # subdirectories by the given pattern. | 31 # subdirectories by the given pattern. |
34 if pattern and root == directory: | 32 if pattern and root == directory: |
35 directories[:] = filter(pattern.match, directories) | 33 directories[:] = filter(pattern.match, directories) |
36 | 34 |
37 for filename in files: | 35 for filename in files: |
38 if filename.endswith('.dart') and not filename.endswith('_test.dart'): | 36 if filename.endswith('.dart') and not filename.endswith('_test.dart'): |
39 fullname = os.path.join(directory, root, filename) | 37 fullname = os.path.relpath(os.path.join(root, filename)) |
40 fullname = fullname.replace(os.sep, '/') | 38 fullname = fullname.replace(os.sep, '/') |
41 print fullname | 39 print fullname |
42 | 40 |
43 | 41 |
44 if __name__ == '__main__': | 42 if __name__ == '__main__': |
45 sys.exit(main(sys.argv)) | 43 sys.exit(main(sys.argv)) |
OLD | NEW |