| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 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 # chromium_extension.py | 6 # chromium_extension.py |
| 7 | 7 |
| 8 import array | 8 import array |
| 9 import hashlib | 9 import hashlib |
| 10 import logging | 10 import logging |
| 11 import optparse | 11 import optparse |
| 12 import os | 12 import os |
| 13 import random |
| 13 import re | 14 import re |
| 14 import shutil | 15 import shutil |
| 15 import sys | 16 import sys |
| 16 import zipfile | 17 import zipfile |
| 17 | 18 |
| 18 if sys.version_info < (2, 6): | 19 if sys.version_info < (2, 6): |
| 19 import simplejson as json | 20 import simplejson as json |
| 20 else: | 21 else: |
| 21 import json | 22 import json |
| 22 | 23 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 def validate(self): | 47 def validate(self): |
| 47 if os.path.join(self._root, MANIFEST_FILENAME) not in self._files: | 48 if os.path.join(self._root, MANIFEST_FILENAME) not in self._files: |
| 48 logging.error("package is missing a valid %s file" % MANIFEST_FILENAME) | 49 logging.error("package is missing a valid %s file" % MANIFEST_FILENAME) |
| 49 return False | 50 return False |
| 50 return True | 51 return True |
| 51 | 52 |
| 52 def writeToPackage(self, path): | 53 def writeToPackage(self, path): |
| 53 if not self.validate(): | 54 if not self.validate(): |
| 54 return False | 55 return False |
| 55 try: | 56 try: |
| 56 f = open(os.path.join(self._root, MANIFEST_FILENAME)) | 57 f = open(os.path.join(self._root, MANIFEST_FILENAME), "r") |
| 57 manifest = json.load(f) | 58 manifest = json.load(f) |
| 58 f.close() | 59 f.close() |
| 59 | 60 |
| 61 # Temporary hack: If the manifest doesn't have an ID, generate a random |
| 62 # one. This is to make it easier for people to play with the extension |
| 63 # system while we don't have the real ID mechanism in place. |
| 64 if not "id" in manifest: |
| 65 random_id = "" |
| 66 for i in range(0, 40): |
| 67 random_id += "0123456789ABCDEF"[random.randrange(0, 15)] |
| 68 logging.info("Generated extension ID: %s" % random_id) |
| 69 manifest["id"] = random_id; |
| 70 f = open(os.path.join(self._root, MANIFEST_FILENAME), "w") |
| 71 f.write(json.dumps(manifest, sort_keys=True, indent=2)); |
| 72 f.close(); |
| 73 |
| 60 zip_path = path + ".zip" | 74 zip_path = path + ".zip" |
| 61 if os.path.exists(zip_path): | 75 if os.path.exists(zip_path): |
| 62 os.remove(zip_path) | 76 os.remove(zip_path) |
| 63 zip = zipfile.ZipFile(zip_path, "w") | 77 zip = zipfile.ZipFile(zip_path, "w") |
| 64 (root, dir) = os.path.split(self._root) | 78 (root, dir) = os.path.split(self._root) |
| 65 root_len = len(self._root) | 79 root_len = len(self._root) |
| 66 for file in self._files: | 80 for file in self._files: |
| 67 arcname = file[root_len+1:] | 81 arcname = file[root_len+1:] |
| 68 logging.debug("%s: %s" % (arcname, file)) | 82 logging.debug("%s: %s" % (arcname, file)) |
| 69 zip.write(file, arcname) | 83 zip.write(file, arcname) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 parser.error("missing required option --outfile") | 163 parser.error("missing required option --outfile") |
| 150 ext = ExtensionDir(options.indir) | 164 ext = ExtensionDir(options.indir) |
| 151 ext.writeToPackage(options.outfile) | 165 ext.writeToPackage(options.outfile) |
| 152 pkg = ExtensionPackage(options.outfile) | 166 pkg = ExtensionPackage(options.outfile) |
| 153 return 0 | 167 return 0 |
| 154 | 168 |
| 155 | 169 |
| 156 if __name__ == "__main__": | 170 if __name__ == "__main__": |
| 157 retcode = Run() | 171 retcode = Run() |
| 158 sys.exit(retcode) | 172 sys.exit(retcode) |
| OLD | NEW |