| 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 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 # This is a bit odd - we're actually appending a new zip file to the end | 97 # This is a bit odd - we're actually appending a new zip file to the end |
| 98 # of the manifest. Believe it or not, this is actually an explicit | 98 # of the manifest. Believe it or not, this is actually an explicit |
| 99 # feature of the zip format, and many zip utilities (this library | 99 # feature of the zip format, and many zip utilities (this library |
| 100 # and three others I tried) can still read the underlying zip file. | 100 # and three others I tried) can still read the underlying zip file. |
| 101 if os.path.exists(path): | 101 if os.path.exists(path): |
| 102 os.remove(path) | 102 os.remove(path) |
| 103 out = open(path, "wb") | 103 out = open(path, "wb") |
| 104 out.write("Cr24") # Extension file magic number | 104 out.write("Cr24") # Extension file magic number |
| 105 # The rest of the header is currently made up of three ints: | 105 # The rest of the header is currently made up of three ints: |
| 106 # version, header size, manifest size | 106 # version, header size, manifest size |
| 107 header = array.array("l") | 107 header = array.array("i") |
| 108 header.append(1) # version | 108 header.append(1) # version |
| 109 header.append(16) # header size | 109 header.append(16) # header size |
| 110 manifest_json = json.dumps(manifest); | 110 manifest_json = json.dumps(manifest); |
| 111 header.append(len(manifest_json)) # manifest size | 111 header.append(len(manifest_json)) # manifest size |
| 112 header.tofile(out) | 112 header.tofile(out) |
| 113 out.write(manifest_json); | 113 out.write(manifest_json); |
| 114 zip = open(zip_path, "rb") | 114 zip = open(zip_path, "rb") |
| 115 while True: | 115 while True: |
| 116 buf = zip.read(32 * 1024) | 116 buf = zip.read(32 * 1024) |
| 117 if not len(buf): | 117 if not len(buf): |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 parser.error("missing required option --outfile") | 163 parser.error("missing required option --outfile") |
| 164 ext = ExtensionDir(options.indir) | 164 ext = ExtensionDir(options.indir) |
| 165 ext.writeToPackage(options.outfile) | 165 ext.writeToPackage(options.outfile) |
| 166 pkg = ExtensionPackage(options.outfile) | 166 pkg = ExtensionPackage(options.outfile) |
| 167 return 0 | 167 return 0 |
| 168 | 168 |
| 169 | 169 |
| 170 if __name__ == "__main__": | 170 if __name__ == "__main__": |
| 171 retcode = Run() | 171 retcode = Run() |
| 172 sys.exit(retcode) | 172 sys.exit(retcode) |
| OLD | NEW |