OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Copies test data files or directories into a given output directory.""" | 6 """Copies test data files or directories into a given output directory.""" |
7 | 7 |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
11 import sys | 11 import sys |
12 | 12 |
13 class WrongNumberOfArgumentsException(Exception): | 13 class WrongNumberOfArgumentsException(Exception): |
14 pass | 14 pass |
15 | 15 |
16 def ListFilesForPath(path): | 16 def ListFilesForPath(path): |
17 """Returns a list of all the files under a given path.""" | 17 """Returns a list of all the files under a given path.""" |
18 output = [] | 18 output = [] |
| 19 # Ignore dotfiles and dot directories. |
| 20 # TODO(rohitrao): This will fail to exclude cases where the initial argument |
| 21 # is a relative path that starts with a dot. |
| 22 if os.path.basename(path).startswith('.'): |
| 23 return output |
| 24 |
19 # Files get returned without modification. | 25 # Files get returned without modification. |
20 if not os.path.isdir(path): | 26 if not os.path.isdir(path): |
21 output.append(path) | 27 output.append(path) |
22 return output | 28 return output |
23 | 29 |
24 # Directories get recursively expanded. | 30 # Directories get recursively expanded. |
25 contents = os.listdir(path) | 31 contents = os.listdir(path) |
26 for item in contents: | 32 for item in contents: |
27 full_path = os.path.join(path, item) | 33 full_path = os.path.join(path, item) |
28 output.extend(ListFilesForPath(full_path)) | 34 output.extend(ListFilesForPath(full_path)) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 result = DoMain(argv[1:]) | 95 result = DoMain(argv[1:]) |
90 except WrongNumberOfArgumentsException, e: | 96 except WrongNumberOfArgumentsException, e: |
91 print >>sys.stderr, e | 97 print >>sys.stderr, e |
92 return 1 | 98 return 1 |
93 if result: | 99 if result: |
94 print result | 100 print result |
95 return 0 | 101 return 0 |
96 | 102 |
97 if __name__ == '__main__': | 103 if __name__ == '__main__': |
98 sys.exit(main(sys.argv)) | 104 sys.exit(main(sys.argv)) |
OLD | NEW |