desktop_l10n.py (5509B)
1 #!/usr/bin/env python 2 # This Source Code Form is subject to the terms of the Mozilla Public 3 # License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 # You can obtain one at http://mozilla.org/MPL/2.0/. 5 """desktop_l10n.py 6 7 This script manages Desktop repacks for nightly builds. 8 """ 9 10 import os 11 import sys 12 13 # load modules from parent dir 14 sys.path.insert(1, os.path.dirname(sys.path[0])) # noqa 15 16 from mozharness.base.script import BaseScript 17 from mozharness.base.vcs.vcsbase import VCSMixin 18 from mozharness.mozilla.automation import AutomationMixin 19 from mozharness.mozilla.building.buildbase import ( 20 get_mozconfig_path, 21 ) 22 from mozharness.mozilla.l10n.locales import LocalesMixin 23 24 try: 25 import simplejson as json 26 27 assert json 28 except ImportError: 29 import json 30 31 32 # DesktopSingleLocale {{{1 33 class DesktopSingleLocale(LocalesMixin, AutomationMixin, VCSMixin, BaseScript): 34 """Manages desktop repacks""" 35 36 config_options = [ 37 [ 38 [ 39 "--locale", 40 ], 41 { 42 "action": "extend", 43 "dest": "locales", 44 "type": "string", 45 "help": "Specify the locale(s) to sign and update. Optionally pass" 46 " revision separated by colon, en-GB:default.", 47 }, 48 ], 49 ] 50 51 def __init__(self, require_config_file=True): 52 # fxbuild style: 53 buildscript_kwargs = { 54 "all_actions": [ 55 "clone-locales", 56 "list-locales", 57 "setup", 58 "repack", 59 "summary", 60 ], 61 "config": { 62 "ignore_locales": ["en-US"], 63 "locales_dir": "browser/locales", 64 "log_name": "single_locale", 65 "git_repository": "https://github.com/mozilla-l10n/firefox-l10n", 66 }, 67 } 68 69 LocalesMixin.__init__(self) 70 BaseScript.__init__( 71 self, 72 config_options=self.config_options, 73 require_config_file=require_config_file, 74 **buildscript_kwargs, 75 ) 76 77 self.bootstrap_env = None 78 self.upload_env = None 79 80 # Helper methods {{{2 81 def query_bootstrap_env(self): 82 """returns the env for repacks""" 83 if self.bootstrap_env: 84 return self.bootstrap_env 85 config = self.config 86 abs_dirs = self.query_abs_dirs() 87 88 bootstrap_env = self.query_env( 89 partial_env=config.get("bootstrap_env"), replace_dict=abs_dirs 90 ) 91 92 bootstrap_env["L10NBASEDIR"] = abs_dirs["abs_l10n_dir"] 93 if self.query_is_nightly(): 94 # we might set update_channel explicitly 95 if config.get("update_channel"): 96 update_channel = config["update_channel"] 97 else: # Let's just give the generic channel based on branch. 98 update_channel = "nightly-%s" % (config["branch"],) 99 if not isinstance(update_channel, bytes): 100 update_channel = update_channel.encode("utf-8") 101 bootstrap_env["MOZ_UPDATE_CHANNEL"] = update_channel 102 self.info( 103 "Update channel set to: {}".format(bootstrap_env["MOZ_UPDATE_CHANNEL"]) 104 ) 105 self.bootstrap_env = bootstrap_env 106 return self.bootstrap_env 107 108 def _query_upload_env(self): 109 """returns the environment used for the upload step""" 110 if self.upload_env: 111 return self.upload_env 112 config = self.config 113 114 self.upload_env = self.query_env(partial_env=config.get("upload_env")) 115 return self.upload_env 116 117 def query_l10n_env(self): 118 l10n_env = self._query_upload_env().copy() 119 l10n_env.update(self.query_bootstrap_env()) 120 return l10n_env 121 122 # Actions {{{2 123 def clone_locales(self): 124 self.pull_locale_source() 125 126 def setup(self): 127 """setup step""" 128 self._copy_mozconfig() 129 self._mach_configure() 130 131 def _copy_mozconfig(self): 132 """copies the mozconfig file into abs_src_dir/.mozconfig 133 and logs the content 134 """ 135 config = self.config 136 dirs = self.query_abs_dirs() 137 src = get_mozconfig_path(self, config, dirs) 138 dst = os.path.join(dirs["abs_src_dir"], ".mozconfig") 139 self.copyfile(src, dst) 140 self.read_from_file(dst, verbose=True) 141 142 def _mach(self, target, env, halt_on_failure=True, output_parser=None): 143 dirs = self.query_abs_dirs() 144 mach = self._get_mach_executable() 145 return self.run_command( 146 mach + target, 147 halt_on_failure=True, 148 env=env, 149 cwd=dirs["abs_src_dir"], 150 output_parser=None, 151 ) 152 153 def _mach_configure(self): 154 """calls mach configure""" 155 env = self.query_bootstrap_env() 156 target = ["configure"] 157 return self._mach(target=target, env=env) 158 159 def _get_mach_executable(self): 160 return [sys.executable, "mach"] 161 162 def repack(self): 163 env = self.query_bootstrap_env() 164 return self._mach( 165 target=[ 166 "repackage-single-locales", 167 "--verbose", 168 "--dest", 169 self.config["upload_env"]["UPLOAD_PATH"], 170 "--locales", 171 ] 172 + list(sorted(self.query_locales())), 173 env=env, 174 ) 175 176 177 # main {{{ 178 if __name__ == "__main__": 179 single_locale = DesktopSingleLocale() 180 single_locale.run_and_exit()