Chromium Code Reviews| 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 import fnmatch | 6 import fnmatch |
| 7 import glob | 7 import glob |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import posixpath | 10 import posixpath |
| 11 import shutil | 11 import shutil |
| 12 import stat | |
| 12 import sys | 13 import sys |
| 13 import time | 14 import time |
| 14 import zipfile | 15 import zipfile |
| 15 | 16 |
| 16 | 17 |
| 17 def IncludeFiles(filters, files): | 18 def IncludeFiles(filters, files): |
| 18 """Filter files based on inclusion lists | 19 """Filter files based on inclusion lists |
| 19 | 20 |
| 20 Return a list of files which match and of the Unix shell-style wildcards | 21 Return a list of files which match and of the Unix shell-style wildcards |
| 21 provided, or return all the files if no filter is provided.""" | 22 provided, or return all the files if no filter is provided.""" |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 | 419 |
| 419 try: | 420 try: |
| 420 zip_stream = zipfile.ZipFile(dest_zip, write_mode, zipfile.ZIP_DEFLATED) | 421 zip_stream = zipfile.ZipFile(dest_zip, write_mode, zipfile.ZIP_DEFLATED) |
| 421 for os_path, file_info_or_zip_path, file_bytes in zip_data: | 422 for os_path, file_info_or_zip_path, file_bytes in zip_data: |
| 422 if isinstance(file_info_or_zip_path, zipfile.ZipInfo): | 423 if isinstance(file_info_or_zip_path, zipfile.ZipInfo): |
| 423 zip_path = file_info_or_zip_path.filename | 424 zip_path = file_info_or_zip_path.filename |
| 424 else: | 425 else: |
| 425 zip_path = file_info_or_zip_path | 426 zip_path = file_info_or_zip_path |
| 426 | 427 |
| 427 if os_path: | 428 if os_path: |
| 428 zip_stream.write(os_path, zip_path) | 429 if stat.S_ISDIR(os.stat(os_path).st_mode): |
| 430 # Python 2.6 on the buildbots doesn't support writing directories to | |
| 431 # zip files. This was resolved in a later version of Python 2.6. | |
| 432 # We'll work around it by writing an empty file with the correct | |
| 433 # path. (This is basically what later versions do anyway.) | |
| 434 zip_stream.writestr(zip_path, '') | |
|
Sam Clegg
2012/11/30 19:01:43
Are you sure this is all it does? Surly there is
binji
2012/11/30 19:43:42
Doesn't seem to be. Though I am writing some of th
| |
| 435 else: | |
| 436 zip_stream.write(os_path, zip_path) | |
| 429 else: | 437 else: |
| 430 zip_stream.writestr(file_info_or_zip_path, file_bytes) | 438 zip_stream.writestr(file_info_or_zip_path, file_bytes) |
| 431 | 439 |
| 432 if not options.quiet: | 440 if not options.quiet: |
| 433 if zip_path in new_files_to_add: | 441 if zip_path in new_files_to_add: |
| 434 operation = 'adding' | 442 operation = 'adding' |
| 435 else: | 443 else: |
| 436 operation = 'updating' | 444 operation = 'updating' |
| 437 zip_info = zip_stream.getinfo(zip_path) | 445 zip_info = zip_stream.getinfo(zip_path) |
| 438 if (zip_info.compress_type == zipfile.ZIP_STORED or | 446 if (zip_info.compress_type == zipfile.ZIP_STORED or |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 463 return 1 | 471 return 1 |
| 464 func = FuncMap.get(args[0]) | 472 func = FuncMap.get(args[0]) |
| 465 if not func: | 473 if not func: |
| 466 print 'Do not recognize command: ' + args[0] | 474 print 'Do not recognize command: ' + args[0] |
| 467 print 'Available commands: %s' % ' '.join(FuncMap) | 475 print 'Available commands: %s' % ' '.join(FuncMap) |
| 468 return 1 | 476 return 1 |
| 469 return func(args[1:]) | 477 return func(args[1:]) |
| 470 | 478 |
| 471 if __name__ == '__main__': | 479 if __name__ == '__main__': |
| 472 sys.exit(main(sys.argv[1:])) | 480 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |