[oe-commits] [bitbake] 12/23: toaster: fix imports to work for python 3

git at git.openembedded.org git at git.openembedded.org
Fri May 20 09:13:41 UTC 2016


rpurdie pushed a commit to branch python3
in repository bitbake.

commit 4e93b149bca4271b64132a29065efc3981e668de
Author: Ed Bartosh <ed.bartosh at linux.intel.com>
AuthorDate: Tue May 10 14:35:55 2016 +0300

    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]
    
    Signed-off-by: Ed Bartosh <ed.bartosh at linux.intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 lib/bb/utils.py           |  1 -
 lib/toaster/orm/models.py | 16 ++++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 138da44..8f75871 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -41,7 +41,6 @@ from subprocess import getstatusoutput
 from contextlib import contextmanager
 from ctypes import cdll
 
-
 logger = logging.getLogger("BitBake.Util")
 python_extensions = [e for e, _, _ in imp.get_suffixes()]
 
diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py
index 88967a2..9183b0c 100644
--- a/lib/toaster/orm/models.py
+++ b/lib/toaster/orm/models.py
@@ -1147,18 +1147,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())

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list