OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """ Set of basic operations/utilities that are used by the build. """ | 5 """ Set of basic operations/utilities that are used by the build. """ |
6 | 6 |
7 from contextlib import contextmanager | 7 from contextlib import contextmanager |
8 import copy | 8 import copy |
9 import cStringIO | 9 import cStringIO |
10 import errno | 10 import errno |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 for name in files: | 465 for name in files: |
466 remove_with_retry(os.remove, os.path.join(root, name)) | 466 remove_with_retry(os.remove, os.path.join(root, name)) |
467 for name in dirs: | 467 for name in dirs: |
468 remove_with_retry(lambda p: shutil.rmtree(p, onerror=RmTreeOnError), | 468 remove_with_retry(lambda p: shutil.rmtree(p, onerror=RmTreeOnError), |
469 os.path.join(root, name)) | 469 os.path.join(root, name)) |
470 | 470 |
471 remove_with_retry(os.rmdir, file_path) | 471 remove_with_retry(os.rmdir, file_path) |
472 | 472 |
473 | 473 |
474 def CopyFileToDir(src_path, dest_dir, dest_fn=None): | 474 def CopyFileToDir(src_path, dest_dir, dest_fn=None): |
475 """Copies the file found at src_path to the dest_dir directory. | 475 """Copies the file found at src_path to the dest_dir directory, with metadata. |
476 | 476 |
477 If dest_fn is specified, the src_path is copied to that name in dest_dir, | 477 If dest_fn is specified, the src_path is copied to that name in dest_dir, |
478 otherwise it is copied to a file of the same name. | 478 otherwise it is copied to a file of the same name. |
479 | 479 |
480 Raises PathNotFound if either the file or the directory is not found. | 480 Raises PathNotFound if either the file or the directory is not found. |
481 """ | 481 """ |
482 # Verify the file and directory separately so we can tell them apart and | 482 # Verify the file and directory separately so we can tell them apart and |
483 # raise PathNotFound rather than shutil.copyfile's IOError. | 483 # raise PathNotFound rather than shutil.copyfile's IOError. |
484 if not os.path.isfile(src_path): | 484 if not os.path.isfile(src_path): |
485 raise PathNotFound('Unable to find file %s' % src_path) | 485 raise PathNotFound('Unable to find file %s' % src_path) |
486 if not os.path.isdir(dest_dir): | 486 if not os.path.isdir(dest_dir): |
487 raise PathNotFound('Unable to find dir %s' % dest_dir) | 487 raise PathNotFound('Unable to find dir %s' % dest_dir) |
488 src_file = os.path.basename(src_path) | 488 src_file = os.path.basename(src_path) |
489 if dest_fn: | 489 if dest_fn: |
490 shutil.copy(src_path, os.path.join(dest_dir, dest_fn)) | 490 shutil.copy2(src_path, os.path.join(dest_dir, dest_fn)) |
491 else: | 491 else: |
492 shutil.copy(src_path, os.path.join(dest_dir, src_file)) | 492 shutil.copy2(src_path, os.path.join(dest_dir, src_file)) |
493 | 493 |
494 | 494 |
495 def MakeZip(output_dir, archive_name, file_list, file_relative_dir, | 495 def MakeZip(output_dir, archive_name, file_list, file_relative_dir, |
496 raise_error=True, remove_archive_directory=True, path_filter=None): | 496 raise_error=True, remove_archive_directory=True, path_filter=None): |
497 """Packs files into a new zip archive. | 497 """Packs files into a new zip archive. |
498 | 498 |
499 Files are first copied into a directory within the output_dir named for | 499 Files are first copied into a directory within the output_dir named for |
500 the archive_name, which will be created if necessary and emptied if it | 500 the archive_name, which will be created if necessary and emptied if it |
501 already exists. The files are then then packed using archive names | 501 already exists. The files are then then packed using archive names |
502 relative to the output_dir. That is, if the zipfile is unpacked in place, | 502 relative to the output_dir. That is, if the zipfile is unpacked in place, |
503 it will create a directory identical to the new archiev_name directory, in | 503 it will create a directory identical to the new archive_name directory, in |
504 the output_dir. The zip file will be named as the archive_name, plus | 504 the output_dir. The zip file will be named as the archive_name, plus |
505 '.zip'. | 505 '.zip'. |
506 | 506 |
507 Args: | 507 Args: |
508 output_dir: Absolute path to the directory in which the archive is to | 508 output_dir: Absolute path to the directory in which the archive is to |
509 be created. | 509 be created. |
510 archive_dir: Subdirectory of output_dir holding files to be added to | 510 archive_dir: Subdirectory of output_dir holding files to be added to |
511 the new zipfile. | 511 the new zipfile. |
512 file_list: List of paths to files or subdirectories, relative to the | 512 file_list: List of paths to files or subdirectories, relative to the |
513 file_relative_dir. | 513 file_relative_dir. |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 """ | 1356 """ |
1357 try: | 1357 try: |
1358 pool = multiprocessing.Pool(processes=processes) | 1358 pool = multiprocessing.Pool(processes=processes) |
1359 yield pool | 1359 yield pool |
1360 pool.close() | 1360 pool.close() |
1361 except: | 1361 except: |
1362 pool.terminate() | 1362 pool.terminate() |
1363 raise | 1363 raise |
1364 finally: | 1364 finally: |
1365 pool.join() | 1365 pool.join() |
OLD | NEW |