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:
parent
800bfdcc19
commit
b83ab91578
@ -15,6 +15,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import six
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import lxml.html
|
import lxml.html
|
||||||
@ -97,7 +98,8 @@ def main():
|
|||||||
lxml.html.fromstring(template.render()),
|
lxml.html.fromstring(template.render()),
|
||||||
pretty_print=True)
|
pretty_print=True)
|
||||||
else:
|
else:
|
||||||
output = template.render(REVERSE=service_types.reverse)
|
output_string = template.render(REVERSE=service_types.reverse)
|
||||||
|
output = output_string.encode()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("rendering template %s failed: %s" %
|
logger.error("rendering template %s failed: %s" %
|
||||||
(templateFile, e))
|
(templateFile, e))
|
||||||
@ -113,7 +115,10 @@ def main():
|
|||||||
os.makedirs(target_directory)
|
os.makedirs(target_directory)
|
||||||
logger.debug("writing %s" % target_file)
|
logger.debug("writing %s" % target_file)
|
||||||
with open(os.path.join(target_file), 'wb') as fh:
|
with open(os.path.join(target_file), 'wb') as fh:
|
||||||
fh.write(output.encode('utf8'))
|
if six.PY3:
|
||||||
|
fh.write(output)
|
||||||
|
else:
|
||||||
|
fh.write(output.encode('utf8'))
|
||||||
except (IOError, OSError, UnicodeEncodeError) as e:
|
except (IOError, OSError, UnicodeEncodeError) as e:
|
||||||
logger.error("writing %s failed: %s" % (target_file, e))
|
logger.error("writing %s failed: %s" % (target_file, e))
|
||||||
raise
|
raise
|
||||||
|
Loading…
Reference in New Issue
Block a user