Commit 6a9d0146 authored by Dylan Baker's avatar Dylan Baker

framework: fix unicode command line arguments with python 2.x

In python 3.x input is unicode by default, but in python 2.x everything
is a byte string by default (which assumes ascii encoding), this
includes input. Currently when running with python 3.x it's possible to
use unicode for input, but python 2.x will choke when it tries to encode
the bytes into unicode using the ascii codec.

For example, this will work with python 3.x but no with python 2.x:
(The character is yuki, Japanese for snow, if memory serves)
./piglit run quick 雪 -c

This is actually pretty easy to fix, when running with python 2.x
decode each input element into unicode using utf-8 as soon as the input
is received. This fixes the above example to work.
Signed-off-by: default avatarDylan Baker <dylanx.c.baker@intel.com>
Tested-by: default avatarMarek Olšák <marek.olsak@amd.com>
parent cc83192b
...@@ -31,12 +31,16 @@ capture -h/--help and the results will not be useful. ...@@ -31,12 +31,16 @@ capture -h/--help and the results will not be useful.
""" """
from __future__ import print_function from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import argparse
import os import os
import os.path as path import os.path as path
import sys import sys
import argparse
import six
def setup_module_search_path(): def setup_module_search_path():
"""Add Piglit's data directory to Python's module search path. """Add Piglit's data directory to Python's module search path.
...@@ -110,6 +114,11 @@ import framework.programs.summary as summary ...@@ -110,6 +114,11 @@ import framework.programs.summary as summary
def main(): def main():
""" Parse argument and call other executables """ """ Parse argument and call other executables """
if six.PY2:
input_ = [i.decode('utf-8') for i in sys.argv[1:]]
elif six.PY3:
input_ = sys.argv[1:]
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
...@@ -147,7 +156,7 @@ def main(): ...@@ -147,7 +156,7 @@ def main():
# Parse the known arguments (piglit run or piglit summary html for # Parse the known arguments (piglit run or piglit summary html for
# example), and then pass the arguments that this parser doesn't know about # example), and then pass the arguments that this parser doesn't know about
# to that executable # to that executable
parsed, args = parser.parse_known_args() parsed, args = parser.parse_known_args(input_)
returncode = parsed.func(args) returncode = parsed.func(args)
sys.exit(returncode) sys.exit(returncode)
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
from __future__ import print_function from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import argparse import argparse
import sys import sys
import os import os
...@@ -36,6 +38,7 @@ from framework.test import Test, GleanTest ...@@ -36,6 +38,7 @@ from framework.test import Test, GleanTest
def main(): def main():
input_ = [i.decode('utf-8') for i in sys.argv[1:]]
parser = argparse.ArgumentParser(parents=[parsers.CONFIG]) parser = argparse.ArgumentParser(parents=[parsers.CONFIG])
parser.add_argument("-t", "--include-tests", parser.add_argument("-t", "--include-tests",
default=[], default=[],
...@@ -52,7 +55,7 @@ def main(): ...@@ -52,7 +55,7 @@ def main():
parser.add_argument("testProfile", parser.add_argument("testProfile",
metavar="<Path to testfile>", metavar="<Path to testfile>",
help="Path to results folder") help="Path to results folder")
args = parser.parse_args() args = parser.parse_args(input_)
options.OPTIONS.exclude_filter = args.exclude_tests options.OPTIONS.exclude_filter = args.exclude_tests
options.OPTIONS.include_filter = args.include_tests options.OPTIONS.include_filter = args.include_tests
......
...@@ -26,7 +26,11 @@ Deprecated compatability wrapper ...@@ -26,7 +26,11 @@ Deprecated compatability wrapper
""" """
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import sys import sys
from framework.programs.run import resume from framework.programs.run import resume
resume(sys.argv[1:]) resume([i.decode('utf-8') for i in sys.argv[1:]])
...@@ -26,7 +26,11 @@ Deprecated compatability wrapper ...@@ -26,7 +26,11 @@ Deprecated compatability wrapper
""" """
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import sys import sys
from framework.programs.run import run from framework.programs.run import run
run(sys.argv[1:]) run([i.decode('utf-8') for i in sys.argv[1:]])
...@@ -22,7 +22,11 @@ ...@@ -22,7 +22,11 @@
""" Deprecated compatability wrapper for html summary """ """ Deprecated compatability wrapper for html summary """
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import sys import sys
from framework.programs.summary import html from framework.programs.summary import html
html(sys.argv[1:]) html([i.decode('utf-8') for i in sys.argv[1:]])
...@@ -22,7 +22,11 @@ ...@@ -22,7 +22,11 @@
""" Deprecated compatability wrapper for console summary """ """ Deprecated compatability wrapper for console summary """
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import sys import sys
from framework.programs.summary import console from framework.programs.summary import console
console(sys.argv[1:]) console([i.decode('utf-8') for i in sys.argv[1:]])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment