Reland "Revert "Adding run_localization_check.py""

This change relands Adding run_localization_check.py which exposed
a bug in esprima that has been fixed in here:
https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1931277

Bug: 1027052
Change-Id: I93a406a15cf5ba21b3a594e8a8593e49518c9a90
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1931279
Commit-Queue: Vidal Diazleal <[email protected]>
Reviewed-by: Paul Lewis <[email protected]>
diff --git a/scripts/test/run_localization_check.py b/scripts/test/run_localization_check.py
new file mode 100644
index 0000000..268c39a
--- /dev/null
+++ b/scripts/test/run_localization_check.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+#
+# Copyright 2019 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import os.path as path
+import re
+import subprocess
+import sys
+
+scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
+sys.path.append(scripts_path)
+import devtools_paths
+
+devtools_path = devtools_paths.devtools_root_path()
+
+
+def parse_options(cli_args):
+    parser = argparse.ArgumentParser(description='Process localization check arguments.')
+    parser.add_argument('--a', action='store_true', dest='all_files', help='If present, check all devtools frontend .js files')
+    parser.add_argument('--files', nargs='+', help='List of .js files with absolute paths separated by a space')
+    parser.add_argument(
+        '--autofix', action='store_true', help='If present, errors in localizable resources will be fixed automatically')
+    args = parser.parse_args(cli_args)
+
+    if not (args.all_files or args.files):
+        parser.error("Please provide a list of files to scan with --files or use --a to scan all files.")
+    elif args.all_files and args.files:
+        parser.error(
+            "Please provide only one option for scanning files: --a for all files or --files <FILE_LIST> for specific files.")
+    return args
+
+
+def popen(arguments, cwd=None):
+    return subprocess.Popen(arguments, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+
+def check_with_node_script(script_path, script_description, args):
+    print(script_description + "...")
+    script_proc_errors_found = False
+    exec_command = [
+        devtools_paths.node_path(),
+        script_path,
+    ] + args
+
+    script_proc = popen(exec_command)
+    (script_proc_out, _) = script_proc.communicate()
+    if script_proc.returncode != 0:
+        script_proc_errors_found = True
+
+    print(script_proc_out)
+    return script_proc_errors_found
+
+
+def show_result(errors, checkIndex):
+    if errors:
+        print('Check {0} failed (see above)'.format(checkIndex))
+        sys.exit(1)
+    else:
+        print('Check {0} succeeded'.format(checkIndex))
+
+
+def check_devtools_localizability(index, check_devtools_localizability_args):
+    script_path = devtools_paths.check_localized_strings_path()
+    script_description = 'Check {0}: Verifying that all resources are localizable'.format(index)
+    return check_with_node_script(script_path, script_description, check_devtools_localizability_args)
+
+
+def check_devtools_localizable_resources(index, check_devtools_localizable_resources_args):
+    script_path = devtools_paths.check_localizable_resources_path()
+    script_description = 'Check {0}: Verifying the structure of localization resource files (grd)'.format(index)
+    return check_with_node_script(script_path, script_description, check_devtools_localizable_resources_args)
+
+
+def main():
+    check_devtools_localizable_resources_args = []
+    check_devtools_localizability_args = []
+
+    parsed_args = parse_options(sys.argv[1:])
+    if parsed_args.all_files:
+        check_devtools_localizability_args = ['-a']
+    elif parsed_args.files:
+        check_devtools_localizability_args = parsed_args.files
+
+    if parsed_args.autofix:
+        check_devtools_localizable_resources_args = ['--autofix']
+
+    resource_index = 1
+    localizability_index = 2
+    resources_errors_found_localizable = check_devtools_localizable_resources(resource_index,
+                                                                              check_devtools_localizable_resources_args)
+    localizability_errors_found = check_devtools_localizability(localizability_index, check_devtools_localizability_args)
+    show_result(resources_errors_found_localizable, resource_index)
+    show_result(localizability_errors_found, localizability_index)
+
+
+if __name__ == '__main__':
+    main()