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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 def ExtractAll(zip_path, path=None, no_clobber=True, pattern=None, | 217 def ExtractAll(zip_path, path=None, no_clobber=True, pattern=None, |
218 predicate=None): | 218 predicate=None): |
219 if path is None: | 219 if path is None: |
220 path = os.getcwd() | 220 path = os.getcwd() |
221 elif not os.path.exists(path): | 221 elif not os.path.exists(path): |
222 MakeDirectory(path) | 222 MakeDirectory(path) |
223 | 223 |
224 if not zipfile.is_zipfile(zip_path): | 224 if not zipfile.is_zipfile(zip_path): |
225 raise Exception('Invalid zip file: %s' % zip_path) | 225 raise Exception('Invalid zip file: %s' % zip_path) |
226 | 226 |
| 227 extracted = [] |
227 with zipfile.ZipFile(zip_path) as z: | 228 with zipfile.ZipFile(zip_path) as z: |
228 for name in z.namelist(): | 229 for name in z.namelist(): |
229 if name.endswith('/'): | 230 if name.endswith('/'): |
230 continue | 231 continue |
231 if pattern is not None: | 232 if pattern is not None: |
232 if not fnmatch.fnmatch(name, pattern): | 233 if not fnmatch.fnmatch(name, pattern): |
233 continue | 234 continue |
234 if predicate and not predicate(name): | 235 if predicate and not predicate(name): |
235 continue | 236 continue |
236 CheckZipPath(name) | 237 CheckZipPath(name) |
237 if no_clobber: | 238 if no_clobber: |
238 output_path = os.path.join(path, name) | 239 output_path = os.path.join(path, name) |
239 if os.path.exists(output_path): | 240 if os.path.exists(output_path): |
240 raise Exception( | 241 raise Exception( |
241 'Path already exists from zip: %s %s %s' | 242 'Path already exists from zip: %s %s %s' |
242 % (zip_path, name, output_path)) | 243 % (zip_path, name, output_path)) |
243 if IsSymlink(z, name): | 244 if IsSymlink(z, name): |
244 dest = os.path.join(path, name) | 245 dest = os.path.join(path, name) |
245 MakeDirectory(os.path.dirname(dest)) | 246 MakeDirectory(os.path.dirname(dest)) |
246 os.symlink(z.read(name), dest) | 247 os.symlink(z.read(name), dest) |
| 248 extracted.append(dest) |
247 else: | 249 else: |
248 z.extract(name, path) | 250 z.extract(name, path) |
| 251 extracted.append(os.path.join(path, name)) |
| 252 |
| 253 return extracted |
249 | 254 |
250 | 255 |
251 def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None, | 256 def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None, |
252 compress=None): | 257 compress=None): |
253 """Adds a file to the given ZipFile with a hard-coded modified time. | 258 """Adds a file to the given ZipFile with a hard-coded modified time. |
254 | 259 |
255 Args: | 260 Args: |
256 zip_file: ZipFile instance to add the file to. | 261 zip_file: ZipFile instance to add the file to. |
257 zip_path: Destination path within the zip file. | 262 zip_path: Destination path within the zip file. |
258 src_path: Path of the source file. Mutually exclusive with |data|. | 263 src_path: Path of the source file. Mutually exclusive with |data|. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 | 575 |
571 md5_check.CallAndRecordIfStale( | 576 md5_check.CallAndRecordIfStale( |
572 on_stale_md5, | 577 on_stale_md5, |
573 record_path=record_path, | 578 record_path=record_path, |
574 input_paths=input_paths, | 579 input_paths=input_paths, |
575 input_strings=input_strings, | 580 input_strings=input_strings, |
576 output_paths=output_paths, | 581 output_paths=output_paths, |
577 force=force, | 582 force=force, |
578 pass_changes=True) | 583 pass_changes=True) |
579 | 584 |
OLD | NEW |