| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 """Class for parsing metadata about extension samples.""" | 6 """Class for parsing metadata about extension samples.""" |
| 7 | 7 |
| 8 import locale | 8 import locale |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 zip_path = os.path.join(sample_parentpath, zip_filename) | 633 zip_path = os.path.join(sample_parentpath, zip_filename) |
| 634 zip_manifest_path = os.path.join(sample_dirname, 'manifest.json') | 634 zip_manifest_path = os.path.join(sample_dirname, 'manifest.json') |
| 635 | 635 |
| 636 zipfile.ZipFile.debug = 3 | 636 zipfile.ZipFile.debug = 3 |
| 637 | 637 |
| 638 if os.path.isfile(zip_path): | 638 if os.path.isfile(zip_path): |
| 639 try: | 639 try: |
| 640 old_zip_file = zipfile.ZipFile(zip_path, 'r') | 640 old_zip_file = zipfile.ZipFile(zip_path, 'r') |
| 641 except IOError, msg: | 641 except IOError, msg: |
| 642 raise Exception("Could not read zip at %s: %s" % (zip_path, msg)) | 642 raise Exception("Could not read zip at %s: %s" % (zip_path, msg)) |
| 643 except zipfile.BadZipfile, msg: |
| 644 raise Exception("File at %s is not a zip file: %s" % (zip_path, msg)) |
| 643 | 645 |
| 644 try: | 646 try: |
| 645 info = old_zip_file.getinfo(zip_manifest_path) | 647 info = old_zip_file.getinfo(zip_manifest_path) |
| 646 hash = info.comment | 648 hash = info.comment |
| 647 if hash == self['source_hash']: | 649 if hash == self['source_hash']: |
| 648 return None # Hashes match - no need to generate file | 650 return None # Hashes match - no need to generate file |
| 649 except KeyError, msg: | 651 except KeyError, msg: |
| 650 pass # The old zip file doesn't contain a hash - overwrite | 652 pass # The old zip file doesn't contain a hash - overwrite |
| 651 finally: | 653 finally: |
| 652 old_zip_file.close() | 654 old_zip_file.close() |
| (...skipping 13 matching lines...) Expand all Loading... |
| 666 zip_file.write(abspath, relpath) | 668 zip_file.write(abspath, relpath) |
| 667 if file == 'manifest.json': | 669 if file == 'manifest.json': |
| 668 info = zip_file.getinfo(zip_manifest_path) | 670 info = zip_file.getinfo(zip_manifest_path) |
| 669 info.comment = self['source_hash'] | 671 info.comment = self['source_hash'] |
| 670 except RuntimeError, msg: | 672 except RuntimeError, msg: |
| 671 raise Exception("Could not write zip at %s: %s" % (zip_path, msg)) | 673 raise Exception("Could not write zip at %s: %s" % (zip_path, msg)) |
| 672 finally: | 674 finally: |
| 673 zip_file.close() | 675 zip_file.close() |
| 674 | 676 |
| 675 return self._get_relative_zip_path() | 677 return self._get_relative_zip_path() |
| OLD | NEW |