From 70068c0f4bfcf6e385349ee601f2705ce44cb86a Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 10 Apr 2013 23:57:57 +0200 Subject: [PATCH 1/2] mpris: Only import 'indicate' if $DISPLAY is set This avoids printing of the following error message: ImportError: could not import gtk.gdk Fixes #311 --- mopidy/frontends/mpris/actor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mopidy/frontends/mpris/actor.py b/mopidy/frontends/mpris/actor.py index 92805bd3..fae8618f 100644 --- a/mopidy/frontends/mpris/actor.py +++ b/mopidy/frontends/mpris/actor.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import logging +import os import pykka @@ -10,10 +11,14 @@ from mopidy.frontends.mpris import objects logger = logging.getLogger('mopidy.frontends.mpris') try: - import indicate -except ImportError as import_error: - indicate = None # noqa - logger.debug('Startup notification will not be sent (%s)', import_error) + indicate = None + if 'DISPLAY' in os.environ: + import indicate +except ImportError: + pass + +if indicate is None: + logger.debug('Startup notification will not be sent') class MprisFrontend(pykka.ThreadingActor, CoreListener): From c1b42d97cd1ff72c9f4fa1067e57bae127ab8465 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 10 Apr 2013 23:58:55 +0200 Subject: [PATCH 2/2] mpris: Disable extension if no $DISPLAY set We cannot connect to the D-Bus session bus if there is no X11 $DISPLAY available. --- mopidy/frontends/mpris/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mopidy/frontends/mpris/__init__.py b/mopidy/frontends/mpris/__init__.py index 813e03a2..5be9c6cf 100644 --- a/mopidy/frontends/mpris/__init__.py +++ b/mopidy/frontends/mpris/__init__.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +import os + import mopidy from mopidy import exceptions, ext from mopidy.utils import formatting, config @@ -89,6 +91,10 @@ class Extension(ext.Extension): return schema def validate_environment(self): + if 'DISPLAY' not in os.environ: + raise exceptions.ExtensionError( + 'An X11 $DISPLAY is needed to use D-Bus') + try: import dbus # noqa except ImportError as e: