[dts] [PATCH v1 1/2] framework/utils: add function to retrieve object from backtrace

Marvin Liu yong.liu at intel.com
Thu Jan 25 20:48:12 CET 2018


Sometimes can't find required variable for overall arch. Add one
function can retrieve those variables from callback frame.

Signed-off-by: Marvin Liu <yong.liu at intel.com>

diff --git a/framework/utils.py b/framework/utils.py
index 762c927..a0dcf8f 100644
--- a/framework/utils.py
+++ b/framework/utils.py
@@ -233,3 +233,22 @@ def convert_ip2int(ip_str, ip_type):
         ip_val = (h << 64) | l
 
     return ip_val
+
+def get_backtrace_object(file_name, obj_name):
+    import inspect
+    frame = inspect.currentframe()
+    obj = None
+    found = False
+    while frame:
+        file_path = inspect.getsourcefile(frame)
+        call_file = file_path.split(os.sep)[-1]
+        if file_name == call_file:
+            found = True
+            break
+
+        frame = frame.f_back
+
+    if found:
+        obj = getattr(frame.f_locals['self'], obj_name, None)
+
+    return obj
-- 
1.9.3



More information about the dts mailing list