sync mic py2 code to mic-bootstrap if it is python2.x version 37/302437/6
authorwangbiao <biao716.wang@samsung.com>
Wed, 6 Dec 2023 11:59:43 +0000 (20:59 +0900)
committerwangbiao <biao716.wang@samsung.com>
Thu, 7 Dec 2023 03:40:04 +0000 (12:40 +0900)
Change-Id: I232e040ecff72c26d1904e120ed84f07e46769a0
Signed-off-by: wangbiao <biao716.wang@samsung.com>
mic/rt_util.py

index b3ca242accf1449b6c6d6da5ab337355ba3ad9c7..df7e163ce3b8e6e63fd4788e27e5e96802ad9d25 100644 (file)
@@ -192,6 +192,19 @@ def get_mic_modpath():
 def get_mic_libpath():
     return os.getenv("MIC_LIBRARY_PATH", "/usr/lib/mic")
 
+# check python version in mic-bootstrap
+def mic_py2_in_mic_bootstrap(binpth_in_micbootstrap):
+    #Check /usr/bin/mic file in mic bootstrap, if there is #!/usr/bin/python2 -tt, mean it is python2.x version.
+    #For python2.x version, the first line of /usr/bin/mic in mic-bootstrap is: #!/bin/python -tt
+    #For python3.x version, the first line of /usr/bin/mic in mic-bootstrap is: #!/bin/python3 -tt
+    with open(binpth_in_micbootstrap, 'r') as mic_bin:
+        first_line = mic_bin.readline()
+
+    msger.debug("first line of /usr/bin/mic in mic bootstrap: %s" % first_line)
+    if (first_line.find('python3') == -1):
+        return True
+    return False
+
 # the hard code path is prepared for bootstrap
 def sync_mic(bootstrap, binpth = '/usr/bin/mic',
              libpth='/usr/lib',
@@ -207,9 +220,23 @@ def sync_mic(bootstrap, binpth = '/usr/bin/mic',
                  'pylib': get_mic_modpath(),
                  'conf': '/etc/mic/mic.conf',
                }
+    print("True or False: %s\n" % mic_py2_in_mic_bootstrap(_path(binpth)))
+    if (mic_py2_in_mic_bootstrap(_path(binpth))):
+        mic_py2_path = get_mic_libpath() + '/mic_py2'
+        pylib = '/usr/lib/python2.7/site-packages'
+
+        micpaths = {
+            'binpth': mic_py2_path + get_mic_binpath(),
+            'libpth': mic_py2_path + get_mic_libpath(),
+            'plugin': mic_py2_path + plugin,
+            'pylib': mic_py2_path + '/usr/lib/python2.7/dist-packages/mic',
+            'conf': mic_py2_path + '/etc/mic/mic.conf',
+            }
 
     if not os.path.exists(_path(pylib)):
         pyptn = '/usr/lib/python3.*/site-packages'
+        if (mic_py2_in_mic_bootstrap(_path(binpth))):
+            pyptn = '/usr/lib/python?.?/site-packages'
         pylibs = glob.glob(_path(pyptn))
         if pylibs:
             pylib = pylibs[0].replace(bootstrap, '')
@@ -232,6 +259,7 @@ def sync_mic(bootstrap, binpth = '/usr/bin/mic',
     # chmod +x /usr/bin/mic
     os.chmod(_path(binpth), 0o777)
 
+
 def safecopy(src, dst, symlinks=False, ignore_ptns=()):
     if os.path.isdir(src):
         if os.path.isdir(dst):