Bug 1110115 - Manage different channels r=bhearsum
--- a/scripts/update_apk_description.py
+++ b/scripts/update_apk_description.py
@@ -81,37 +81,38 @@ class UpdateDescriptionAPK(BaseScript, G
self,
config_options=self.config_options,
require_config_file=require_config_file,
config=default_config,
all_actions=all_actions,
default_actions=default_actions,
)
- self.all_locales_url = self.config['l10n_api_url'] + "api/?done"
- self.locale_url = self.config['l10n_api_url'] + "api/?locale="
+ self.all_locales_url = self.config['l10n_api_url'] + "api/?done&channel={channel}"
+ self.locale_url = self.config['l10n_api_url'] + "api/?locale={locale}&channel={channel}"
self.mapping_url = self.config['l10n_api_url'] + "api/?locale_mapping&reverse"
def check_argument(self):
""" Check that the given values are correct,
files exists, etc
"""
if self.config['package_name'] not in self.package_name_values:
self.fatal("Unknown package name value " +
self.config['package_name'])
if not os.path.isfile(self.config['google_play_credentials_file']):
self.fatal("Could not find " + self.config['google_play_credentials_file'])
- def get_list_locales(self):
+ def get_list_locales(self, package_name):
+
""" Get all the translated locales supported by Google play
So, locale unsupported by Google play won't be downloaded
Idem for not translated locale
"""
- response = urllib2.urlopen(self.all_locales_url)
+ response = urllib2.urlopen(self.all_locales_url.format(channel=package_name))
return json.load(response)
def get_mapping(self):
""" Download and load the locale mapping
"""
response = urllib2.urlopen(self.mapping_url)
self.mappings = json.load(response)
@@ -119,16 +120,22 @@ class UpdateDescriptionAPK(BaseScript, G
""" Google play and Mozilla don't have the exact locale code
Translate them
"""
if locale in self.mappings:
return self.mappings[locale]
else:
return locale
+ def get_translation(self, package_name, locale):
+ """ Get the translation for a locale
+ """
+ response = urllib2.urlopen(self.locale_url.format(channel=package_name, locale=locale))
+ return json.load(response)
+
def update_desc(self, service, package_name):
""" Update the desc on google play
service -- The session to Google play
package_name -- The name of the package
locale -- The locale to update
description -- The new description
"""
@@ -137,35 +144,35 @@ class UpdateDescriptionAPK(BaseScript, G
packageName=package_name)
result = edit_request.execute()
edit_id = result['id']
# Retrieve the mapping
self.get_mapping()
# Get all the locales from the web interface
- locales = self.get_list_locales()
+ locales = self.get_list_locales(package_name)
for locale in locales:
- response = urllib2.urlopen(self.locale_url + locale)
-
- description_json = json.load(response)
- title = description_json.get('title')
- shortDescription = description_json.get('short_desc')
- fullDescription = description_json.get('long_desc')
+ translation = self.get_translation(package_name, locale)
+ title = translation.get("title")
+ short_desc = translation.get("short_desc")
+ long_desc = translation.get("long_desc")
# Google play expects some locales codes (de-DE instead of de)
locale = self.locale_mapping(locale)
try:
self.log("Udating " + package_name + " for '" + locale +
- "' / desc (first chars): " + fullDescription[0:20])
+ "' / title: '" + title + "', short_desc: '" +
+ short_desc[0:20] + "'..., long_desc: '" +
+ long_desc[0:20] + "...'")
listing_response = service.edits().listings().update(
editId=edit_id, packageName=package_name, language=locale,
- body={'fullDescription': fullDescription,
- 'shortDescription': shortDescription,
+ body={'fullDescription': long_desc,
+ 'shortDescription': short_desc,
'title': title}).execute()
except client.AccessTokenRefreshError:
self.log('The credentials have been revoked or expired,'
'please re-run the application to re-authorize')
# Commit our changes
commit_request = service.edits().commit(