Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: sky/tools/publish_apk.py

Issue 1233853006: Add a script for publishing an APK to the Play store. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/tools/big_red_button.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 # Modeled on examples from:
7 # https://github.com/googlesamples/android-play-publisher-api/tree/master/v2/pyt hon
8
9 import argparse
10 import httplib2
11 import logging
12 import os
13 import sys
14
15 from apiclient.discovery import build
16 from oauth2client import client
17
18
19 SERVICE_ACCOUNT_EMAIL = (
20 '69268379666-mu02g6delkg25t856t773fkdt9p90lpd@developer.gserviceaccount.com' )
21 KEY_FILE_PATH = os.path.expanduser('~/sky_publish_key.p12')
22 API_AUTH_SCOPE = 'https://www.googleapis.com/auth/androidpublisher'
23 TRACK = 'production' # Can be
24
25
26 def read_binary_file(path):
27 with file(path, 'rb') as f:
28 return f.read()
29
30
31 def read_text_file(path):
32 with file(path, 'r') as f:
33 return f.read()
34
35
36 def publish_apk(service, package_name, apk_path, changes_text, track):
37 edit_request = service.edits().insert(body={}, packageName=package_name)
38 result = edit_request.execute()
39 edit_id = result['id']
40
41 apk_response = service.edits().apks().upload(
42 editId=edit_id,
43 packageName=package_name,
44 media_body=apk_path).execute()
45
46 print 'Version code %d has been uploaded' % apk_response['versionCode']
47
48 track_response = service.edits().tracks().update(
49 editId=edit_id,
50 track=track,
51 packageName=package_name,
52 body={u'versionCodes': [apk_response['versionCode']]}).execute()
53
54 print 'Track %s is set for version code(s) %s' % (
55 track_response['track'], str(track_response['versionCodes']))
56
57 listing_response = service.edits().apklistings().update(
58 editId=edit_id, packageName=package_name, language='en-US',
59 apkVersionCode=apk_response['versionCode'],
60 body={'recentChanges': changes}).execute()
61
62 print ('Listing for language %s was updated.'
63 % listing_response['language'])
64
65 commit_request = service.edits().commit(
66 editId=edit_id, packageName=package_name).execute()
67
68 print 'Edit "%s" has been committed' % (commit_request['id'])
69
70
71 def connect_to_service(email, key_file, auth_scope):
72 credentials = client.SignedJwtAssertionCredentials(
73 email,
74 read_binary_file(key_file),
75 scope=auth_scope)
76 http = httplib2.Http()
77 http = credentials.authorize(http)
78
79 return build('androidpublisher', 'v2', http=http)
80
81
82 def main(argv):
83 logging.basicConfig()
84
85 parser = argparse.ArgumentParser()
86 parser.add_argument('package_name', help='Package (e.g. com.android.sample)')
87 parser.add_argument('apk_path', help='Path to the APK file to upload.')
88 parser.add_argument('changes_file',
89 help='Path to file containing "What\'s new in this version?" text.')
90 parser.add_argument('--track', default='production',
91 choices=['alpha', 'beta', 'production', 'rollout'])
92 args = parser.parse_args()
93
94 changes_text = read_text_file(args.changes_file)
95
96 service = connect_to_service(SERVICE_ACCOUNT_EMAIL, KEY_FILE_PATH,
97 API_AUTH_SCOPE)
98
99 try:
100 publish_apk(service, args.package_name, args.apk_path, changes_text,
101 args.track)
102 except client.AccessTokenRefreshError:
103 print ('The credentials have been revoked or expired, please re-run the '
104 'application to re-authorize')
105
106
107 if __name__ == '__main__':
108 main(sys.argv)
OLDNEW
« no previous file with comments | « sky/tools/big_red_button.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698