Fix publishdocs error with Python 3

This patch fixes the following error
 - AttributeError: 'bytes' object has no attribute 'encode'

Change-Id: I49febda11f53dc8dc794deaa21d846c5875b613e
This commit is contained in:
Ian Y. Choi 2019-06-22 15:05:35 +09:00
parent 800bfdcc19
commit b83ab91578

View File

@ -15,6 +15,7 @@
import argparse
import logging
import os
import six
import sys
import lxml.html
@ -97,7 +98,8 @@ def main():
lxml.html.fromstring(template.render()),
pretty_print=True)
else:
output = template.render(REVERSE=service_types.reverse)
output_string = template.render(REVERSE=service_types.reverse)
output = output_string.encode()
except Exception as e:
logger.error("rendering template %s failed: %s" %
(templateFile, e))
@ -113,6 +115,9 @@ def main():
os.makedirs(target_directory)
logger.debug("writing %s" % target_file)
with open(os.path.join(target_file), 'wb') as fh:
if six.PY3:
fh.write(output)
else:
fh.write(output.encode('utf8'))
except (IOError, OSError, UnicodeEncodeError) as e:
logger.error("writing %s failed: %s" % (target_file, e))