restore_plug_in_value: Improve output/default determines type
- Improve the output with some additional print_vars
- Use the default value to determine the type of the value in question
and therefore to do conversions (e.g. str to int).
Change-Id: I3f27bc6bd5ec906ce726109e0e5febec87757d97
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/gen_plug_in_utils.py b/lib/gen_plug_in_utils.py
index bed1778..f5f96d60 100755
--- a/lib/gen_plug_in_utils.py
+++ b/lib/gen_plug_in_utils.py
@@ -446,11 +446,20 @@
if os.path.isfile(save_file_path):
gp.qprint_timen("Restoring " + lvalue + " value from "
+ save_file_path + ".")
- return gm.file_to_list(save_file_path, newlines=0, comments=0,
- trim=1)[0]
+ value = gm.file_to_list(save_file_path, newlines=0, comments=0,
+ trim=1)[0]
+ if type(default) is bool:
+ # Convert from string to bool.
+ value = (value == 'True')
+ if type(default) is int:
+ # Convert from string to int.
+ value = int(value)
+ gp.qprint_varx(lvalue, value)
+ return value
else:
gp.qprint_timen("Save file " + save_file_path
+ " does not exist so returning default value.")
+ gp.qprint_var(default)
return default