Skip to contentSkip to conversation

lib/ui/taskexp: Validate gi import

PATCH In review David Khouya 3 participants 7 messages Jul 1, 2020 – Jul 7, 2020 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/ui/taskexp: Validate gi import

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.

---
 lib/bb/ui/taskexp.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
lib/bb/ui/taskexp.py +9 -3
index 8fff2442..336d197d 100644
@@ -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
Signature · 1 line
2.25.1
#1 lore raw
Quoted 26 lines · David Khouya

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.

---
  lib/bb/ui/taskexp.py | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
lib/bb/ui/taskexp.py +2 -3
index 8fff2442..336d197d 100644
@@ -8,9 +8,15 @@
  #
 
  import sys
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk, Gdk, GObject
+
+try:

lib/bb/ui/taskexp.py line 22

Quoted 10 lines
lib/bb/ui/taskexp.py +7 -0
+    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

With this patch applied I get:

Traceback (most recent call last):
File "/home/jkroon/Projects/foo-linux/bitbake/bin/bitbake", line 35,
in <module>
sys.exit(bitbake_main(BitBakeConfigParameters(sys.argv),
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
366, in bitbake_main
server_connection, ui_module = setup_bitbake(configParams,
configuration)
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
404, in setup_bitbake
ui_module = import_extension_module(bb.ui, configParams.ui, 'main')
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
96, in import_extension_module

    module = __import__(pkg.__name__, fromlist=[modulename])

File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/ui/taskexp.py",
line 33, in <module>
class PackageDepView(Gtk.TreeView):
NameError: name 'Gtk' is not defined

Reverting the patch allows me to run

bitbake -g -u taskexp core-image-minimal

and browsing via the Gtk UI works fine.

Jacob

#2 lore raw

Thanks Jacob for the feedback. I'll submit a patch v2 with the changes

Quoted 68 lines · Jacob Kroon
Quoted 20 lines · David Khouya

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.

---
  lib/bb/ui/taskexp.py | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
lib/bb/ui/taskexp.py +0 -1
index 8fff2442..336d197d 100644
@@ -8,9 +8,15 @@
  #
 
  import sys
-import gi

lib/bb/ui/taskexp.py line 18

Quoted 10 lines
lib/bb/ui/taskexp.py +8 -2
-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")

lib/bb/ui/taskexp.py line 22

Quoted 6 lines
lib/bb/ui/taskexp.py +1 -0
+
  import threading
  from xmlrpc import client
  import bb

With this patch applied I get:

Traceback (most recent call last):
File "/home/jkroon/Projects/foo-linux/bitbake/bin/bitbake", line 35,
in <module>
sys.exit(bitbake_main(BitBakeConfigParameters(sys.argv),
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
366, in bitbake_main
server_connection, ui_module = setup_bitbake(configParams,
configuration)
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
404, in setup_bitbake
ui_module = import_extension_module(bb.ui, configParams.ui, 'main')
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
96, in import_extension_module

     module = __import__(pkg.__name__, fromlist=[modulename])

File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/ui/taskexp.py",
line 33, in <module>
class PackageDepView(Gtk.TreeView):
NameError: name 'Gtk' is not defined

Reverting the patch allows me to run

bitbake -g -u taskexp core-image-minimal

and browsing via the Gtk UI works fine.

Jacob

#3 lore raw

It's already in master:
https://git.openembedded.org/bitbake/commit/?id=2a2c507f239b047f34765312df4168030e38b90d
you should send a separate fixup patch instead of v2.

Quoted 75 lines · David Khouya

Thanks Jacob for the feedback. I'll submit a patch v2 with the changes

Quoted 68 lines · Jacob Kroon
Quoted 20 lines · David Khouya

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.

---
  lib/bb/ui/taskexp.py | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
lib/bb/ui/taskexp.py +0 -1
index 8fff2442..336d197d 100644
@@ -8,9 +8,15 @@
  #
 
  import sys
-import gi

lib/bb/ui/taskexp.py line 18

Quoted 10 lines
lib/bb/ui/taskexp.py +8 -2
-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")

lib/bb/ui/taskexp.py line 22

Quoted 6 lines
lib/bb/ui/taskexp.py +1 -0
+
  import threading
  from xmlrpc import client
  import bb

With this patch applied I get:

Traceback (most recent call last):
File "/home/jkroon/Projects/foo-linux/bitbake/bin/bitbake", line 35,
in <module>
sys.exit(bitbake_main(BitBakeConfigParameters(sys.argv),
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
366, in bitbake_main
server_connection, ui_module = setup_bitbake(configParams,
configuration)
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
404, in setup_bitbake
ui_module = import_extension_module(bb.ui, configParams.ui, 'main')
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
96, in import_extension_module

     module = __import__(pkg.__name__, fromlist=[modulename])

File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/ui/taskexp.py",
line 33, in <module>
class PackageDepView(Gtk.TreeView):
NameError: name 'Gtk' is not defined

Reverting the patch allows me to run

bitbake -g -u taskexp core-image-minimal

and browsing via the Gtk UI works fine.

Jacob

#4 lore raw

Perfect, will do.

Quoted 83 lines · Martin Jansa

It's already in master:

https://git.openembedded.org/bitbake/commit/?id=2a2c507f239b047f34765312df4168030e38b90d
you should send a separate fixup patch instead of v2.

Quoted 75 lines · David Khouya

Thanks Jacob for the feedback. I'll submit a patch v2 with the changes

Quoted 68 lines · Jacob Kroon
Quoted 20 lines · David Khouya

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.

---
  lib/bb/ui/taskexp.py | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
lib/bb/ui/taskexp.py +0 -1
index 8fff2442..336d197d 100644
@@ -8,9 +8,15 @@
  #
 
  import sys
-import gi

lib/bb/ui/taskexp.py line 18

Quoted 10 lines
lib/bb/ui/taskexp.py +8 -2
-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")

lib/bb/ui/taskexp.py line 22

Quoted 6 lines
lib/bb/ui/taskexp.py +1 -0
+
  import threading
  from xmlrpc import client
  import bb

With this patch applied I get:

Traceback (most recent call last):
File "/home/jkroon/Projects/foo-linux/bitbake/bin/bitbake", line 35,
in <module>
sys.exit(bitbake_main(BitBakeConfigParameters(sys.argv),
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
366, in bitbake_main
server_connection, ui_module = setup_bitbake(configParams,
configuration)
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
404, in setup_bitbake
ui_module = import_extension_module(bb.ui, configParams.ui, 'main')
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
96, in import_extension_module

     module = __import__(pkg.__name__, fromlist=[modulename])

File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/ui/taskexp.py",
line 33, in <module>
class PackageDepView(Gtk.TreeView):
NameError: name 'Gtk' is not defined

Reverting the patch allows me to run

bitbake -g -u taskexp core-image-minimal

and browsing via the Gtk UI works fine.

Jacob

Signature · 1 line
*David Khouya*

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

I pushed a commit on my fork if you want to give it a try. It works on my side.

https://github.com/dakhouya/bitbake/commit/3af4530571cef1b6ec58f810b89f6f35a14cc475

I'll send a patch for that this evening.

Quoted 95 lines · David Khouya via lists.openembedded.org

Perfect, will do.

Quoted 83 lines · Martin Jansa

It's already in master:

https://git.openembedded.org/bitbake/commit/?id=2a2c507f239b047f34765312df4168030e38b90d
you should send a separate fixup patch instead of v2.

Quoted 76 lines · David Khouya

Thanks Jacob for the feedback. I'll submit a patch v2 with the changes

Quoted 68 lines · Jacob Kroon
Quoted 20 lines · David Khouya

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.

---
  lib/bb/ui/taskexp.py | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
lib/bb/ui/taskexp.py +0 -1
index 8fff2442..336d197d 100644
@@ -8,9 +8,15 @@
  #
 
  import sys
-import gi

lib/bb/ui/taskexp.py line 18

Quoted 10 lines
lib/bb/ui/taskexp.py +8 -2
-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")

lib/bb/ui/taskexp.py line 22

Quoted 6 lines
lib/bb/ui/taskexp.py +1 -0
+
  import threading
  from xmlrpc import client
  import bb

With this patch applied I get:

Traceback (most recent call last):
File "/home/jkroon/Projects/foo-linux/bitbake/bin/bitbake", line 35,
in <module>
sys.exit(bitbake_main(BitBakeConfigParameters(sys.argv),
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
366, in bitbake_main
server_connection, ui_module = setup_bitbake(configParams,
configuration)
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
404, in setup_bitbake
ui_module = import_extension_module(bb.ui, configParams.ui, 'main')
File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/main.py", line
96, in import_extension_module

     module = __import__(pkg.__name__, fromlist=[modulename])

File "/home/jkroon/Projects/foo-linux/bitbake/lib/bb/ui/taskexp.py",
line 33, in <module>
class PackageDepView(Gtk.TreeView):
NameError: name 'Gtk' is not defined

Reverting the patch allows me to run

bitbake -g -u taskexp core-image-minimal

and browsing via the Gtk UI works fine.

Jacob

--
*David Khouya*

Signature · 1 line
*David Khouya*