Commit 6b0d8dcf authored by dtseng's avatar dtseng Committed by Commit bot

Add a flag to ChromeVox upload script for direct publish without interactive mode.

- -p or --publish will now upload and publish.
- only request auth code and oauth token once each (reuse as needed for subsequent calls).
- try closing some more of the httpd socket connections.

Review URL: https://codereview.chromium.org/927543003

Cr-Commit-Position: refs/heads/master@{#317463}
parent e94fe096
...@@ -24,7 +24,10 @@ PROJECT_ARGS = { ...@@ -24,7 +24,10 @@ PROJECT_ARGS = {
'redirect_uri': 'http://localhost:8000' 'redirect_uri': 'http://localhost:8000'
} }
# Globals.
PORT = 8000 PORT = 8000
g_auth_code = None
g_oauth_token = None
APP_ID = 'kgejglhpjiefppelpmljglcjbhoiplfn' APP_ID = 'kgejglhpjiefppelpmljglcjbhoiplfn'
OAUTH_DOMAIN = 'accounts.google.com' OAUTH_DOMAIN = 'accounts.google.com'
...@@ -45,6 +48,10 @@ class CodeRequestHandler(SocketServer.StreamRequestHandler): ...@@ -45,6 +48,10 @@ class CodeRequestHandler(SocketServer.StreamRequestHandler):
self.rfile.close() self.rfile.close()
def GetAuthCode(): def GetAuthCode():
global g_auth_code
if g_auth_code:
return g_auth_code
Handler = CodeRequestHandler Handler = CodeRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler) httpd = SocketServer.TCPServer(("", PORT), Handler)
query = '&'.join(['response_type=code', query = '&'.join(['response_type=code',
...@@ -56,9 +63,14 @@ def GetAuthCode(): ...@@ -56,9 +63,14 @@ def GetAuthCode():
webbrowser.open(auth_url) webbrowser.open(auth_url)
httpd.handle_request() httpd.handle_request()
httpd.server_close() httpd.server_close()
return httpd.code g_auth_code = httpd.code
return g_auth_code
def GetOauthToken(code, client_secret): def GetOauthToken(code, client_secret):
global g_oauth_token
if g_oauth_token:
return g_oauth_token
PROJECT_ARGS['code'] = code PROJECT_ARGS['code'] = code
PROJECT_ARGS['client_secret'] = client_secret PROJECT_ARGS['client_secret'] = client_secret
body = urllib.urlencode(PROJECT_ARGS) body = urllib.urlencode(PROJECT_ARGS)
...@@ -69,11 +81,14 @@ def GetOauthToken(code, client_secret): ...@@ -69,11 +81,14 @@ def GetOauthToken(code, client_secret):
conn.endheaders() conn.endheaders()
conn.send(body) conn.send(body)
content = conn.getresponse().read() content = conn.getresponse().read()
return json.loads(content) conn.close()
g_oauth_token = json.loads(content)
return g_oauth_token
def GetPopulatedHeader(client_secret): def GetPopulatedHeader(client_secret):
code = GetAuthCode() code = GetAuthCode()
access_token = GetOauthToken(code, client_secret) access_token = GetOauthToken(code, client_secret)
url = 'www.googleapis.com' url = 'www.googleapis.com'
return {'Authorization': 'Bearer %(access_token)s' % access_token, return {'Authorization': 'Bearer %(access_token)s' % access_token,
...@@ -85,14 +100,18 @@ def SendGetCommand(command, client_secret): ...@@ -85,14 +100,18 @@ def SendGetCommand(command, client_secret):
headers = GetPopulatedHeader(client_secret) headers = GetPopulatedHeader(client_secret)
conn = httplib.HTTPSConnection(API_ENDPOINT_DOMAIN) conn = httplib.HTTPSConnection(API_ENDPOINT_DOMAIN)
conn.request('GET', command, '', headers) conn.request('GET', command, '', headers)
return conn.getresponse() r = conn.getresponse()
conn.close()
return r
def SendPostCommand(command, client_secret, header_additions = {}, body=None): def SendPostCommand(command, client_secret, header_additions = {}, body=None):
headers = GetPopulatedHeader(client_secret) headers = GetPopulatedHeader(client_secret)
headers = dict(headers.items() + header_additions.items()) headers = dict(headers.items() + header_additions.items())
conn = httplib.HTTPSConnection(API_ENDPOINT_DOMAIN) conn = httplib.HTTPSConnection(API_ENDPOINT_DOMAIN)
conn.request('POST', command, body, headers) conn.request('POST', command, body, headers)
return conn.getresponse() r = conn.getresponse()
conn.close()
return r
def GetUploadStatus(client_secret): def GetUploadStatus(client_secret):
'''Gets the status of a previous upload. '''Gets the status of a previous upload.
......
...@@ -43,7 +43,9 @@ EXCLUDE_PATHS = [ ...@@ -43,7 +43,9 @@ EXCLUDE_PATHS = [
def CreateOptionParser(): def CreateOptionParser():
parser = optparse.OptionParser(description=__doc__) parser = optparse.OptionParser(description=__doc__)
parser.usage = '%prog <extension_path> <output_path> <client_secret' parser.usage = '%prog <extension_path> <client_secret>'
parser.add_option('-p', '--publish', action='store_true',
help='publish the extension')
return parser return parser
...@@ -88,11 +90,11 @@ def RunInteractivePrompt(client_secret, output_path): ...@@ -88,11 +90,11 @@ def RunInteractivePrompt(client_secret, output_path):
chromevox_webstore_util.GetUploadStatus(client_secret).read()) chromevox_webstore_util.GetUploadStatus(client_secret).read())
elif input == 'u': elif input == 'u':
print ('Uploaded with status: %s' % print ('Uploaded with status: %s' %
chromevox_webstore_util.PostUpload(output_path, client_secret)) chromevox_webstore_util.PostUpload(output_path.name, client_secret))
elif input == 't': elif input == 't':
print ('Published to trusted testers with status: %s' % print ('Published to trusted testers with status: %s' %
chromevox_webstore_util.PostPublishTrustedTesters( chromevox_webstore_util.PostPublishTrustedTesters(
client_secret).read()) client_secret).read())
elif input == 'p': elif input == 'p':
print ('Published to public with status: %s' % print ('Published to public with status: %s' %
chromevox_webstore_util.PostPublish(client_secret).read()) chromevox_webstore_util.PostPublish(client_secret).read())
...@@ -102,14 +104,15 @@ def RunInteractivePrompt(client_secret, output_path): ...@@ -102,14 +104,15 @@ def RunInteractivePrompt(client_secret, output_path):
print 'Unrecognized option: %s' % input print 'Unrecognized option: %s' % input
def main(): def main():
_, args = CreateOptionParser().parse_args() options, args = CreateOptionParser().parse_args()
if len(args) != 3: if len(args) != 2:
print 'Expected exactly three arguments' print 'Expected exactly two arguments'
print str(args)
sys.exit(1) sys.exit(1)
extension_path = args[0] extension_path = args[0]
output_path = args[1] client_secret = args[1]
client_secret = args[2] output_path = tempfile.NamedTemporaryFile()
with ZipFile(output_path, 'w') as zip: with ZipFile(output_path, 'w') as zip:
for root, dirs, files in os.walk(extension_path): for root, dirs, files in os.walk(extension_path):
...@@ -125,9 +128,15 @@ def main(): ...@@ -125,9 +128,15 @@ def main():
os.path.join(rel_path, extension_file)) os.path.join(rel_path, extension_file))
manifest_file = MakeManifest() manifest_file = MakeManifest()
zip.write(manifest_file.name, 'manifest.json') zip.write(manifest_file.name, 'manifest.json')
print 'Created ChromeVox zip file in %s' % output_path print 'Created ChromeVox zip file in %s' % output_path.name
print 'Please run manual smoke tests before proceeding.' print 'Please run manual smoke tests before proceeding.'
RunInteractivePrompt(client_secret, output_path) if options.publish:
print('Uploading...%s' %
chromevox_webstore_util.PostUpload(output_path.name, client_secret))
print('publishing...%s' %
chromevox_webstore_util.PostPublish(client_secret).read())
else:
RunInteractivePrompt(client_secret, output_path)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment