acloud: import six for compatibility between py2 and py3.
Add py-six into Androip.bp and provide simple utilities for wrapping over differences between py2 and py3.
BUG:137195528
Test: atest acloud_test --host
Change-Id: If187e6d567890a46b0b841229e5f6a6df419bffb
diff --git a/Android.bp b/Android.bp
index 3ff0421..fb9f40e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -55,7 +55,8 @@
"py-dateutil",
"py-google-api-python-client",
"py-oauth2client",
- "py-pyopenssl",
+ "py-pyopenssl",
+ "py-six",
],
dist: {
targets: ["droidcore"],
diff --git a/internal/lib/utils.py b/internal/lib/utils.py
index d484f15..fde70c5 100755
--- a/internal/lib/utils.py
+++ b/internal/lib/utils.py
@@ -38,6 +38,8 @@
import uuid
import zipfile
+import six
+
from acloud import errors
from acloud.internal import constants
@@ -1197,3 +1199,30 @@
"Try to run 'source build/envsetup.sh && lunch <target>'"
% variable_name
)
+
+
+# pylint: disable=no-member
+def FindExecutable(filename):
+ """A compatibility function to find execution file path.
+
+ Args:
+ filename: String of execution filename.
+
+ Returns:
+ String: execution file path.
+ """
+ return find_executable(filename) if six.PY2 else shutil.which(filename)
+
+
+def GetDictItems(namedtuple_object):
+ """A compatibility function to access the OrdereDict object from the given namedtuple object.
+
+ Args:
+ namedtuple_object: namedtuple object.
+
+ Returns:
+ collections.namedtuple.__dict__.items() when using python2.
+ collections.namedtuple._asdict().items() when using python3.
+ """
+ return (namedtuple_object.__dict__.items() if six.PY2
+ else namedtuple_object._asdict().items())