1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
'''Publishes a set of extensions to the webstore.
Given an unpacked extension, compresses and sends to the Chrome webstore.
Releasing to the webstore should involve the following manual steps before
running this script:
1. clean the output directory.
2. make a release build.
3. run manual smoke tests.
4. run automated tests.
'''
import webstore_extension_util
import generate_manifest
import json
import optparse
import os
import sys
import tempfile
from zipfile import ZipFile
_CHROMEVOX_ID = 'kgejglhpjiefppelpmljglcjbhoiplfn'
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
_CHROME_SOURCE_DIR = os.path.normpath(
os.path.join(_SCRIPT_DIR, *[os.path.pardir] * 3))
sys.path.insert(0, os.path.join(_CHROME_SOURCE_DIR, 'build', 'util'))
import version
# A list of files (or directories) to exclude from the webstore build.
EXCLUDE_PATHS = [
'manifest.json',
'manifest_guest.json',
]
def CreateOptionParser():
parser = optparse.OptionParser(description=__doc__)
parser.usage = (
'%prog --client_secret <client_secret> extension_id:extension_path ...')
parser.add_option(
'-c',
'--client_secret',
dest='client_secret',
action='store',
metavar='CLIENT_SECRET')
parser.add_option(
'-p', '--publish', action='store_true', help='publish the extension(s)')
return parser
def GetVersion():
'''Returns the chrome version string.'''
filename = os.path.join(_CHROME_SOURCE_DIR, 'chrome', 'VERSION')
values = version.FetchValues([filename])
return version.SubstTemplate('@MAJOR@.@MINOR@.@BUILD@.@PATCH@', values)
def MakeChromeVoxManifest():
'''Create a manifest for the webstore.
Returns:
Temporary file with generated manifest.
'''
new_file = tempfile.NamedTemporaryFile(mode='w+a', bufsize=0)
in_file_name = os.path.join(_SCRIPT_DIR, os.path.pardir,
'manifest.json.jinja2')
context = {
'is_guest_manifest': '0',
'is_js_compressed': '1',
'is_webstore': '1',
'set_version': GetVersion()
}
generate_manifest.processJinjaTemplate(in_file_name, new_file.name, context)
return new_file
def RunInteractivePrompt(client_secret, output_path):
input = ''
while True:
print 'u upload'
print 'g get upload status'
print 't publish trusted tester'
print 'p publish public'
print 'q quit'
input = raw_input('Please select an option: ')
input = input.strip()
if input == 'g':
print('Upload status: %s' %
webstore_extension_util.GetUploadStatus(client_secret).read())
elif input == 'u':
print('Uploaded with status: %s' % webstore_extension_util.PostUpload(
output_path.name, client_secret))
elif input == 't':
print('Published to trusted testers with status: %s' %
webstore_extension_util.PostPublishTrustedTesters(
client_secret).read())
elif input == 'p':
print('Published to public with status: %s' %
webstore_extension_util.PostPublish(client_secret).read())
elif input == 'q':
sys.exit()
else:
print 'Unrecognized option: %s' % input
def main():
options, args = CreateOptionParser().parse_args()
if len(args) < 1 or not options.client_secret:
print 'Expected at least one argument and --client_secret flag'
print str(args)
sys.exit(1)
client_secret = options.client_secret
for extension in args:
webstore_extension_util.g_app_id, extension_path = extension.split(':')
output_path = tempfile.NamedTemporaryFile()
extension_path = os.path.expanduser(extension_path)
is_chromevox = webstore_extension_util.g_app_id == _CHROMEVOX_ID
with ZipFile(output_path, 'w') as zip:
for root, dirs, files in os.walk(extension_path):
rel_path = os.path.join(os.path.relpath(root, extension_path), '')
if is_chromevox and rel_path in EXCLUDE_PATHS:
continue
for extension_file in files:
if is_chromevox and extension_file in EXCLUDE_PATHS:
continue
zip.write(
os.path.join(root, extension_file),
os.path.join(rel_path, extension_file))
if is_chromevox:
manifest_file = MakeChromeVoxManifest()
zip.write(manifest_file.name, 'manifest.json')
print 'Created extension zip file in %s' % output_path.name
print 'Please run manual smoke tests before proceeding.'
if options.publish:
print('Uploading...%s' % webstore_extension_util.PostUpload(
output_path.name, client_secret))
print('publishing...%s' %
webstore_extension_util.PostPublish(client_secret).read())
else:
RunInteractivePrompt(client_secret, output_path)
if __name__ == '__main__':
main()
|