[bitbake-devel,dunfell,1.46,1/8] lib/ui/taskexp: Validate gi import

Submitted by Steve Sakoman on July 15, 2020, 2:26 p.m. | Patch ID: 174451

Details

Message ID 45e32f2651d35bf7a315af95cfe0b1070e038c9e.1594822992.git.steve@sakoman.com
State New
Headers show

Commit Message

Steve Sakoman July 15, 2020, 2:26 p.m.
From: David Khouya <dakhouya@gmail.com>

When running bitbake -g -u taskexp without having gi python module or
and invalid gtk version, bitbake fails with a stack trace.

In case of import or version error, bitbake should exit with an error
message instead of a stack trace.

Signed-off-by: David Khouya <dakhouya@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 2a2c507f239b047f34765312df4168030e38b90d)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
 lib/bb/ui/taskexp.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/bb/ui/taskexp.py b/lib/bb/ui/taskexp.py
index 8fff2442..336d197d 100644
--- a/lib/bb/ui/taskexp.py
+++ b/lib/bb/ui/taskexp.py
@@ -8,9 +8,15 @@ 
 #
 
 import sys
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk, Gdk, GObject
+
+try:
+    import gi
+    gi.require_version('Gtk', '3.0')
+except ValueError:
+    sys.exit("FATAL: Gtk version needs to be 3.0")
+except ImportError:
+    sys.exit("FATAL: Gtk ui could not load the required gi python module")
+
 import threading
 from xmlrpc import client
 import bb