html.py must run with either Python 2 or 3 to support COPR builds
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Fri, 4 Feb 2022 16:26:52 +0000 (17:26 +0100)
committerDaniel Lenski <dlenski@gmail.com>
Thu, 17 Feb 2022 18:35:32 +0000 (10:35 -0800)
The script starts with `#!/usr/bin/env python3` but COPR builds run it as
`/usr/bin/python2 "./html.py"`. In the long term we should phase out Python
2 and make sure Python 3 is used everywhere.  In the short term, let's
repair COPR builds first, then plan the Python 2 to 3 transition.

This reverts e83b646f.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
www/html.py

index 8c71d988e2f2d9ce07ea12b4bedd1461e23e26b6..2b7b69db4582f6622e178e8ea3966de489ef54b2 100755 (executable)
@@ -14,7 +14,13 @@ import getopt
 import xml.sax
 import codecs
 
-sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
+if sys.version_info >= (3, 0):
+    sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
+else:
+    # reload() always needed because of https://docs.python.org/2.7/library/sys.html#sys.setdefaultencoding
+    reload(sys)
+    sys.setdefaultencoding('utf-8')
+    sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
 
 lookupdir = ''