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 """Reads a manifest, creates a tree of hardlinks and runs the test. | 6 """Reads a manifest, creates a tree of hardlinks and runs the test. |
7 | 7 |
8 Keeps a local cache. | 8 Keeps a local cache. |
9 """ | 9 """ |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 def open_remote(file_or_url): | 110 def open_remote(file_or_url): |
111 """Reads a file or url.""" | 111 """Reads a file or url.""" |
112 if re.match(r'^https?://.+$', file_or_url): | 112 if re.match(r'^https?://.+$', file_or_url): |
113 return urllib.urlopen(file_or_url) | 113 return urllib.urlopen(file_or_url) |
114 return open(file_or_url, 'rb') | 114 return open(file_or_url, 'rb') |
115 | 115 |
116 | 116 |
117 def download_or_copy(file_or_url, dest): | 117 def download_or_copy(file_or_url, dest): |
118 """Copies a file or download an url.""" | 118 """Copies a file or download an url.""" |
119 if re.match(r'^https?://.+$', file_or_url): | 119 if re.match(r'^https?://.+$', file_or_url): |
120 urllib.urlretrieve(file_or_url, dest) | 120 try: |
121 urllib.URLopener().retrieve(file_or_url, dest) | |
csharp
2012/04/24 15:18:47
I don't see any need to create a new subclass sinc
| |
122 except IOError: | |
123 logging.error('Failed to download ' + file_or_url) | |
121 else: | 124 else: |
122 shutil.copy(file_or_url, dest) | 125 shutil.copy(file_or_url, dest) |
123 | 126 |
124 | 127 |
125 def get_free_space(path): | 128 def get_free_space(path): |
126 """Returns the number of free bytes.""" | 129 """Returns the number of free bytes.""" |
127 if sys.platform == 'win32': | 130 if sys.platform == 'win32': |
128 free_bytes = ctypes.c_ulonglong(0) | 131 free_bytes = ctypes.c_ulonglong(0) |
129 ctypes.windll.kernel32.GetDiskFreeSpaceExW( | 132 ctypes.windll.kernel32.GetDiskFreeSpaceExW( |
130 ctypes.c_wchar_p(path), None, None, ctypes.pointer(free_bytes)) | 133 ctypes.c_wchar_p(path), None, None, ctypes.pointer(free_bytes)) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 parser.error('Unsupported args %s' % ' '.join(args)) | 306 parser.error('Unsupported args %s' % ' '.join(args)) |
304 | 307 |
305 manifest = json.load(open_remote(options.manifest)) | 308 manifest = json.load(open_remote(options.manifest)) |
306 return run_tha_test( | 309 return run_tha_test( |
307 manifest, os.path.abspath(options.cache), options.remote, | 310 manifest, os.path.abspath(options.cache), options.remote, |
308 options.max_cache_size, options.min_free_space) | 311 options.max_cache_size, options.min_free_space) |
309 | 312 |
310 | 313 |
311 if __name__ == '__main__': | 314 if __name__ == '__main__': |
312 sys.exit(main()) | 315 sys.exit(main()) |
OLD | NEW |