Adding the following support functions for use with dvt robot tests:
sprint_func_name
get_arg_name
sprint_time
sprint_timen
sprint_error
sprint_varx
sprint_var
sprint_dashes
sprint_call_stack
sprint_executing
sprint_pgm_header
sissuing
sprint_pgm_footer
create_temp_file_name
my_parm_file
rprint
rprintn
rprint_auto_vars
rpvars
Change-Id: I30f022e7bfdb92bdf083305e87aeccd94b9bd49e
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/gen_misc.py b/lib/gen_misc.py
new file mode 100755
index 0000000..167a3d9
--- /dev/null
+++ b/lib/gen_misc.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+# This module provides many valuable functions such as my_parm_file.
+
+# sys and os are needed to get the program dir path and program name.
+import sys
+import os
+import ConfigParser
+import StringIO
+
+
+###############################################################################
+def my_parm_file(prop_file_path):
+
+ r"""
+ Read a properties file, put the keys/values into a dictionary and return
+ the dictionary.
+
+ The properties file must have the following format:
+ var_name<= or :>var_value
+ Comment lines (those beginning with a "#") and blank lines are allowed and
+ will be ignored. Leading and trailing single or double quotes will be
+ stripped from the value. E.g.
+ var1="This one"
+ Quotes are stripped so the resulting value for var1 is:
+ This one
+
+ Description of arguments:
+ prop_file_path The caller should pass the path to the properties file.
+ """
+
+ # ConfigParser expects at least one section header in the file (or you
+ # get ConfigParser.MissingSectionHeaderError). Properties files don't
+ # need those so I'll write a dummy section header.
+
+ string_file = StringIO.StringIO()
+ # Write the dummy section header to the string file.
+ string_file.write('[dummysection]\n')
+ # Write the entire contents of the properties file to the string file.
+ string_file.write(open(prop_file_path).read())
+ # Rewind the string file.
+ string_file.seek(0, os.SEEK_SET)
+
+ # Create the ConfigParser object.
+ config_parser = ConfigParser.ConfigParser()
+ # Make the property names case-sensitive.
+ config_parser.optionxform = str
+ # Read the properties from the string file.
+ config_parser.readfp(string_file)
+ # Return the properties as a dictionary.
+ return dict(config_parser.items('dummysection'))
+
+###############################################################################