core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:

- new BridgeInitError and BridgeExceptionNoService are in core.exceptions
    - D-Bus NotSupported is catched in bridge, and launch a BridgeInitError
    - BridgeInitError stop SàT core, jp, and quick_frontends with an explanation message.
fix bug 27
This commit is contained in:
Goffi 2013-06-21 02:00:37 +02:00
commit 8e2f394b5b
3 changed files with 55 additions and 26 deletions

View file

@ -20,6 +20,7 @@
from bridge_frontend import BridgeFrontend
import dbus
from logging import debug, error
from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
@ -31,10 +32,6 @@ const_CORE_SUFFIX = ".core"
const_PLUGIN_SUFFIX = ".plugin"
class BridgeExceptionNoService(Exception):
pass
class DBusBridgeFrontend(BridgeFrontend):
def __init__(self):
try:
@ -48,6 +45,9 @@ class DBusBridgeFrontend(BridgeFrontend):
except dbus.exceptions.DBusException, e:
if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown':
raise BridgeExceptionNoService
elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
print u"D-Bus is not launched, please see README to see instructions on how to launch it"
raise BridgeInitError
else:
raise e
#props = self.db_core_iface.getProperties()

View file

@ -53,7 +53,8 @@ from os.path import abspath, basename, dirname
from optparse import OptionParser
from sat.tools.jid import JID
import gobject
from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
from sat_frontends.bridge.DBus import DBusBridgeFrontend
from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
from sat.tools.utils import clean_ustr
import tarfile
import tempfile
@ -74,7 +75,9 @@ class JP(object):
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)
except BridgeInitError:
print(_(u"Can't init bridge"))
sys.exit(1)
self.transfer_data = None

View file

@ -17,9 +17,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from logging import debug, info, warning, error
from sat.tools.jid import JID
from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
from sat_frontends.bridge.DBus import DBusBridgeFrontend
from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
from optparse import OptionParser
@ -41,7 +43,9 @@ class QuickApp(object):
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)
except BridgeInitError:
print(_(u"Can't init bridge"))
sys.exit(1)
self.bridge.register("connected", self.connected)
self.bridge.register("disconnected", self.disconnected)