Fix python3.x compatibility for stable 2.0 branch
Change-Id: I958d02873e4ba76be72230365dff8e500fa31b3c
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/boot_data.py b/lib/boot_data.py
index 8dfdff0..070a0e6 100755
--- a/lib/boot_data.py
+++ b/lib/boot_data.py
@@ -74,7 +74,7 @@
# For every boot_type we should have a corresponding mfg mode boot type.
enhanced_boot_table = DotDict()
- for key, value in boot_table.iteritems():
+ for key, value in boot_table.items():
enhanced_boot_table[key] = value
enhanced_boot_table[key + " (mfg)"] = value
diff --git a/lib/gen_cmd.py b/lib/gen_cmd.py
index 3b99fbc..d6ae199 100644
--- a/lib/gen_cmd.py
+++ b/lib/gen_cmd.py
@@ -96,21 +96,23 @@
out_buf = ""
if return_stderr:
for line in sub_proc.stderr:
- err_buf += line
+ try:
+ err_buf += line
+ except TypeError:
+ line = line.decode("utf-8")
+ err_buf += line
if not print_output:
continue
- if robot_env:
- grp.rprint(line)
- else:
- sys.stdout.write(line)
+ gp.gp_print(line)
for line in sub_proc.stdout:
- out_buf += line
+ try:
+ out_buf += line
+ except TypeError:
+ line = line.decode("utf-8")
+ out_buf += line
if not print_output:
continue
- if robot_env:
- grp.rprint(line)
- else:
- sys.stdout.write(line)
+ gp.gp_print(line)
if print_output and not robot_env:
sys.stdout.flush()
sub_proc.communicate()
@@ -417,12 +419,20 @@
try:
if return_stderr:
for line in sub_proc.stderr:
- err_buf += line
+ try:
+ err_buf += line
+ except TypeError:
+ line = line.decode("utf-8")
+ err_buf += line
if not print_output:
continue
func_stdout += line
for line in sub_proc.stdout:
- out_buf += line
+ try:
+ out_buf += line
+ except TypeError:
+ line = line.decode("utf-8")
+ out_buf += line
if not print_output:
continue
func_stdout += line
diff --git a/lib/gen_plug_in.py b/lib/gen_plug_in.py
index 1bd70a1..2cfd3e0 100755
--- a/lib/gen_plug_in.py
+++ b/lib/gen_plug_in.py
@@ -6,7 +6,11 @@
import sys
import os
-import commands
+try:
+ import commands
+except ImportError:
+ import subprocess
+
import glob
import gen_print as gp
diff --git a/lib/gen_robot_plug_in.py b/lib/gen_robot_plug_in.py
index 5c1dd06..cfcb660 100755
--- a/lib/gen_robot_plug_in.py
+++ b/lib/gen_robot_plug_in.py
@@ -8,7 +8,11 @@
import sys
import subprocess
from robot.libraries.BuiltIn import BuiltIn
-import commands
+try:
+ import commands
+except ImportError:
+ import subprocess
+
import os
import tempfile
diff --git a/lib/gen_robot_utils.py b/lib/gen_robot_utils.py
index 281c27a..fd15eed 100644
--- a/lib/gen_robot_utils.py
+++ b/lib/gen_robot_utils.py
@@ -66,7 +66,7 @@
# If any variable values were changed due to the prior import, set them
# back to their original values.
- for key, value in post_var_dict.iteritems():
+ for key, value in post_var_dict.items():
if key in pre_var_dict:
if value != pre_var_dict[key]:
global_var_name = re.sub("[@&]", "$", key)
diff --git a/lib/state.py b/lib/state.py
index 0aae066..78f4cf4 100755
--- a/lib/state.py
+++ b/lib/state.py
@@ -34,7 +34,11 @@
import gen_cmd as gc
import bmc_ssh_utils as bsu
-import commands
+try:
+ import commands
+except ImportError:
+ import subprocess
+
from robot.libraries.BuiltIn import BuiltIn
from robot.utils import DotDict