Make D-Bus an optional (recommended) dependency

Make D-Bus optional if python-dbus is not available,
not only if we're on Win32. Also, if we have D-Bus,
but getting the session bus fails, show an error and
exit. This should fix Debian Bug 520369.
This commit is contained in:
Thomas Perl 2009-05-30 11:31:02 +02:00
parent 8e7b3d6b12
commit e727b4cbaa
3 changed files with 40 additions and 19 deletions

2
README
View file

@ -32,7 +32,7 @@
* python (>= 2.5)
* python-gtk2 (>= 2.12)
* python-feedparser
* python-dbus
* python-dbus (optional, but highly recommended)
Additional dependencies for iPod synchronization support:

View file

@ -34,8 +34,15 @@ import platform
import gettext
import dbus
import dbus.glib
try:
import dbus
import dbus.glib
have_dbus = True
except ImportError:
print >>sys.stderr, """
Warning: python-dbus not found. Disabling D-Bus support.
"""
have_dbus = False
from optparse import OptionParser
@ -135,13 +142,17 @@ if __name__ == '__main__':
from gpodder.liblogger import enable_verbose
enable_verbose()
# Try to find an already-running instance of gPodder
try:
session_bus = dbus.SessionBus()
remote_object = session_bus.get_object(gpodder.dbus_bus_name, gpodder.dbus_gui_object_path)
from gpodder.liblogger import log
log('Found gPodder GUI instance already running')
except dbus.exceptions.DBusException:
if have_dbus:
# Try to find an already-running instance of gPodder
try:
session_bus = dbus.SessionBus()
remote_object = session_bus.get_object(gpodder.dbus_bus_name, gpodder.dbus_gui_object_path)
from gpodder.liblogger import log
log('Found gPodder GUI instance already running')
except dbus.exceptions.DBusException:
remote_object = None
else:
# No D-Bus available :/
remote_object = None
from gpodder import console

View file

@ -40,8 +40,13 @@ from string import strip
import gpodder
if gpodder.win32:
# Mock the required D-Bus interfaces with no-ops
try:
import dbus
import dbus.service
import dbus.mainloop
import dbus.glib
except ImportError:
# Mock the required D-Bus interfaces with no-ops (ugly? maybe.)
class dbus:
class SessionBus:
def __init__(self, *args, **kwargs):
@ -59,11 +64,6 @@ if gpodder.win32:
class Object:
def __init__(self, *args, **kwargs):
pass
else:
import dbus
import dbus.service
import dbus.mainloop
import dbus.glib
from gpodder import libtagupdate
@ -5059,8 +5059,18 @@ def main():
gobject.threads_init()
gtk.window_set_default_icon_name( 'gpodder')
session_bus = dbus.SessionBus(mainloop=dbus.glib.DBusGMainLoop())
bus_name = dbus.service.BusName(gpodder.dbus_bus_name, bus=session_bus)
try:
session_bus = dbus.SessionBus(mainloop=dbus.glib.DBusGMainLoop())
bus_name = dbus.service.BusName(gpodder.dbus_bus_name, bus=session_bus)
except dbus.exceptions.DBusException, dbe:
log('Warning: Cannot get "on the bus".', traceback=True)
dlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, \
gtk.BUTTONS_CLOSE, _('Cannot start gPodder'))
dlg.format_secondary_markup(_('D-Bus error: %s') % (str(dbe),))
dlg.set_title('gPodder')
dlg.run()
dlg.destroy()
sys.exit(0)
if gpodder.interface == gpodder.MAEMO and \
not gl.config.disable_fingerscroll: