D-Bus testing: support git glib/gobject bindings

More recent GNOME Python bindings are provided by gobject
introspection. The traditional gobject/glib modules no
longer exist.

The API is similar enough that we just need to adapt importing: if
importing the normal modules fails, try importing from gi.repository
instead.
This commit is contained in:
Patrick Ohly 2013-06-13 10:04:39 +02:00
parent 9c6022bd13
commit 0c63a4f7f0
2 changed files with 19 additions and 6 deletions

View File

@ -42,7 +42,6 @@ import traceback
import re
import itertools
import codecs
import glib
import pprint
import shutil
@ -54,6 +53,9 @@ testFolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect
if testFolder not in sys.path:
sys.path.insert(0, testFolder)
# Rely on the glib/gobject compatibility import code in test-dbus.py.
from testdbus import glib, gobject
from testdbus import DBusUtil, timeout, property, usingValgrind, xdg_root, bus, logging, NullLogging, loop
import testdbus

View File

@ -42,8 +42,6 @@ import socket
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import dbus.service
import gobject
import glib
import sys
import traceback
import re
@ -52,11 +50,24 @@ import base64
# introduced in python-gobject 2.16, not available
# on all Linux distros => make it optional
glib = None
try:
import glib
have_glib = True
except ImportError:
have_glib = False
try:
from gi.repository import GLib as glib
except ImportError:
pass
gobject = None
try:
import gobject
except ImportError:
try:
from gi.repository import GObject as gobject
except ImportError:
pass
DBusGMainLoop(set_as_default=True)
@ -251,7 +262,7 @@ class Timeout:
be executed. It was observed that trying to append to
DBusUtil.quit_events before calling loop.quit() caused
a KeyboardInterrupt"""
if have_glib and use_glib:
if glib and use_glib:
return glib.timeout_add(delay_seconds, callback)
else:
now = time.time()