verify_cast_locales.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. # Copyright 2017 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Ensures that Chromecast developers are notified of locale changes."""
  6. from __future__ import print_function
  7. import argparse
  8. import sys
  9. CAST_LOCALES = [
  10. 'am', 'ar', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en-GB', 'en-US',
  11. 'es-419', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'gu', 'he', 'hi', 'hr', 'hu',
  12. 'id', 'it', 'ja', 'kn', 'ko', 'lt', 'lv', 'ml', 'mr', 'ms', 'nb', 'nl',
  13. 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sk', 'sl', 'sr', 'sv', 'sw', 'ta',
  14. 'te', 'th', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW'
  15. ]
  16. SUCCESS_RETURN_CODE = 0
  17. FAILURE_RETURN_CODE = 1
  18. # Chromecast OWNERS need to know if the list of locales used in
  19. # //build/config/locales.gni changes, so that the Chromecast build process
  20. # can be updated accordingly when it does.
  21. #
  22. # This script runs a check to verify that the list of locales maintained in GN
  23. # matches CAST_LOCALES above. If a CL changes that list, it must also change
  24. # CAST_LOCALES in this file to make the Cast trybot pass. This change will
  25. # require adding a //chromecast OWNER to the change, keeping the team aware of
  26. # any locale changes.
  27. def main():
  28. parser = argparse.ArgumentParser()
  29. parser.add_argument('locales', type=str, nargs='+',
  30. help='Locales from the GN locale list')
  31. parser.add_argument('--stamp-file', '-s', type=str, required=True,
  32. help='The script will stamp this file if successful.')
  33. args = parser.parse_args()
  34. if set(CAST_LOCALES) == set(args.locales):
  35. open(args.stamp_file, 'w')
  36. return SUCCESS_RETURN_CODE
  37. # The lists do not match. Compute the difference and log it to the developer.
  38. removed_locales = set(CAST_LOCALES) - set(args.locales)
  39. added_locales = set(args.locales) - set(CAST_LOCALES)
  40. print('CAST_LOCALES no longer matches the locales list from GN!')
  41. if removed_locales:
  42. print('These locales have been removed: {}'.format(list(removed_locales)))
  43. if added_locales:
  44. print('These locales have been added: {}'.format(list(added_locales)))
  45. print(('Please update CAST_LOCALES in {file} and add a reviewer from '
  46. '//chromecast/OWNERS to your CL. ').format(file=__file__))
  47. return FAILURE_RETURN_CODE
  48. if __name__ == '__main__':
  49. sys.exit(main())