Frontends: management of unlaunched SàT Backend (information message and exit)

DBus Bridge Frontend: added an exception to manage unlaunched SàT Backend (BridgeExceptionNoService)
Quick App, jp: a message is print when the previous exception is launched
This commit is contained in:
Goffi 2010-08-09 21:36:31 +08:00
commit d2ca8812df
3 changed files with 29 additions and 11 deletions

View file

@ -55,7 +55,7 @@ from optparse import OptionParser
import pdb import pdb
from tools.jid import JID from tools.jid import JID
import gobject import gobject
from sat_bridge_frontend.DBus import DBusBridgeFrontend from sat_bridge_frontend.DBus import DBusBridgeFrontend,BridgeExceptionNoService
import tarfile import tarfile
try: try:
from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed
@ -69,7 +69,12 @@ except ImportError, e:
class JP(): class JP():
def __init__(self): 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 self.transfert_id = None
def check_options(self): def check_options(self):

View file

@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
from logging import debug, info, error from logging import debug, info, error
from tools.jid import JID from tools.jid import JID
from sat_bridge_frontend.DBus import DBusBridgeFrontend from sat_bridge_frontend.DBus import DBusBridgeFrontend,BridgeExceptionNoService
from optparse import OptionParser from optparse import OptionParser
import pdb import pdb
@ -38,7 +38,12 @@ class QuickApp():
self.check_options() self.check_options()
## bridge ## ## 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("connected", self.connected)
self.bridge.register("disconnected", self.disconnected) self.bridge.register("disconnected", self.disconnected)
self.bridge.register("newContact", self.newContact) self.bridge.register("newContact", self.newContact)

View file

@ -22,16 +22,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
from bridge_frontend import BridgeFrontend from bridge_frontend import BridgeFrontend
import dbus, dbus.glib import dbus, dbus.glib
class BridgeExceptionNoService(Exception):
pass
class DBusBridgeFrontend(BridgeFrontend): class DBusBridgeFrontend(BridgeFrontend):
def __init__(self): def __init__(self):
self.sessions_bus = dbus.SessionBus() try:
self.db_object = self.sessions_bus.get_object('org.goffi.SAT', self.sessions_bus = dbus.SessionBus()
'/org/goffi/SAT/bridge') self.db_object = self.sessions_bus.get_object('org.goffi.SAT',
self.db_comm_iface = dbus.Interface(self.db_object, '/org/goffi/SAT/bridge')
dbus_interface='org.goffi.SAT.communication') self.db_comm_iface = dbus.Interface(self.db_object,
self.db_req_iface = dbus.Interface(self.db_object, dbus_interface='org.goffi.SAT.communication')
dbus_interface='org.goffi.SAT.request') 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() #props = self.db_comm_iface.getProperties()
def register(self, functionName, handler, iface="communication"): def register(self, functionName, handler, iface="communication"):