Improve is_dict efficiency/python_verion in header
- Improve is_dict() efficiency by returning as soon as the type is determined.
- Added new dictproxy type.
- Added code to include the following in program header:
- PYTHON_VERSION
- python_version
- PYTHON_PGM_PATH
Change-Id: I3eab79dfd734ba16af12a8bc2188f55643b8c0bf
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/gen_print.py b/lib/gen_print.py
index f0bc76d..b51b51e 100755
--- a/lib/gen_print.py
+++ b/lib/gen_print.py
@@ -769,6 +769,10 @@
return 4
+def proxy_dict_type():
+ return 5
+
+
def is_dict(var_value):
r"""
Return non-zero if var_value is a type of dictionary and 0 if it is not.
@@ -782,25 +786,29 @@
type of dictionary.
"""
- type_is_dict = 0
if isinstance(var_value, dict):
- type_is_dict = dict_type()
+ return dict_type()
try:
if isinstance(var_value, collections.OrderedDict):
- type_is_dict = ordered_dict_type()
+ return ordered_dict_type()
except AttributeError:
pass
try:
if isinstance(var_value, DotDict):
- type_is_dict = dot_dict_type()
+ return dot_dict_type()
except NameError:
pass
try:
if isinstance(var_value, NormalizedDict):
- type_is_dict = normalized_dict_type()
+ return normalized_dict_type()
except NameError:
pass
- return type_is_dict
+ try:
+ if str(type(var_value)).split("'")[1] == "dictproxy":
+ return proxy_dict_type()
+ except NameError:
+ pass
+ return 0
def get_int_types():
@@ -1586,8 +1594,22 @@
DISPLAY = os.environ['DISPLAY']
except KeyError:
DISPLAY = ""
- buffer += sprint_var(DISPLAY, 0, indent,
- col1_width)
+ buffer += sprint_var(DISPLAY, 0, indent, col1_width)
+ PYTHON_VERSION = os.environ.get('PYTHON_VERSION', None)
+ if PYTHON_VERSION is not None:
+ buffer += sprint_var(PYTHON_VERSION)
+ PYTHON_PGM_PATH = os.environ.get('PYTHON_PGM_PATH', None)
+ if PYTHON_PGM_PATH is not None:
+ buffer += sprint_var(PYTHON_PGM_PATH)
+ python_version = sys.version.replace("\n", "")
+ buffer += sprint_var(python_version)
+ ROBOT_VERSION = os.environ.get('ROBOT_VERSION', None)
+ if ROBOT_VERSION is not None:
+ buffer += sprint_var(ROBOT_VERSION)
+ ROBOT_PGM_PATH = os.environ.get('ROBOT_PGM_PATH', None)
+ if ROBOT_PGM_PATH is not None:
+ buffer += sprint_var(ROBOT_PGM_PATH)
+
# TODO: Add code to print caller's parms.
# __builtin__.arg_obj is created by the get_arg module function,