Bug 1568151 - Replace `target.getInspector()` by `target.getFront("inspector")`....
[gecko.git] / config / check_js_msg_encoding.py
blob5562fbe3f49660e08e59b1a249a7bdc60e2910f8
1 # vim: set ts=8 sts=4 et sw=4 tw=99:
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
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 # ----------------------------------------------------------------------------
7 # This script checks encoding of the files that define JSErrorFormatStrings.
9 # JSErrorFormatString.format member should be in ASCII encoding.
10 # ----------------------------------------------------------------------------
12 from __future__ import absolute_import
13 from __future__ import print_function
15 import os
16 import sys
18 from mozversioncontrol import get_repository_from_env
21 scriptname = os.path.basename(__file__)
22 expected_encoding = 'ascii'
24 # The following files don't define JSErrorFormatString.
25 ignore_files = [
26 'dom/base/domerr.msg',
27 'js/xpconnect/src/xpc.msg',
31 def log_pass(filename, text):
32 print('TEST-PASS | {} | {} | {}'.format(scriptname, filename, text))
35 def log_fail(filename, text):
36 print('TEST-UNEXPECTED-FAIL | {} | {} | {}'.format(scriptname, filename,
37 text))
40 def check_single_file(filename):
41 with open(filename, 'rb') as f:
42 data = f.read()
43 try:
44 data.decode(expected_encoding)
45 except Exception:
46 log_fail(filename, 'not in {} encoding'.format(expected_encoding))
48 log_pass(filename, 'ok')
49 return True
52 def check_files():
53 result = True
55 with get_repository_from_env() as repo:
56 root = repo.path
58 for filename in repo.get_files_in_working_directory():
59 if filename.endswith('.msg'):
60 if filename not in ignore_files:
61 if not check_single_file(os.path.join(root, filename)):
62 result = False
64 return result
67 def main():
68 if not check_files():
69 sys.exit(1)
71 sys.exit(0)
74 if __name__ == '__main__':
75 main()