cli: deploy: Don't assume the Python interpreter

Portage may be installed for a different interpreter than
/usr/bin/python.  Stop assuming that's the interpreter we should use
for Portage, and instead detect it by searching for the emerge
launcher in /usr/lib/python-exec.

BUG=b:291125423
TEST="cros deploy" a package onto a device with Portage installed for
     Python 3.8
TEST=unit tests

Change-Id: I640ad922b45bf2d56a2a6678e96225456bb13b82
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4685754
Auto-Submit: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Alex Klein <saklein@chromium.org>
Commit-Queue: Alex Klein <saklein@chromium.org>
Tested-by: Jack Rosenthal <jrosenth@chromium.org>
diff --git a/cli/deploy_unittest.py b/cli/deploy_unittest.py
index 8683baf..6b104cb 100644
--- a/cli/deploy_unittest.py
+++ b/cli/deploy_unittest.py
@@ -206,6 +206,11 @@
         )
 
     def SetupVartree(self, vartree_pkgs):
+        self.PatchObject(
+            self.scanner,
+            "_get_portage_interpreter",
+            return_value="FAKE_PYTHON",
+        )
         self.device.agent.remote_sh_output = json.dumps(vartree_pkgs)
 
     def SetupBintree(self, bintree_pkgs):
@@ -425,6 +430,18 @@
         self.ValidatePkgs(listed, [app1])
         self.assertEqual(num_updates, 1)
 
+    def test_get_portage_interpreter(self):
+        """Test getting the portage interpreter from the device."""
+        self.device.agent.remote_sh_output = """\
+/usr/lib/python-exec/python3.6/emerge
+/usr/lib/python-exec/python3.8/emerge
+/usr/lib/python-exec/python3.11/emerge
+"""
+        self.assertEqual(
+            self.scanner._get_portage_interpreter(self.device),
+            "python3.11",
+        )
+
 
 class TestDeploy(
     cros_test_lib.ProgressBarTestCase, cros_test_lib.MockTempDirTestCase