2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00
iceraven-browser/automation/taskcluster/l10n/locales.py
Kainalu Hagiwara 0d977a5e2d [fenix] Move release locales to a separate config file.
We should leave l10n.toml untouched unless the l10n team wants to
change it.
2020-07-21 10:20:21 -07:00

60 lines
1.8 KiB
Python

#!/usr/bin/python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function, unicode_literals
import re
OPEN_LOCALES = "locales = ["
CLOSE_LOCALES = "]"
def trim_to_locale(str):
match = re.search('\s*"([a-z]+-?[A-Z]*)",\s*', str)
if not match:
raise Exception("Failed parsing locale found in l10n.toml: " + str)
return match.group(1)
# This file is a dumb parser that converts values from '/l10n-release.toml' to be easily
# consumed from Python.
#
# 'l10n-release.toml' has a very simple structure, and it is reasonable to believe that this
# (very basic) algorithm will continue to work as it is changed.
#
# Alternatives to custom parsing that were considered:
# - Using standard library module --- none exists to parse TOML
# - Importing a TOML parsing module --- introduces an additional build step, complexity, and
# security risk
# - Vendoring a TOML module --- large amount of code given the use case. Introduces a security
# risk
def get_release_locales():
with open(r"l10n-release.toml") as f:
file = f.read().splitlines()
locales_opened = False
locales_closed = False
found_locales = []
for line in file:
if line == OPEN_LOCALES:
locales_opened = True
elif line == CLOSE_LOCALES:
locales_closed = True
break
elif locales_opened:
found_locales.append(trim_to_locale(line))
if locales_opened == False:
raise Exception("Could not find `locales` open in l10n.toml")
if locales_closed == False:
raise Exception("Could not find `locales` close in l10n.toml")
return found_locales
RELEASE_LOCALES = get_release_locales()