Added translatable help messages for each command
This commit is contained in:
parent
e4d5ece8a2
commit
a48bd1b6f9
1 changed files with 145 additions and 30 deletions
|
@ -24,12 +24,20 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import gtk
|
import gtk
|
||||||
|
import gtk.glade
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
import signal
|
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 i18n
|
||||||
|
|
||||||
|
_ = i18n._
|
||||||
|
APP = i18n.APP
|
||||||
|
gtk.glade.bindtextdomain(APP, i18n.DIR)
|
||||||
|
gtk.glade.textdomain(APP)
|
||||||
|
i18n.init()
|
||||||
def send_error(error_message):
|
def send_error(error_message):
|
||||||
sys.stderr.write(error_message + '\n')
|
sys.stderr.write(error_message + '\n')
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
@ -41,33 +49,131 @@ except:
|
||||||
send_error('Dbus is not supported.\n')
|
send_error('Dbus is not supported.\n')
|
||||||
|
|
||||||
_version = getattr(dbus, 'version', (0, 20, 0))
|
_version = getattr(dbus, 'version', (0, 20, 0))
|
||||||
|
if _version[1] >= 41:
|
||||||
|
import dbus.service
|
||||||
|
import dbus.glib
|
||||||
|
|
||||||
OBJ_PATH = '/org/gajim/dbus/RemoteObject'
|
OBJ_PATH = '/org/gajim/dbus/RemoteObject'
|
||||||
INTERFACE = 'org.gajim.dbus.RemoteInterface'
|
INTERFACE = 'org.gajim.dbus.RemoteInterface'
|
||||||
SERVICE = 'org.gajim.dbus'
|
SERVICE = 'org.gajim.dbus'
|
||||||
commands = ['help', 'toggle_roster_appearance', 'show_next_unread',
|
|
||||||
'list_contacts', 'list_accounts', 'change_status', 'new_message',
|
|
||||||
'send_message', 'contact_info']
|
commands = {
|
||||||
|
'help':[
|
||||||
if _version[1] >= 41:
|
_('show a help on specific command'),
|
||||||
import dbus.service
|
[
|
||||||
import dbus.glib
|
(_('on_command'), _('show help on command'), False)
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'toggle_roster_appearance' : [
|
||||||
|
_('Shows or hides the roster window'),
|
||||||
|
[]
|
||||||
|
],
|
||||||
|
'show_next_unread': [
|
||||||
|
_('Popup a window with the next unread message'),
|
||||||
|
[]
|
||||||
|
],
|
||||||
|
'list_contacts': [
|
||||||
|
_('Print a list of all contacts in the roster. \
|
||||||
|
Each contact appear on a separate line'),
|
||||||
|
[
|
||||||
|
(_('account'), _('show only contacts of the account \'account\''), False)
|
||||||
|
]
|
||||||
|
|
||||||
|
],
|
||||||
|
'list_accounts': [
|
||||||
|
_('Print a list of registered accounts'),
|
||||||
|
[]
|
||||||
|
],
|
||||||
|
'change_status': [
|
||||||
|
_('Change '),
|
||||||
|
[
|
||||||
|
(_('status'), _('one of: offline, online, chat, \
|
||||||
|
away, xa, dnd, invisible '), True),
|
||||||
|
(_('message'), _('status message'), False),
|
||||||
|
(_('account'), _('change status of the account \'accounts\'. \
|
||||||
|
If not specified try to change stutus of all accounts that \
|
||||||
|
have \'sync with global \' option set'), False)
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'new_message': [
|
||||||
|
_('Show the chat dialog so that you can send message to a contact'),
|
||||||
|
[
|
||||||
|
(_('jid'), _('jid of the contact that you want to send a message to'), True),
|
||||||
|
(_('account'), _('if specified will try to send the \
|
||||||
|
message using this account'), False)
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'send_message':[
|
||||||
|
_('Send new message to a contact in the roster'),
|
||||||
|
[
|
||||||
|
(_('jid'), _('jid of the contact that will receive the message'), True),
|
||||||
|
(_('message'), _('message contents'), True),
|
||||||
|
(_('keyID'), _('if specified will encrypt the message using \
|
||||||
|
this pulic key'), False),
|
||||||
|
(_('account'), _('if specified will try to send the \
|
||||||
|
message using this account'), False),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'contact_info': [
|
||||||
|
_('Get detailed info on a contact'),
|
||||||
|
[
|
||||||
|
(_('jid'), _('jid of the contact'), True)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def make_arguments_row(args):
|
||||||
|
str = ''
|
||||||
|
for argument in args:
|
||||||
|
str += ' '
|
||||||
|
if argument[2]:
|
||||||
|
str += '<'
|
||||||
|
else:
|
||||||
|
str += '['
|
||||||
|
str += argument[0]
|
||||||
|
if argument[2]:
|
||||||
|
str += '>'
|
||||||
|
else:
|
||||||
|
str += ']'
|
||||||
|
return str
|
||||||
|
def help_on_command(command):
|
||||||
|
if command in commands:
|
||||||
|
str = _('Usage: %s %s %s \n\t') % (sys.argv[0], command, make_arguments_row(commands[command][1]))
|
||||||
|
str += commands[command][0] + '\n\nArguments:\n'
|
||||||
|
for argument in commands[command][1]:
|
||||||
|
str += ' ' + argument[0] + ' - ' + argument[1] + '\n'
|
||||||
|
return str
|
||||||
|
send_error(_(' %s not found') % command)
|
||||||
|
|
||||||
def compose_help():
|
def compose_help():
|
||||||
str = 'Usage: '+ sys.argv[0] + ' command [arguments]\n'
|
str = _('Usage: %s command [arguments]\nCommand is one of:\n' ) % sys.argv[0]
|
||||||
str += 'Command must be one of:\n'
|
for command in commands.keys():
|
||||||
for command in commands:
|
str += ' ' + command
|
||||||
str += '\t' + command +'\n'
|
for argument in commands[command][1]:
|
||||||
|
str += ' '
|
||||||
|
if argument[2]:
|
||||||
|
str += '<'
|
||||||
|
else:
|
||||||
|
str += '['
|
||||||
|
str += argument[0]
|
||||||
|
if argument[2]:
|
||||||
|
str += '>'
|
||||||
|
else:
|
||||||
|
str += ']'
|
||||||
|
str += '\n'
|
||||||
return str
|
return str
|
||||||
|
|
||||||
def show_vcard_info(*args, **keyword):
|
def show_vcard_info(*args, **keyword):
|
||||||
|
# more cleaner output
|
||||||
if _version[1] >= 30:
|
if _version[1] >= 30:
|
||||||
print args[0]
|
print args[0]
|
||||||
else:
|
else:
|
||||||
if args and len(args) >= 5:
|
if args and len(args) >= 5:
|
||||||
print args[4].get_args_list()
|
print args[4].get_args_list()
|
||||||
|
|
||||||
# remove_signal_receiver is broken in lower versions,
|
# remove_signal_receiver is broken in lower versions (< 0.35),
|
||||||
# so we leave the leak - nothing can be done
|
# so we leave the leak - nothing can be done
|
||||||
if _version[1] >= 41:
|
if _version[1] >= 41:
|
||||||
sbus.remove_signal_receiver(show_vcard_info, 'VcardInfo', INTERFACE,
|
sbus.remove_signal_receiver(show_vcard_info, 'VcardInfo', INTERFACE,
|
||||||
|
@ -84,13 +190,16 @@ def gtk_quit():
|
||||||
|
|
||||||
argv_len = len(sys.argv)
|
argv_len = len(sys.argv)
|
||||||
|
|
||||||
if argv_len < 2 or sys.argv[1] not in commands: # no args or bad args
|
if argv_len < 2 or sys.argv[1] not in commands.keys(): # no args or bad args
|
||||||
send_error(compose_help())
|
send_error(compose_help())
|
||||||
|
|
||||||
command = sys.argv[1]
|
command = sys.argv[1]
|
||||||
|
|
||||||
if command == 'help':
|
if command == 'help':
|
||||||
print compose_help()
|
if argv_len == 3:
|
||||||
|
print help_on_command(sys.argv[2])
|
||||||
|
else:
|
||||||
|
print compose_help()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -112,30 +221,36 @@ method = interface.__getattr__(sys.argv[1]) # get the function asked
|
||||||
|
|
||||||
if command == 'contact_info':
|
if command == 'contact_info':
|
||||||
if argv_len < 3:
|
if argv_len < 3:
|
||||||
send_error("Missing argument \'contact_jid'")
|
send_error('Missing argument \'contact_jid\'')
|
||||||
try:
|
try:
|
||||||
id = sbus.add_signal_receiver(show_vcard_info, 'VcardInfo',
|
id = sbus.add_signal_receiver(show_vcard_info, 'VcardInfo',
|
||||||
INTERFACE, SERVICE, OBJ_PATH)
|
INTERFACE, SERVICE, OBJ_PATH)
|
||||||
except:
|
except:
|
||||||
send_error('Service not available')
|
send_error('Service not available')
|
||||||
|
|
||||||
#FIXME: gajim-remote.py change_status help to inform what it does with optional arg (account). the same for rest of methods that accept args
|
|
||||||
|
|
||||||
#FIXME - didn't find more clever way for the below 8 lines of code.
|
#FIXME - didn't find more clever way for the below 8 lines of code.
|
||||||
# method(sys.argv[2:]) doesn't work, cos sys.argv[2:] is a tuple
|
# method(sys.argv[2:]) doesn't work, cos sys.argv[2:] is a tuple
|
||||||
try:
|
def call_remote_method(method):
|
||||||
if argv_len == 2:
|
argv_len = len(sys.argv)
|
||||||
res = method()
|
try:
|
||||||
elif argv_len == 3:
|
if argv_len == 2:
|
||||||
res = method(sys.argv[2])
|
res = method()
|
||||||
elif argv_len == 4:
|
elif argv_len == 3:
|
||||||
res = method(sys.argv[2], sys.argv[3])
|
res = method(sys.argv[2])
|
||||||
elif argv_len == 5:
|
elif argv_len == 4:
|
||||||
res = method(sys.argv[2], sys.argv[3], sys.argv[4])
|
res = method(sys.argv[2], sys.argv[3])
|
||||||
if res:
|
elif argv_len == 5:
|
||||||
print res
|
res = method(sys.argv[2], sys.argv[3], sys.argv[4])
|
||||||
except:
|
return res
|
||||||
send_error('Service not available')
|
except:
|
||||||
|
send_error(_('Service not available'))
|
||||||
|
return None
|
||||||
|
|
||||||
|
res = call_remote_method(method)
|
||||||
|
|
||||||
|
|
||||||
|
if res:
|
||||||
|
print res
|
||||||
|
|
||||||
if command == 'contact_info':
|
if command == 'contact_info':
|
||||||
gobject.timeout_add(5000, gtk_quit) # wait 5 sec maximum
|
gobject.timeout_add(5000, gtk_quit) # wait 5 sec maximum
|
||||||
|
|
Loading…
Add table
Reference in a new issue