add an exceptions file that contain our custom exceptions
This commit is contained in:
parent
0bf6346ab1
commit
54e47436e3
|
@ -0,0 +1,56 @@
|
|||
## exceptions.py
|
||||
##
|
||||
## Gajim Team:
|
||||
## - Yann Le Boulanger <asterix@lagaule.org>
|
||||
## - Vincent Hanquez <tab@snarc.org>
|
||||
## - Nikos Kouremenos <kourem@gmail.com>
|
||||
##
|
||||
## Copyright (C) 2003-2005 Gajim Team
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
## by the Free Software Foundation; version 2 only.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
|
||||
from common import i18n
|
||||
_ = i18n._
|
||||
|
||||
class PysqliteNotAvailable(Exception):
|
||||
'''sqlite2 is not installed or python bindings are missing'''
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
def __str__(self):
|
||||
return _('pysqlite2 (aka python-pysqlite2) dependency is missing. '\
|
||||
'After you install pysqlite3, if you want to migrate your logs '\
|
||||
'to the new database, please read: http://trac.gajim.org/wiki/MigrateLogToDot9DB '\
|
||||
'Exiting...')
|
||||
|
||||
class ServiceNotAvailable(Exception):
|
||||
'''This exception is raised when we cannot use Gajim remotely'''
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
def __str__(self):
|
||||
return _('Service not available: Gajim is not running, or remote_control is False')
|
||||
|
||||
class DbusNotSupported(Exception):
|
||||
'''D-Bus is not installed or python bindings are missing'''
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
def __str__(self):
|
||||
return _('D-Bus is not present on this machine or python module is missing')
|
||||
|
||||
class SessionBusNotPresent(Exception):
|
||||
'''This exception indicates that there is no session daemon'''
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
def __str__(self):
|
||||
return _('Session bus is not available')
|
|
@ -22,20 +22,15 @@ import sys
|
|||
import time
|
||||
import datetime
|
||||
|
||||
from common import exceptions
|
||||
from common import i18n
|
||||
_ = i18n._
|
||||
|
||||
try:
|
||||
from pysqlite2 import dbapi2 as sqlite
|
||||
except ImportError:
|
||||
error = _('pysqlite2 (aka python-pysqlite2) dependency is missing. '\
|
||||
'After you install pysqlite3, if you want to migrate your logs '\
|
||||
'to the new database, please read: http://trac.gajim.org/wiki/MigrateLogToDot9DB '\
|
||||
'Exiting...'
|
||||
)
|
||||
print >> sys.stderr, error
|
||||
sys.exit()
|
||||
|
||||
raise exceptions.PysqliteNotAvailable
|
||||
|
||||
GOT_JIDS_ALREADY_IN_DB = False # see get_jids_already_in_db()
|
||||
|
||||
if os.name == 'nt':
|
||||
|
|
|
@ -32,6 +32,7 @@ import signal
|
|||
signal.signal(signal.SIGINT, signal.SIG_DFL) # ^C exits the application
|
||||
import traceback
|
||||
|
||||
from common import exceptions
|
||||
from common import i18n
|
||||
|
||||
_ = i18n._
|
||||
|
@ -43,34 +44,10 @@ def send_error(error_message):
|
|||
sys.stderr.flush()
|
||||
sys.exit(1)
|
||||
|
||||
class ServiceNotAvailable(Exception):
|
||||
'''This exception is raised when we cannot use Gajim remotely'''
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
def __str__(self):
|
||||
return _('Service not available: Gajim is not running, or remote_control is False')
|
||||
|
||||
class DbusNotSupported(Exception):
|
||||
'''D-Bus is not installed or python bindings are missing'''
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
def __str__(self):
|
||||
return _('D-Bus is not present on this machine or python module is missing')
|
||||
|
||||
class SessionBusNotPresent(Exception):
|
||||
'''This exception indicates that there is no session daemon'''
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
def __str__(self):
|
||||
return _('Session bus is not available')
|
||||
|
||||
try:
|
||||
import dbus
|
||||
except:
|
||||
raise DbusNotSupported
|
||||
raise exceptions.DbusNotSupported
|
||||
|
||||
_version = getattr(dbus, 'version', (0, 20, 0))
|
||||
if _version[1] >= 41:
|
||||
|
@ -236,7 +213,7 @@ class GajimRemote:
|
|||
id = self.sbus.add_signal_receiver(self.show_vcard_info,
|
||||
'VcardInfo', INTERFACE, SERVICE, OBJ_PATH)
|
||||
except Exception, e:
|
||||
raise ServiceNotAvailable
|
||||
raise exceptions.ServiceNotAvailable
|
||||
|
||||
res = self.call_remote_method()
|
||||
self.print_result(res)
|
||||
|
@ -282,7 +259,7 @@ class GajimRemote:
|
|||
try:
|
||||
self.sbus = dbus.SessionBus()
|
||||
except:
|
||||
raise SessionBusNotPresent
|
||||
raise exceptions.SessionBusNotPresent
|
||||
|
||||
if _version[1] >= 30:
|
||||
obj = self.sbus.get_object(SERVICE, OBJ_PATH)
|
||||
|
@ -566,7 +543,7 @@ Type "%s help %s" for more info') % (args[argv_len][0], BASENAME, self.command))
|
|||
return res
|
||||
except Exception, e:
|
||||
print str(e)
|
||||
raise ServiceNotAvailable
|
||||
raise exceptions.ServiceNotAvailable
|
||||
return None
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue