Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
dmazzoni
2014/07/23 18:52:41
Maybe call this upload_to_webstore or something al
David Tseng
2014/07/23 22:45:31
I didn't specialize it because it will also contai
| |
| 2 | |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 '''Publishes an extension to the webstore. | |
|
dmazzoni
2014/07/23 18:52:41
Is this "an extension" or is it just ChromeVox?
David Tseng
2014/07/23 22:45:31
Done.
| |
| 8 Given an unpacked extension, compresses and sends to the Chrome webstore. | |
| 9 | |
| 10 Releasing to the webstore should involve the following manual steps before | |
| 11 running this script: | |
| 12 1. clean the output directory. | |
| 13 2. make a release build. | |
| 14 3. run manual smoke tests. | |
| 15 4. run automated ChromeVox tests. | |
| 16 ''' | |
| 17 | |
| 18 import json | |
| 19 import optparse | |
| 20 import os | |
| 21 import sys | |
| 22 from zipfile import ZipFile | |
| 23 | |
| 24 # A list of files to exclude from the webstore build. | |
| 25 EXCLUDE_FILES = ['manifest_guest.json'] | |
| 26 | |
| 27 | |
| 28 def CreateOptionParser(): | |
| 29 parser = optparse.OptionParser(description=__doc__) | |
| 30 parser.usage = '%prog <extension_path> <output_path>' | |
| 31 return parser | |
| 32 | |
| 33 def MakeManifestEdits(root, old): | |
| 34 '''Customize a manifest for the webstore. | |
| 35 | |
| 36 Args: | |
| 37 root: The directory containing file. | |
| 38 | |
| 39 old: A json file. | |
| 40 | |
| 41 Returns: | |
| 42 Path of the new json manifest. | |
| 43 ''' | |
| 44 new = os.path.join('/tmp', old) | |
|
dmazzoni
2014/07/23 18:52:41
Use a tmpfile api to get a temporary file that won
David Tseng
2014/07/23 22:45:31
Done.
| |
| 45 with open(os.path.join(root, old)) as old_file, open(new, 'w') as new_file: | |
| 46 new_contents = json.loads(old_file.read()) | |
| 47 new_contents.pop('key', '') | |
| 48 new_file.write(json.dumps(new_contents)) | |
| 49 return new | |
| 50 | |
| 51 def main(): | |
| 52 _, args = CreateOptionParser().parse_args() | |
| 53 if len(args) != 2: | |
| 54 print 'Expected exactly two arguments' | |
| 55 sys.exit(1) | |
| 56 | |
| 57 extension_path = args[0] | |
| 58 output_path = args[1] | |
| 59 | |
| 60 with ZipFile(output_path, 'w') as zip: | |
| 61 for root, dirs, files in os.walk(extension_path): | |
| 62 rel_path = os.path.join(os.path.relpath(root, extension_path), '') | |
| 63 | |
| 64 for file in files: | |
| 65 extension_file = file | |
| 66 if file in EXCLUDE_FILES: | |
| 67 continue | |
| 68 if file == 'manifest.json': | |
| 69 extension_file = file | |
| 70 file = MakeManifestEdits(root, file) | |
| 71 | |
| 72 zip.write( | |
| 73 os.path.join(root, file), os.path.join(rel_path, extension_file)) | |
| 74 # TODO(dtseng): Publish to webstore | |
| 75 | |
| 76 if __name__ == '__main__': | |
| 77 main() | |
| OLD | NEW |