summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core/utils/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/core/utils/misc.py')
-rw-r--r--meta/lib/oeqa/core/utils/misc.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/utils/misc.py b/meta/lib/oeqa/core/utils/misc.py
new file mode 100644
index 0000000000..6ae58ad6c4
--- /dev/null
+++ b/meta/lib/oeqa/core/utils/misc.py
@@ -0,0 +1,37 @@
1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4def toList(obj, obj_type, obj_name="Object"):
5 if isinstance(obj, obj_type):
6 return [obj]
7 elif isinstance(obj, list):
8 return obj
9 else:
10 raise TypeError("%s must be %s or list" % (obj_name, obj_type))
11
12def toSet(obj, obj_type, obj_name="Object"):
13 if isinstance(obj, obj_type):
14 return {obj}
15 elif isinstance(obj, list):
16 return set(obj)
17 elif isinstance(obj, set):
18 return obj
19 else:
20 raise TypeError("%s must be %s or set" % (obj_name, obj_type))
21
22def strToList(obj, obj_name="Object"):
23 return toList(obj, str, obj_name)
24
25def strToSet(obj, obj_name="Object"):
26 return toSet(obj, str, obj_name)
27
28def intToList(obj, obj_name="Object"):
29 return toList(obj, int, obj_name)
30
31def dataStoteToDict(d, variables):
32 data = {}
33
34 for v in variables:
35 data[v] = d.getVar(v, True)
36
37 return data