Some APIs have been moved to other modules in python 3: getstatusoutput: moved from commands to subproces urlopen: moved from urllib2 to urllib.request urlparse: moved from urlparse to urllib.parse
Made the imports work for both python versions by catching ImportError and importing APIs from different modules. [YOCTO #9584] Signed-off-by: Ed Bartosh <[email protected]> --- bitbake/lib/bb/utils.py | 6 +++++- bitbake/lib/toaster/orm/models.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 5e735d3..92bed77 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -36,10 +36,14 @@ import traceback import errno import signal import ast -from commands import getstatusoutput from contextlib import contextmanager from ctypes import cdll +try: + from subprocess import getstatusoutput +except ImportError: + from commands import getstatusoutput + logger = logging.getLogger("BitBake.Util") python_extensions = [e for e, _, _ in imp.get_suffixes()] diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 2669606..95a3dc7 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py @@ -1146,18 +1146,26 @@ class LayerIndexLayerSource(LayerSource): assert self.apiurl is not None from django.db import transaction, connection - import urllib2, urlparse, json + import json import os + + try: + from urllib.request import urlopen, URLError + from urllib.parse import urlparse + except ImportError: + from urllib2 import urlopen, URLError + from urlparse import urlparse + proxy_settings = os.environ.get("http_proxy", None) oe_core_layer = 'openembedded-core' def _get_json_response(apiurl = self.apiurl): - _parsedurl = urlparse.urlparse(apiurl) + _parsedurl = urlparse(apiurl) path = _parsedurl.path try: - res = urllib2.urlopen(apiurl) - except urllib2.URLError as e: + res = urlopen(apiurl) + except URLError as e: raise Exception("Failed to read %s: %s" % (path, e.reason)) return json.loads(res.read()) -- 2.1.4 -- _______________________________________________ toaster mailing list [email protected] https://lists.yoctoproject.org/listinfo/toaster
