Bug 1278105 - Update the what's new section in every languages draft
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 22 Jun 2016 19:23:55 +0200
changeset 380682 94490bcded6fa85ab5081f6840567d76fbaabab3
parent 375481 b9213f375a3fa9570893c23eef9ef4be4cc83226
child 380684 3ef131e3449ec3cac3e18f993575dbee65358bc2
push id21284
push usersledru@mozilla.com
push dateWed, 22 Jun 2016 17:24:37 +0000
bugs1278105
milestone49.0a1
Bug 1278105 - Update the what's new section in every languages MozReview-Commit-ID: LSkozgFeqRy
testing/mozharness/scripts/push_apk.py
--- a/testing/mozharness/scripts/push_apk.py
+++ b/testing/mozharness/scripts/push_apk.py
@@ -1,26 +1,29 @@
 #!/usr/bin/env python
 """ push_apk.py
 
     Upload the apk of a Firefox app on Google play
     Example for a beta upload:
     $ python push_apk.py --package-name org.mozilla.firefox_beta --service-account foo@developer.gserviceaccount.com --credentials key.p12 --apk-x86=/path/to/fennec-XX.0bY.multi.android-i386.apk --apk-armv7-v9=/path/to/fennec-XX.0bY.multi.android-arm-v9.apk --apk-armv7-v15=/path/to/fennec-XX.0bY.multi.android-arm-v15.apk --track production --push_apk
+
+    Debian/Ubuntu dependencies: python-googleapi python-oauth2client
 """
 import sys
 import os
 
 from oauth2client import client
 
 # load modules from parent dir
 sys.path.insert(1, os.path.dirname(sys.path[0]))
 
 # import the guts
 from mozharness.base.script import BaseScript
 from mozharness.mozilla.googleplay import GooglePlayMixin
+from mozharness.mozilla.storel10n import storel10n
 from mozharness.base.python import VirtualenvMixin
 
 
 class PushAPK(BaseScript, GooglePlayMixin, VirtualenvMixin):
     all_actions = [
         'create-virtualenv',
         'push_apk',
         'test',
@@ -71,19 +74,19 @@ class PushAPK(BaseScript, GooglePlayMixi
 
     ]
 
     # Google play has currently 3 tracks. Rollout deploys
     # to a limited percentage of users
     track_values = ("production", "beta", "alpha", "rollout")
 
     # We have 3 apps. Make sure that their names are correct
-    package_name_values = ("org.mozilla.fennec_aurora",
-                           "org.mozilla.firefox_beta",
-                           "org.mozilla.firefox")
+    package_name_values = {"org.mozilla.fennec_aurora": "aurora",
+                           "org.mozilla.firefox_beta": "beta",
+                           "org.mozilla.firefox": "release"}
 
     def __init__(self, require_config_file=False, config={},
                  all_actions=all_actions,
                  default_actions=default_actions):
 
         # Default configuration
         default_config = {
             'debug_build': False,
@@ -104,16 +107,18 @@ class PushAPK(BaseScript, GooglePlayMixi
             self,
             config_options=self.config_options,
             require_config_file=require_config_file,
             config=default_config,
             all_actions=all_actions,
             default_actions=default_actions,
         )
 
+        self.translationMgmt = storel10n(config, {})
+
     def check_argument(self):
         """ Check that the given values are correct,
         files exists, etc
         """
         if self.config['track'] not in self.track_values:
             self.fatal("Unknown track value " + self.config['track'])
 
         if self.config['package_name'] not in self.package_name_values:
@@ -138,36 +143,61 @@ class PushAPK(BaseScript, GooglePlayMixi
     def upload_apks(self, service, apk_files):
         """ Upload the APK to google play
 
         service -- The session to Google play
         apk_files -- The files
         """
         edit_request = service.edits().insert(body={},
                                               packageName=self.config['package_name'])
+        package_code = self.package_name_values[self.config['package_name']]
         result = edit_request.execute()
         edit_id = result['id']
         # Store all the versions to set the tracks (needs to happen
         # at the same time
         versions = []
 
+        # Retrieve the mapping
+        self.translationMgmt.load_mapping()
+
         # For each files, upload it
         for apk_file in apk_files:
             try:
                 # Upload the file
                 apk_response = service.edits().apks().upload(
                     editId=edit_id,
                     packageName=self.config['package_name'],
                     media_body=apk_file).execute()
                 self.log('Version code %d has been uploaded. '
                          'Filename "%s" edit_id %s' %
                          (apk_response['versionCode'], apk_file, edit_id))
 
                 versions.append(apk_response['versionCode'])
 
+                locales = self.translationMgmt.get_list_locales(package_code)
+                locales.append(u'en-US')
+                nb_locales = 0
+                for locale in locales:
+                    translation = self.translationMgmt.get_translation(package_code, locale)
+                    whatsnew = translation.get("whatsnew")
+                    if locale == "en-GB":
+                        self.log("Ignoring en-GB as locale")
+                        continue
+                    locale = self.translationMgmt.locale_mapping(locale)
+                    self.log('Locale "%s" what\'s new has been updated to "%s"'
+                             % (locale, whatsnew))
+
+                    listing_response = service.edits().apklistings().update(
+                        editId=edit_id, packageName=self.config['package_name'], language=locale,
+                        apkVersionCode=apk_response['versionCode'],
+                        body={'recentChanges': whatsnew}).execute()
+
+                    self.log('Listing for language %s was updated.'
+                           % listing_response['language'])
+
             except client.AccessTokenRefreshError:
                 self.log('The credentials have been revoked or expired,'
                          'please re-run the application to re-authorize')
 
         # Set the track for all apk
         service.edits().tracks().update(
             editId=edit_id,
             track=self.config['track'],