Chromium Code Reviews| 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 ast | 5 import ast |
| 6 import contextlib | 6 import contextlib |
| 7 import fnmatch | 7 import fnmatch |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import pipes | 10 import pipes |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 return device_state.strip() == 'device' | 189 return device_state.strip() == 'device' |
| 190 | 190 |
| 191 | 191 |
| 192 def CheckZipPath(name): | 192 def CheckZipPath(name): |
| 193 if os.path.normpath(name) != name: | 193 if os.path.normpath(name) != name: |
| 194 raise Exception('Non-canonical zip path: %s' % name) | 194 raise Exception('Non-canonical zip path: %s' % name) |
| 195 if os.path.isabs(name): | 195 if os.path.isabs(name): |
| 196 raise Exception('Absolute zip path: %s' % name) | 196 raise Exception('Absolute zip path: %s' % name) |
| 197 | 197 |
| 198 | 198 |
| 199 def ExtractAll(zip_path, path=None, no_clobber=True, pattern=None): | 199 def ExtractAll(zip_path, path=None, no_clobber=True, pattern=None, |
| 200 predicate=None): | |
| 200 if path is None: | 201 if path is None: |
| 201 path = os.getcwd() | 202 path = os.getcwd() |
| 202 elif not os.path.exists(path): | 203 elif not os.path.exists(path): |
| 203 MakeDirectory(path) | 204 MakeDirectory(path) |
| 204 | 205 |
| 205 with zipfile.ZipFile(zip_path) as z: | 206 with zipfile.ZipFile(zip_path) as z: |
| 206 for name in z.namelist(): | 207 for name in z.namelist(): |
| 207 if name.endswith('/'): | 208 if name.endswith('/'): |
| 208 continue | 209 continue |
| 209 if pattern is not None: | 210 if pattern is not None: |
| 210 if not fnmatch.fnmatch(name, pattern): | 211 if not fnmatch.fnmatch(name, pattern): |
| 211 continue | 212 continue |
| 213 if predicate is not None and not predicate(name): | |
|
jbudorick
2015/09/23 00:26:20
I don't think functions can be interpreted as fals
agrieve
2015/09/23 02:07:56
Done.
| |
| 214 continue | |
| 212 CheckZipPath(name) | 215 CheckZipPath(name) |
| 213 if no_clobber: | 216 if no_clobber: |
| 214 output_path = os.path.join(path, name) | 217 output_path = os.path.join(path, name) |
| 215 if os.path.exists(output_path): | 218 if os.path.exists(output_path): |
| 216 raise Exception( | 219 raise Exception( |
| 217 'Path already exists from zip: %s %s %s' | 220 'Path already exists from zip: %s %s %s' |
| 218 % (zip_path, name, output_path)) | 221 % (zip_path, name, output_path)) |
| 219 | 222 |
| 220 z.extractall(path=path) | 223 z.extractall(path=path) |
| 221 | 224 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 expansion = file_jsons[file_path] | 399 expansion = file_jsons[file_path] |
| 397 for k in lookup_path[1:]: | 400 for k in lookup_path[1:]: |
| 398 expansion = expansion[k] | 401 expansion = expansion[k] |
| 399 | 402 |
| 400 new_args[i] = arg[:match.start()] + str(expansion) | 403 new_args[i] = arg[:match.start()] + str(expansion) |
| 401 | 404 |
| 402 return new_args | 405 return new_args |
| 403 | 406 |
| 404 | 407 |
| 405 def CallAndRecordIfStale(function, options, record_path=None, input_paths=None, | 408 def CallAndRecordIfStale(function, options, record_path=None, input_paths=None, |
| 406 input_strings=None, output_paths=None, force=False): | 409 input_strings=None, output_paths=None, force=False, |
| 410 pass_changes=False): | |
| 407 """Wraps md5_check.CallAndRecordIfStale() and also writes dep & stamp files. | 411 """Wraps md5_check.CallAndRecordIfStale() and also writes dep & stamp files. |
| 408 | 412 |
| 409 Depfiles and stamp files are automatically added to output_paths when present | 413 Depfiles and stamp files are automatically added to output_paths when present |
| 410 in the |options| arguemnt. They are then created after |function| is called. | 414 in the |options| arguemnt. They are then created after |function| is called. |
| 411 """ | 415 """ |
| 412 if not output_paths: | 416 if not output_paths: |
| 413 raise Exception('At least one output_path must be specified.') | 417 raise Exception('At least one output_path must be specified.') |
| 414 input_paths = list(input_paths or []) | 418 input_paths = list(input_paths or []) |
| 415 input_strings = list(input_strings or []) | 419 input_strings = list(input_strings or []) |
| 416 output_paths = list(output_paths or []) | 420 output_paths = list(output_paths or []) |
| 417 | 421 |
| 418 python_deps = None | 422 python_deps = None |
| 419 if hasattr(options, 'depfile') and options.depfile: | 423 if hasattr(options, 'depfile') and options.depfile: |
| 420 python_deps = GetPythonDependencies() | 424 python_deps = GetPythonDependencies() |
| 421 # List python deps in input_strings rather than input_paths since the | 425 # List python deps in input_strings rather than input_paths since the |
| 422 # contents of them does not change what gets written to the depfile. | 426 # contents of them does not change what gets written to the depfile. |
| 423 input_strings += python_deps | 427 input_strings += python_deps |
| 424 output_paths += [options.depfile] | 428 output_paths += [options.depfile] |
| 425 | 429 |
| 426 stamp_file = hasattr(options, 'stamp') and options.stamp | 430 stamp_file = hasattr(options, 'stamp') and options.stamp |
| 427 if stamp_file: | 431 if stamp_file: |
| 428 output_paths += [stamp_file] | 432 output_paths += [stamp_file] |
| 429 | 433 |
| 430 def on_stale_md5(): | 434 def on_stale_md5(changes): |
| 431 function() | 435 args = (changes,) if pass_changes else () |
| 436 function(*args) | |
| 432 if python_deps is not None: | 437 if python_deps is not None: |
| 433 WriteDepfile(options.depfile, python_deps + input_paths) | 438 WriteDepfile(options.depfile, python_deps + input_paths) |
| 434 if stamp_file: | 439 if stamp_file: |
| 435 Touch(stamp_file) | 440 Touch(stamp_file) |
| 436 | 441 |
| 437 md5_check.CallAndRecordIfStale( | 442 md5_check.CallAndRecordIfStale( |
| 438 on_stale_md5, | 443 on_stale_md5, |
| 439 record_path=record_path, | 444 record_path=record_path, |
| 440 input_paths=input_paths, | 445 input_paths=input_paths, |
| 441 input_strings=input_strings, | 446 input_strings=input_strings, |
| 442 output_paths=output_paths, | 447 output_paths=output_paths, |
| 443 force=force) | 448 force=force, |
| 449 pass_changes=True) | |
| 444 | 450 |
| OLD | NEW |