From d2ca8812df06dfdc52c50d59a23ac2dd1597322c Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 9 Aug 2010 21:36:31 +0800 Subject: [PATCH] =?UTF-8?q?Frontends:=20management=20of=20unlaunched=20S?= =?UTF-8?q?=C3=A0T=20Backend=20(information=20message=20and=20exit)=20DBus?= =?UTF-8?q?=20Bridge=20Frontend:=20added=20an=20exception=20to=20manage=20?= =?UTF-8?q?unlaunched=20S=C3=A0T=20Backend=20(BridgeExceptionNoService)=20?= =?UTF-8?q?Quick=20App,=20jp:=20a=20message=20is=20print=20when=20the=20pr?= =?UTF-8?q?evious=20exception=20is=20launched?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontends/jp/jp | 9 +++++++-- frontends/quick_frontend/quick_app.py | 9 +++++++-- frontends/sat_bridge_frontend/DBus.py | 22 +++++++++++++++------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/frontends/jp/jp b/frontends/jp/jp index e5fe57e6..8d8383d8 100755 --- a/frontends/jp/jp +++ b/frontends/jp/jp @@ -55,7 +55,7 @@ from optparse import OptionParser import pdb from tools.jid import JID import gobject -from sat_bridge_frontend.DBus import DBusBridgeFrontend +from sat_bridge_frontend.DBus import DBusBridgeFrontend,BridgeExceptionNoService import tarfile try: from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed @@ -69,7 +69,12 @@ except ImportError, e: class JP(): def __init__(self): - self.bridge=DBusBridgeFrontend() + try: + self.bridge=DBusBridgeFrontend() + except BridgeExceptionNoService: + print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) + import sys + sys.exit(1) self.transfert_id = None def check_options(self): diff --git a/frontends/quick_frontend/quick_app.py b/frontends/quick_frontend/quick_app.py index 3da37338..7336628e 100644 --- a/frontends/quick_frontend/quick_app.py +++ b/frontends/quick_frontend/quick_app.py @@ -21,7 +21,7 @@ along with this program. If not, see . from logging import debug, info, error from tools.jid import JID -from sat_bridge_frontend.DBus import DBusBridgeFrontend +from sat_bridge_frontend.DBus import DBusBridgeFrontend,BridgeExceptionNoService from optparse import OptionParser import pdb @@ -38,7 +38,12 @@ class QuickApp(): self.check_options() ## bridge ## - self.bridge=DBusBridgeFrontend() + try: + self.bridge=DBusBridgeFrontend() + except BridgeExceptionNoService: + print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) + import sys + sys.exit(1) self.bridge.register("connected", self.connected) self.bridge.register("disconnected", self.disconnected) self.bridge.register("newContact", self.newContact) diff --git a/frontends/sat_bridge_frontend/DBus.py b/frontends/sat_bridge_frontend/DBus.py index 42d960a0..4ba420ca 100755 --- a/frontends/sat_bridge_frontend/DBus.py +++ b/frontends/sat_bridge_frontend/DBus.py @@ -22,16 +22,24 @@ along with this program. If not, see . from bridge_frontend import BridgeFrontend import dbus, dbus.glib +class BridgeExceptionNoService(Exception): + pass class DBusBridgeFrontend(BridgeFrontend): def __init__(self): - self.sessions_bus = dbus.SessionBus() - self.db_object = self.sessions_bus.get_object('org.goffi.SAT', - '/org/goffi/SAT/bridge') - self.db_comm_iface = dbus.Interface(self.db_object, - dbus_interface='org.goffi.SAT.communication') - self.db_req_iface = dbus.Interface(self.db_object, - dbus_interface='org.goffi.SAT.request') + try: + self.sessions_bus = dbus.SessionBus() + self.db_object = self.sessions_bus.get_object('org.goffi.SAT', + '/org/goffi/SAT/bridge') + self.db_comm_iface = dbus.Interface(self.db_object, + dbus_interface='org.goffi.SAT.communication') + self.db_req_iface = dbus.Interface(self.db_object, + dbus_interface='org.goffi.SAT.request') + except dbus.exceptions.DBusException,e: + if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': + raise BridgeExceptionNoService + else: + raise e #props = self.db_comm_iface.getProperties() def register(self, functionName, handler, iface="communication"):