[V1,1/1] framework: check the python version

Message ID 20201014031451.31487-2-yufengx.mo@intel.com (mailing list archive)
State Superseded
Headers
Series framework: check the python version |

Commit Message

Yufen.Mo Oct. 14, 2020, 3:14 a.m. UTC
  implement a method to check the python version of tester and the server that run dts.
If the version is python2, print a warning message.

Signed-off-by: yufengmx <yufengx.mo@intel.com>
---
 framework/utils.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Patch

diff --git a/framework/utils.py b/framework/utils.py
index e74e6c5..335090b 100644
--- a/framework/utils.py
+++ b/framework/utils.py
@@ -32,6 +32,7 @@ 
 import json         # json format
 import re
 import os
+import sys
 import inspect
 import socket
 import struct
@@ -280,3 +281,16 @@  def get_backtrace_object(file_name, obj_name):
         obj = getattr(frame.f_locals['self'], obj_name, None)
 
     return obj
+
+
+def check_python_version(crb):
+    cmd = 'python3 -V'
+    out = crb.send_expect(cmd, '#', 5)
+    pat = "Python (\d+).(\d+).(\d+)"
+    result = re.findall(pat, out)
+    if not result or int(result[0][0]) < 3:
+        print("WARNING: Test node is using Python 2, it is deprecated for use in DTS, and will not work in future releases.", file=sys.stderr)
+        print("Please use Python 3 instead", file=sys.stderr)
+    if sys.version_info.major < 3:
+        print("WARNING: Dts running node is using Python 2, it is deprecated for use in DTS, and will not work in future releases.", file=sys.stderr)
+        print("Please use Python 3 instead", file=sys.stderr)