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 time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from common import exceptions
|
||||||
from common import i18n
|
from common import i18n
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pysqlite2 import dbapi2 as sqlite
|
from pysqlite2 import dbapi2 as sqlite
|
||||||
except ImportError:
|
except ImportError:
|
||||||
error = _('pysqlite2 (aka python-pysqlite2) dependency is missing. '\
|
raise exceptions.PysqliteNotAvailable
|
||||||
'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()
|
|
||||||
|
|
||||||
GOT_JIDS_ALREADY_IN_DB = False # see get_jids_already_in_db()
|
GOT_JIDS_ALREADY_IN_DB = False # see get_jids_already_in_db()
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
|
|
|
@ -32,6 +32,7 @@ import signal
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL) # ^C exits the application
|
signal.signal(signal.SIGINT, signal.SIG_DFL) # ^C exits the application
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from common import exceptions
|
||||||
from common import i18n
|
from common import i18n
|
||||||
|
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
|
@ -43,34 +44,10 @@ def send_error(error_message):
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
sys.exit(1)
|
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:
|
try:
|
||||||
import dbus
|
import dbus
|
||||||
except:
|
except:
|
||||||
raise DbusNotSupported
|
raise exceptions.DbusNotSupported
|
||||||
|
|
||||||
_version = getattr(dbus, 'version', (0, 20, 0))
|
_version = getattr(dbus, 'version', (0, 20, 0))
|
||||||
if _version[1] >= 41:
|
if _version[1] >= 41:
|
||||||
|
@ -236,7 +213,7 @@ class GajimRemote:
|
||||||
id = self.sbus.add_signal_receiver(self.show_vcard_info,
|
id = self.sbus.add_signal_receiver(self.show_vcard_info,
|
||||||
'VcardInfo', INTERFACE, SERVICE, OBJ_PATH)
|
'VcardInfo', INTERFACE, SERVICE, OBJ_PATH)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise ServiceNotAvailable
|
raise exceptions.ServiceNotAvailable
|
||||||
|
|
||||||
res = self.call_remote_method()
|
res = self.call_remote_method()
|
||||||
self.print_result(res)
|
self.print_result(res)
|
||||||
|
@ -282,7 +259,7 @@ class GajimRemote:
|
||||||
try:
|
try:
|
||||||
self.sbus = dbus.SessionBus()
|
self.sbus = dbus.SessionBus()
|
||||||
except:
|
except:
|
||||||
raise SessionBusNotPresent
|
raise exceptions.SessionBusNotPresent
|
||||||
|
|
||||||
if _version[1] >= 30:
|
if _version[1] >= 30:
|
||||||
obj = self.sbus.get_object(SERVICE, OBJ_PATH)
|
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
|
return res
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print str(e)
|
print str(e)
|
||||||
raise ServiceNotAvailable
|
raise exceptions.ServiceNotAvailable
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue