obmc-phosphor-python-autotools: hack to support mixed python installs

Some packages are switching to 'inherit python3native' while also
having a DEPEND on a python2-based script (such as sdbus++).  Rewrite
the #! in these executables to use `nativepython` instead of `python`
so that the correct version of python and modules are found.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I5a139d7815daca0c0cfd1ceab0c97d1680aef5cc
diff --git a/classes/obmc-phosphor-python-autotools.bbclass b/classes/obmc-phosphor-python-autotools.bbclass
index d69eb34..0922a1a 100644
--- a/classes/obmc-phosphor-python-autotools.bbclass
+++ b/classes/obmc-phosphor-python-autotools.bbclass
@@ -15,3 +15,16 @@
         set_append(d, 'FILES_%s' % pkg,
                    d.getVar('PYTHON_SITEPACKAGES_DIR', True))
 }
+
+# In order to facilitate packages that use python3native, but also
+# depend on python2 scripts we need to replace the #! to be nativepython
+# instead of just python.  Without this, `which python` points to the
+# host's python, which is not the one where required modules would be
+# installed.
+do_install_append_class-native() {
+    for i in ${D}${bindir}/* ${D}${sbindir}/*; do
+        if [ -f "$i" ]; then
+            sed -i -e s:env\ python:env\ nativepython:g $i
+        fi
+    done
+}