[PATCH 20/20] oeqa.utils.readconfig: Read self-test configuration file

Jose Lamego
2016-08-08T16:23:23Z

This library reads a configuration file located at the
oeqa/selftest/conf directory with same name as the caller
file and the conf extension.

[Yocto 9389]

Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
---
meta/lib/oeqa/utils/readconfig.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 meta/lib/oeqa/utils/readconfig.py

diff --git a/meta/lib/oeqa/utils/readconfig.py b/meta/lib/oeqa/utils/readconfig.py
new file mode 100644
index 0000000..1534ce7
--- /dev/null
+++ b/meta/lib/oeqa/utils/readconfig.py
@@ -0,0 +1,18 @@
+import os
+import re
+import configparser
+
+
+def conffile(codefile):
+ # Get test configurations from configuration file
+ f = re.compile(r'(pyc?$)')
+ fn = os.path.basename(codefile)
+ configfile = os.path.join(os.path.dirname(codefile), 'conf',
+ f.sub('conf', fn))
+ config = configparser.SafeConfigParser()
+ read_result = config.read(configfile)
+ if read_result == []:
+ raise configparser.Error("Failed to get test configuration from \
+\"%s\". Verify that file exists and format is correct."
+ % configfile)
+ return config
--
1.8.3.1