summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2016-05-10 14:35:55 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-16 23:32:41 +0100
commit973b6b961597e421d06607908300441de3ff4e0c (patch)
tree822bf355bdf2550d1cff25f9a68b1baa60c1778f
parent909f1b7bf83d17efd06bcf470364385efe2704be (diff)
downloadpoky-973b6b961597e421d06607908300441de3ff4e0c.tar.gz
bitbake: toaster: fix imports to work for python 3
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] (Bitbake rev: 5c39479fd7cb1b7c0bfc50c8cdfb9e5453bfa8e8) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/utils.py1
-rw-r--r--bitbake/lib/toaster/orm/models.py16
2 files changed, 12 insertions, 5 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 138da44ef1..8f75871c18 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -41,7 +41,6 @@ from subprocess import getstatusoutput
41from contextlib import contextmanager 41from contextlib import contextmanager
42from ctypes import cdll 42from ctypes import cdll
43 43
44
45logger = logging.getLogger("BitBake.Util") 44logger = logging.getLogger("BitBake.Util")
46python_extensions = [e for e, _, _ in imp.get_suffixes()] 45python_extensions = [e for e, _, _ in imp.get_suffixes()]
47 46
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index 88967a23f5..9183b0cd7c 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -1147,18 +1147,26 @@ class LayerIndexLayerSource(LayerSource):
1147 assert self.apiurl is not None 1147 assert self.apiurl is not None
1148 from django.db import transaction, connection 1148 from django.db import transaction, connection
1149 1149
1150 import urllib2, urlparse, json 1150 import json
1151 import os 1151 import os
1152
1153 try:
1154 from urllib.request import urlopen, URLError
1155 from urllib.parse import urlparse
1156 except ImportError:
1157 from urllib2 import urlopen, URLError
1158 from urlparse import urlparse
1159
1152 proxy_settings = os.environ.get("http_proxy", None) 1160 proxy_settings = os.environ.get("http_proxy", None)
1153 oe_core_layer = 'openembedded-core' 1161 oe_core_layer = 'openembedded-core'
1154 1162
1155 def _get_json_response(apiurl = self.apiurl): 1163 def _get_json_response(apiurl = self.apiurl):
1156 _parsedurl = urlparse.urlparse(apiurl) 1164 _parsedurl = urlparse(apiurl)
1157 path = _parsedurl.path 1165 path = _parsedurl.path
1158 1166
1159 try: 1167 try:
1160 res = urllib2.urlopen(apiurl) 1168 res = urlopen(apiurl)
1161 except urllib2.URLError as e: 1169 except URLError as e:
1162 raise Exception("Failed to read %s: %s" % (path, e.reason)) 1170 raise Exception("Failed to read %s: %s" % (path, e.reason))
1163 1171
1164 return json.loads(res.read()) 1172 return json.loads(res.read())