Patchwork [bitbake-devel,1/1] lib/bb/ui/hob: exit cleanly if the required pygtk version isn't available

login
register
mail settings
Submitter Joshua Lock
Date April 4, 2012, 12:35 a.m.
Message ID <44c725f736689467b237b57d5c2bfe4f7d937bc5.1333499344.git.josh@linux.intel.com>
Download mbox | patch
Permalink /patch/25135/
State Accepted
Commit 192d5fdf9ea27cdc8b043204857ae5b21173a011
Headers show

Comments

Joshua Lock - April 4, 2012, 12:35 a.m.
Hob uses API from pygtk 2.22, therefore check to see whether this
version is available and exit cleanly if not.

Signed-off-by: Joshua Lock <josh@linux.intel.com>
---
 lib/bb/ui/hob.py |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
Richard Purdie - April 5, 2012, 1:01 p.m.
On Tue, 2012-04-03 at 17:35 -0700, Joshua Lock wrote:
> Hob uses API from pygtk 2.22, therefore check to see whether this
> version is available and exit cleanly if not.
> 
> Signed-off-by: Joshua Lock <josh@linux.intel.com>
> ---
>  lib/bb/ui/hob.py |   13 +++++++++++--
>  1 files changed, 11 insertions(+), 2 deletions(-)

Merged to master, thanks.

Richard

Patch

diff --git a/lib/bb/ui/hob.py b/lib/bb/ui/hob.py
index e72ab23..1321ebb 100755
--- a/lib/bb/ui/hob.py
+++ b/lib/bb/ui/hob.py
@@ -20,10 +20,19 @@ 
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-import gobject
-import gtk
 import sys
 import os
+requirements = "FATAL: pygtk (version 2.22.0 or later) and pygobject are required to use Hob"
+try:
+    import gobject
+    import gtk
+    import pygtk
+    pygtk.require('2.0') # to be certain we don't have gtk+ 1.x !?!
+    ver = gtk.pygtk_version
+    if ver  < (2, 22, 0):
+        sys.exit("%s (you have pygtk %s.%s.%s)." % (requirements, ver[0], ver[1], ver[2]))
+except ImportError as exc:
+    sys.exit("%s (%s)." % (requirements, str(exc)))
 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
 try:
     import bb