blank line is really blank (no \t)
This commit is contained in:
parent
159e782ce9
commit
274d5270d1
|
@ -66,7 +66,7 @@ BASENAME = 'gajim-remote'
|
||||||
|
|
||||||
|
|
||||||
class GajimRemote:
|
class GajimRemote:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.argv_len = len(sys.argv)
|
self.argv_len = len(sys.argv)
|
||||||
# define commands dict. Prototype :
|
# define commands dict. Prototype :
|
||||||
|
@ -99,7 +99,7 @@ class GajimRemote:
|
||||||
[
|
[
|
||||||
(_('account'), _('show only contacts of the given account'), False)
|
(_('account'), _('show only contacts of the given account'), False)
|
||||||
]
|
]
|
||||||
|
|
||||||
],
|
],
|
||||||
'list_accounts': [
|
'list_accounts': [
|
||||||
_('Prints a list of registered accounts'),
|
_('Prints a list of registered accounts'),
|
||||||
|
@ -201,7 +201,7 @@ class GajimRemote:
|
||||||
('jid', _('JID of the contact'), True),
|
('jid', _('JID of the contact'), True),
|
||||||
(_('account'), _('if specified, contact is taken from the '
|
(_('account'), _('if specified, contact is taken from the '
|
||||||
'contact list of this account'), False)
|
'contact list of this account'), False)
|
||||||
|
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'add_contact': [
|
'add_contact': [
|
||||||
|
@ -211,14 +211,14 @@ class GajimRemote:
|
||||||
(_('account'), _('Adds new contact to this account'), False)
|
(_('account'), _('Adds new contact to this account'), False)
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
'get_status': [
|
'get_status': [
|
||||||
_('Returns current status (the global one unless account is specified)'),
|
_('Returns current status (the global one unless account is specified)'),
|
||||||
[
|
[
|
||||||
(_('account'), _(''), False)
|
(_('account'), _(''), False)
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
'get_status_message': [
|
'get_status_message': [
|
||||||
_('Returns current status message(the global one unless account is specified)'),
|
_('Returns current status message(the global one unless account is specified)'),
|
||||||
[
|
[
|
||||||
|
@ -247,14 +247,14 @@ class GajimRemote:
|
||||||
else:
|
else:
|
||||||
print self.compose_help().encode(PREFERRED_ENCODING)
|
print self.compose_help().encode(PREFERRED_ENCODING)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
self.init_connection()
|
self.init_connection()
|
||||||
self.check_arguments()
|
self.check_arguments()
|
||||||
|
|
||||||
if self.command == 'contact_info':
|
if self.command == 'contact_info':
|
||||||
if self.argv_len < 3:
|
if self.argv_len < 3:
|
||||||
send_error(_('Missing argument "contact_jid"'))
|
send_error(_('Missing argument "contact_jid"'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = self.call_remote_method()
|
res = self.call_remote_method()
|
||||||
except exceptions.ServiceNotAvailable:
|
except exceptions.ServiceNotAvailable:
|
||||||
|
@ -262,14 +262,14 @@ class GajimRemote:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
self.print_result(res)
|
self.print_result(res)
|
||||||
|
|
||||||
def print_result(self, res):
|
def print_result(self, res):
|
||||||
''' Print retrieved result to the output '''
|
''' Print retrieved result to the output '''
|
||||||
if res is not None:
|
if res is not None:
|
||||||
if self.command in ('open_chat', 'send_message', 'send_single_message', 'start_chat'):
|
if self.command in ('open_chat', 'send_message', 'send_single_message', 'start_chat'):
|
||||||
if self.command in ('send_message', 'send_single_message'):
|
if self.command in ('send_message', 'send_single_message'):
|
||||||
self.argv_len -= 2
|
self.argv_len -= 2
|
||||||
|
|
||||||
if res is False:
|
if res is False:
|
||||||
if self.argv_len < 4:
|
if self.argv_len < 4:
|
||||||
send_error(_('\'%s\' is not in your roster.\n'
|
send_error(_('\'%s\' is not in your roster.\n'
|
||||||
|
@ -302,7 +302,7 @@ class GajimRemote:
|
||||||
print self.print_info(0, res, True)
|
print self.print_info(0, res, True)
|
||||||
elif res:
|
elif res:
|
||||||
print unicode(res).encode(PREFERRED_ENCODING)
|
print unicode(res).encode(PREFERRED_ENCODING)
|
||||||
|
|
||||||
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 '''
|
||||||
|
@ -310,7 +310,7 @@ class GajimRemote:
|
||||||
self.sbus = dbus.SessionBus()
|
self.sbus = dbus.SessionBus()
|
||||||
except:
|
except:
|
||||||
raise exceptions.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)
|
||||||
interface = dbus.Interface(obj, INTERFACE)
|
interface = dbus.Interface(obj, INTERFACE)
|
||||||
|
@ -319,10 +319,10 @@ class GajimRemote:
|
||||||
interface = self.service.get_object(OBJ_PATH, INTERFACE)
|
interface = self.service.get_object(OBJ_PATH, INTERFACE)
|
||||||
else:
|
else:
|
||||||
send_error(_('Unknown D-Bus version: %s') % _version[1])
|
send_error(_('Unknown D-Bus version: %s') % _version[1])
|
||||||
|
|
||||||
# get the function asked
|
# get the function asked
|
||||||
self.method = interface.__getattr__(self.command)
|
self.method = interface.__getattr__(self.command)
|
||||||
|
|
||||||
def make_arguments_row(self, args):
|
def make_arguments_row(self, args):
|
||||||
''' return arguments list. Mandatory arguments are enclosed with:
|
''' return arguments list. Mandatory arguments are enclosed with:
|
||||||
'<', '>', optional arguments - with '[', ']' '''
|
'<', '>', optional arguments - with '[', ']' '''
|
||||||
|
@ -339,7 +339,7 @@ class GajimRemote:
|
||||||
else:
|
else:
|
||||||
str += ']'
|
str += ']'
|
||||||
return str
|
return str
|
||||||
|
|
||||||
def help_on_command(self, command):
|
def help_on_command(self, command):
|
||||||
''' return help message for a given command '''
|
''' return help message for a given command '''
|
||||||
if command in self.commands:
|
if command in self.commands:
|
||||||
|
@ -353,7 +353,7 @@ class GajimRemote:
|
||||||
str += ' ' + argument[0] + ' - ' + argument[1] + '\n'
|
str += ' ' + argument[0] + ' - ' + argument[1] + '\n'
|
||||||
return str
|
return str
|
||||||
send_error(_('%s not found') % command)
|
send_error(_('%s not found') % command)
|
||||||
|
|
||||||
def compose_help(self):
|
def compose_help(self):
|
||||||
''' print usage, and list available commands '''
|
''' print usage, and list available commands '''
|
||||||
str = _('Usage: %s command [arguments]\nCommand is one of:\n' ) % BASENAME
|
str = _('Usage: %s command [arguments]\nCommand is one of:\n' ) % BASENAME
|
||||||
|
@ -374,7 +374,7 @@ class GajimRemote:
|
||||||
str += ']'
|
str += ']'
|
||||||
str += '\n'
|
str += '\n'
|
||||||
return str
|
return str
|
||||||
|
|
||||||
def print_info(self, level, prop_dict, encode_return = False):
|
def print_info(self, level, prop_dict, encode_return = False):
|
||||||
''' return formated string from data structure '''
|
''' return formated string from data structure '''
|
||||||
if prop_dict is None or not isinstance(prop_dict, (dict, list, tuple)):
|
if prop_dict is None or not isinstance(prop_dict, (dict, list, tuple)):
|
||||||
|
@ -423,7 +423,7 @@ class GajimRemote:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return ret_str
|
return ret_str
|
||||||
|
|
||||||
def check_arguments(self):
|
def check_arguments(self):
|
||||||
''' Make check if all necessary arguments are given '''
|
''' Make check if all necessary arguments are given '''
|
||||||
argv_len = self.argv_len - 2
|
argv_len = self.argv_len - 2
|
||||||
|
@ -433,7 +433,7 @@ class GajimRemote:
|
||||||
send_error(_('Argument "%s" is not specified. \n'
|
send_error(_('Argument "%s" is not specified. \n'
|
||||||
'Type "%s help %s" for more info') %
|
'Type "%s help %s" for more info') %
|
||||||
(args[argv_len][0], BASENAME, self.command))
|
(args[argv_len][0], BASENAME, self.command))
|
||||||
|
|
||||||
def call_remote_method(self):
|
def call_remote_method(self):
|
||||||
''' calls self.method with arguments from sys.argv[2:] '''
|
''' calls self.method with arguments from sys.argv[2:] '''
|
||||||
args = sys.argv[2:]
|
args = sys.argv[2:]
|
||||||
|
|
Loading…
Reference in New Issue