OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import fnmatch | |
5 import os | 6 import os |
7 import shlex | |
8 import shutil | |
6 | 9 |
7 | 10 |
8 def EnsureDirectoryExists(dir_path): | 11 def MakeDirectory(dir_path): |
newt (away)
2013/03/15 23:01:19
Yea, that's clearer.
| |
9 try: | 12 try: |
10 os.makedirs(dir_path) | 13 os.makedirs(dir_path) |
11 except OSError: | 14 except OSError: |
12 pass | 15 pass |
13 | 16 |
14 | 17 |
18 def DeleteDirectory(dir_path): | |
19 if os.path.exists(dir_path): | |
20 shutil.rmtree(dir_path) | |
21 | |
22 | |
23 def Touch(path): | |
24 MakeDirectory(os.path.dirname(path)) | |
25 with open(path, 'a'): | |
26 os.utime(path, None) | |
27 | |
28 | |
29 def FindInDirectory(directory, filter): | |
30 files = [] | |
31 for root, dirnames, filenames in os.walk(directory): | |
32 matched_files = fnmatch.filter(filenames, filter) | |
33 files.extend((os.path.join(root, f) for f in matched_files)) | |
34 return files | |
35 | |
36 | |
37 def FindInDirectories(directories, filter): | |
38 all_files = [] | |
39 for directory in directories: | |
40 all_files.extend(FindInDirectory(directory, filter)) | |
41 return all_files | |
42 | |
43 | |
44 def ParseGypList(gyp_string): | |
45 # The ninja generator doesn't support $ in strings, so use ## to | |
46 # represent $. | |
47 # TODO(cjhopman): Remove when | |
48 # https://code.google.com/p/gyp/issues/detail?id=327 | |
49 # is addressed. | |
50 gyp_string = gyp_string.replace('##', '$') | |
51 return shlex.split(gyp_string) | |
52 | |
53 | |
OLD | NEW |