Prevent traceback when gajim-remote is used while gajim is not running. Add a check_gajim_running command to gajim-remote
This commit is contained in:
parent
36438f44b6
commit
0ac8ce3c6e
|
@ -263,8 +263,13 @@ class GajimRemote:
|
||||||
(_('account'), _(''), False)
|
(_('account'), _(''), False)
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'check_gajim_running':[
|
||||||
|
_('Check if Gajim is running'),
|
||||||
|
[]
|
||||||
|
],
|
||||||
|
|
||||||
}
|
}
|
||||||
|
self.sbus = None
|
||||||
if self.argv_len < 2 or \
|
if self.argv_len < 2 or \
|
||||||
sys.argv[1] not in self.commands.keys(): # no args or bad args
|
sys.argv[1] not in self.commands.keys(): # no args or bad args
|
||||||
send_error(self.compose_help())
|
send_error(self.compose_help())
|
||||||
|
@ -277,6 +282,9 @@ class GajimRemote:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
if self.command == 'handle_uri':
|
if self.command == 'handle_uri':
|
||||||
self.handle_uri()
|
self.handle_uri()
|
||||||
|
if self.command == 'check_gajim_running':
|
||||||
|
print self.check_gajim_running()
|
||||||
|
sys.exit(0)
|
||||||
self.init_connection()
|
self.init_connection()
|
||||||
self.check_arguments()
|
self.check_arguments()
|
||||||
|
|
||||||
|
@ -332,6 +340,22 @@ class GajimRemote:
|
||||||
elif res:
|
elif res:
|
||||||
print unicode(res).encode(PREFERRED_ENCODING)
|
print unicode(res).encode(PREFERRED_ENCODING)
|
||||||
|
|
||||||
|
def check_gajim_running(self):
|
||||||
|
if not self.sbus:
|
||||||
|
try:
|
||||||
|
self.sbus = dbus.SessionBus()
|
||||||
|
except:
|
||||||
|
raise exceptions.SessionBusNotPresent
|
||||||
|
|
||||||
|
test = False
|
||||||
|
if hasattr(self.sbus, 'name_has_owner'):
|
||||||
|
if self.sbus.name_has_owner(SERVICE):
|
||||||
|
test = True
|
||||||
|
elif dbus.dbus_bindings.bus_name_has_owner(self.sbus.get_connection(),
|
||||||
|
SERVICE):
|
||||||
|
test = True
|
||||||
|
return test
|
||||||
|
|
||||||
def init_connection(self):
|
def init_connection(self):
|
||||||
''' create the onnection to the session dbus,
|
''' create the onnection to the session dbus,
|
||||||
or exit if it is not possible '''
|
or exit if it is not possible '''
|
||||||
|
@ -340,6 +364,8 @@ class GajimRemote:
|
||||||
except:
|
except:
|
||||||
raise exceptions.SessionBusNotPresent
|
raise exceptions.SessionBusNotPresent
|
||||||
|
|
||||||
|
if not self.check_gajim_running():
|
||||||
|
send_error(_('It seems Gajim is not running. So you can\'t use gajim-remote.'))
|
||||||
obj = self.sbus.get_object(SERVICE, OBJ_PATH)
|
obj = self.sbus.get_object(SERVICE, OBJ_PATH)
|
||||||
interface = dbus.Interface(obj, INTERFACE)
|
interface = dbus.Interface(obj, INTERFACE)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue