summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2015-06-05 10:42:56 -0700
committerPhilip Chimento <philip@endlessm.com>2015-06-05 10:42:56 -0700
commit879bc52304f165d1ad20cad843941ce152922f4f (patch)
tree3a3bd0b5387ff1783644b1c5b290c9eb21a3b185 /tools
parent36a7bc8c631832d2ec99be196e6674a63288287c (diff)
Ensure stdout is UTF-8
This gets the underlying byte stream of sys.stdout and wraps it in a UTF-8 encoder. That is then used as the default output file rather than sys.stdout itself, which on Jenkins may not have a default encoding of UTF-8. [endlessm/eos-sdk#3245]
Diffstat (limited to 'tools')
-rwxr-xr-xtools/eos-html-extractor6
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/eos-html-extractor b/tools/eos-html-extractor
index 5d863be..f82afa1 100755
--- a/tools/eos-html-extractor
+++ b/tools/eos-html-extractor
@@ -3,6 +3,7 @@
# Copyright 2013-2015 Endless Mobile, Inc.
import argparse
+import io
import os.path
import re
import sys
@@ -42,13 +43,16 @@ class TranslatableHTMLParser(HTMLParser):
def handle_comment(self, comment):
self._comments_with_line_numbers.append((comment, self.getpos()[0]))
+# Ensure stdout is UTF-8
+default_out = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
+
parser = argparse.ArgumentParser(description='Extract translatable strings ' +
'from HTML files. This is xgettext for HTML.')
parser.add_argument('input_file', type=str,
help='Input file to scan')
parser.add_argument('top_srcdir', type=str, nargs='?', default='.',
help='Top-level source directory (for printing correct #line directives)')
-parser.add_argument('-o', '--output', default=sys.stdout,
+parser.add_argument('-o', '--output', default=default_out,
type=argparse.FileType('w', encoding='utf-8'),
help='File to write (default: stdout)')
args = parser.parse_args()