generate_ini.py (1069B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 # Generate updater.ini by doing some light substitution on the localized updater.ini input, 6 # and appending the contents of updater_ini_append on Windows. 7 8 import codecs 9 import re 10 import shutil 11 12 import buildconfig 13 14 15 def main(output, ini, ini_append=None, locale=None): 16 fixup_re = re.compile("^(Info|Title)Text=") 17 # Input INI is always utf-8. 18 with codecs.open(ini, "rb", "utf_8") as f: 19 for line in f: 20 fixed_line = fixup_re.sub(r"\1=", line) 21 fixed_line = fixed_line.replace( 22 "%MOZ_APP_DISPLAYNAME%", buildconfig.substs["MOZ_APP_DISPLAYNAME"] 23 ) 24 output.write(fixed_line) 25 if ini_append and buildconfig.substs["OS_TARGET"] == "WINNT": 26 # Also append the contents of `ini_append`. 27 with codecs.open(ini_append, "rb", "utf_8") as f: 28 shutil.copyfileobj(f, output)