Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 ChromeVox to the webstore. | |
| 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 chromevox_webstore_util | |
| 19 import json | |
| 20 import optparse | |
| 21 import os | |
| 22 import sys | |
| 23 import tempfile | |
| 24 from zipfile import ZipFile | |
| 25 | |
| 26 # A list of files to exclude from the webstore build. | |
| 27 EXCLUDE_FILES = ['manifest_guest.json'] | |
| 28 | |
| 29 | |
| 30 def CreateOptionParser(): | |
| 31 parser = optparse.OptionParser(description=__doc__) | |
| 32 parser.usage = '%prog <extension_path> <output_path> <client_secret' | |
| 33 return parser | |
| 34 | |
| 35 def MakeManifestEdits(root, old): | |
| 36 '''Customize a manifest for the webstore. | |
| 37 | |
| 38 Args: | |
| 39 root: The directory containing file. | |
| 40 | |
| 41 old: A json file. | |
| 42 | |
| 43 Returns: | |
| 44 File of the new manifest. | |
| 45 ''' | |
| 46 new_file = tempfile.NamedTemporaryFile() | |
| 47 new = new_file.name | |
| 48 with open(os.path.join(root, old)) as old_file: | |
| 49 new_contents = json.loads(old_file.read()) | |
| 50 new_contents.pop('key', '') | |
| 51 new_file.write(json.dumps(new_contents)) | |
| 52 return new_file | |
| 53 | |
| 54 def RunInteractivePrompt(client_secret, output_path): | |
| 55 input = '' | |
| 56 while True: | |
| 57 print 'u upload' | |
| 58 print 'g get upload status' | |
| 59 print 't publish trusted tester' | |
| 60 print 'p publish public' | |
| 61 print 'q quit' | |
| 62 input = raw_input('Please select an option: ') | |
| 63 input = input.strip() | |
| 64 if input == 'g': | |
| 65 chromevox_webstore_util.GetUploadStatus(client_secret) | |
| 66 elif input == 'u': | |
| 67 chromevox_webstore_util.PostUpload(output_path, client_secret) | |
| 68 elif input == 't': | |
| 69 chromevox_webstore_util.PostPublishTrustedTesters(client_secret) | |
| 70 elif input == 'p': | |
| 71 chromevox_webstore_util.PostPublish(client_secret) | |
| 72 elif input == 'q': | |
| 73 sys.exit() | |
| 74 else: | |
| 75 print 'Unrecognized option: %s' % input | |
| 76 | |
| 77 def main(): | |
| 78 _, args = CreateOptionParser().parse_args() | |
| 79 if len(args) != 3: | |
| 80 print 'Expected exactly three arguments' | |
| 81 sys.exit(1) | |
| 82 | |
| 83 extension_path = args[0] | |
| 84 output_path = args[1] | |
| 85 client_secret = args[2] | |
| 86 | |
| 87 with ZipFile(output_path, 'w') as zip: | |
| 88 for root, dirs, files in os.walk(extension_path): | |
| 89 rel_path = os.path.join(os.path.relpath(root, extension_path), '') | |
| 90 | |
| 91 for file in files: | |
|
dmazzoni
2014/07/30 05:39:55
file is a reserved word in python, please use some
David Tseng
2014/07/31 21:52:57
Ah yes; changed.
| |
| 92 extension_file = file | |
| 93 if file in EXCLUDE_FILES: | |
| 94 continue | |
| 95 if file == 'manifest.json': | |
| 96 extension_file = file | |
| 97 new_file = MakeManifestEdits(root, file) | |
| 98 zip.write( | |
| 99 new_file.name, os.path.join(rel_path, extension_file)) | |
| 100 continue | |
| 101 | |
| 102 zip.write( | |
| 103 os.path.join(root, file), os.path.join(rel_path, extension_file)) | |
| 104 RunInteractivePrompt(client_secret, output_path) | |
|
dmazzoni
2014/07/30 05:39:55
I don't think this is indented correctly - it will
David Tseng
2014/07/31 21:52:57
Yup; you're right. I haven't really tested this ex
| |
| 105 | |
| 106 | |
| 107 if __name__ == '__main__': | |
| 108 main() | |
| OLD | NEW |