summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2015-06-05 10:07:02 -0700
committerPhilip Chimento <philip@endlessm.com>2015-06-05 10:07:02 -0700
commit32e768ecf7524a7e05ba2037715dc32e02452b50 (patch)
tree4db7eb18dd3fc4700d55f95efe8342f65de5ded8 /tools
parent65ddd00e60eef0f4a7374a9046dc9a6d26ff2539 (diff)
Set encoding on input and output files
Since this is Python 3, we can specify at file-open time what the encoding of the input and output files is to be. This should fix any build errors with non-ASCII characters in an ASCII terminal environment. [endlessm/eos-sdk#3245]
Diffstat (limited to 'tools')
-rwxr-xr-xtools/eos-html-extractor15
1 files changed, 10 insertions, 5 deletions
diff --git a/tools/eos-html-extractor b/tools/eos-html-extractor
index a351f0d..5d863be 100755
--- a/tools/eos-html-extractor
+++ b/tools/eos-html-extractor
@@ -5,6 +5,7 @@
import argparse
import os.path
import re
+import sys
from bs4 import BeautifulSoup
from html.parser import HTMLParser
@@ -47,16 +48,20 @@ 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,
+ type=argparse.FileType('w', encoding='utf-8'),
+ help='File to write (default: stdout)')
args = parser.parse_args()
# Path from current directory to top-level app directory
html_file = args.input_file
top_dir = args.top_srcdir
final_path = os.path.relpath(html_file, top_dir)
+out_file = args.output
# Create the BeautifulSoup HTML-parsing object
-with open(html_file, 'rb') as f:
- page = f.read().decode('utf-8')
+with open(html_file, encoding='utf-8') as f:
+ page = f.read()
soup = BeautifulSoup(page)
# Extract all translatable strings from that HTML
@@ -69,7 +74,7 @@ parser.feed(page)
# Write out all info about the translatable strings found in this file
for string, line_num, optional_comment in parser.all_translatable_data:
- print('#line {line} "{path}"'.format(line=line_num, path=final_path))
+ out_file.write('#line {line} "{path}"\n'.format(line=line_num, path=final_path))
if optional_comment:
- print('// ' + optional_comment)
- print('_("{string}");'.format(string=string))
+ out_file.write('// {}\n'.format(optional_comment))
+ out_file.write('_("{string}");\n'.format(string=string))