~ubuntu-branches/ubuntu/lucid/gajim/lucid-security

« back to all changes in this revision

Viewing changes to src/gajim-remote.py

  • Committer: Maia Kozheva
  • Date: 2009-11-25 08:32:36 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: sikon@maia-desktop-20091125083236-hkxrujhn3amehuve
Merged new upstream release 0.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
signal.signal(signal.SIGINT, signal.SIG_DFL) # ^C exits the application
34
34
 
35
35
from common import exceptions
36
 
from common import i18n
 
36
from common import i18n # This installs _() function
37
37
 
38
38
try:
39
39
        PREFERRED_ENCODING = locale.getpreferredencoding()
46
46
        sys.exit(1)
47
47
 
48
48
try:
49
 
        if sys.platform == 'darwin':
50
 
                import osx.dbus
51
 
                osx.dbus.load(False)
52
49
        import dbus
53
50
        import dbus.service
54
51
        import dbus.glib
117
114
                '"sync with global status" option set'), False)
118
115
                                        ]
119
116
                                ],
 
117
                        'set_priority': [
 
118
                                        _('Changes the priority of account or accounts'),
 
119
                                        [
 
120
                                                (_('priority'), _('priority you want to give to the account'),
 
121
                                                        True),
 
122
                                                (_('account'), _('change the priority of the given account. '
 
123
                                                        'If not specified, change status of all accounts that have'
 
124
                                                        ' "sync with global status" option set'), False)
 
125
                                        ]
 
126
                                ],
120
127
                        'open_chat': [
121
128
                                        _('Shows the chat dialog so that you can send messages to a contact'),
122
129
                                        [
123
130
                                                ('jid', _('JID of the contact that you want to chat with'),
124
131
                                                        True),
125
132
                                                (_('account'), _('if specified, contact is taken from the '
126
 
                                                'contact list of this account'), False)
 
133
                                                        'contact list of this account'), False),
 
134
                                                (_('message'),
 
135
                                                        _('message content. The account must be specified or ""'),
 
136
                                                        False)
127
137
                                        ]
128
138
                                ],
129
139
                        'send_chat_message':[
260
270
                                        [
261
271
                                                (_('uri'), _('URI to handle'), True),
262
272
                                                (_('account'), _('Account in which you want to handle it'),
263
 
                                                        False)
 
273
                                                        False),
 
274
                                                (_('message'), _('Message content'), False)
264
275
                                        ]
265
276
                                ],
266
277
                        'join_room': [
285
296
                        }
286
297
 
287
298
                self.sbus = None
288
 
                if self.argv_len  < 2 or sys.argv[1] not in self.commands.keys():
 
299
                if self.argv_len < 2 or sys.argv[1] not in self.commands.keys():
289
300
                        # no args or bad args
290
301
                        send_error(self.compose_help())
291
302
                self.command = sys.argv[1]
389
400
        def make_arguments_row(self, args):
390
401
                ''' return arguments list. Mandatory arguments are enclosed with:
391
402
                '<', '>', optional arguments - with '[', ']' '''
392
 
                str = ''
393
 
                for argument in args:
394
 
                        str += ' '
395
 
                        if argument[2]:
396
 
                                str += '<'
397
 
                        else:
398
 
                                str += '['
399
 
                        str += argument[0]
400
 
                        if argument[2]:
401
 
                                str += '>'
402
 
                        else:
403
 
                                str += ']'
404
 
                return str
 
403
                s = ''
 
404
                for arg in args:
 
405
                        if arg[2]:
 
406
                                s += ' <' + arg[0] + '>'
 
407
                        else:
 
408
                                s += ' [' + arg[0] + ']'
 
409
                return s
405
410
 
406
411
        def help_on_command(self, command):
407
412
                ''' return help message for a given command '''
408
413
                if command in self.commands:
409
414
                        command_props = self.commands[command]
410
415
                        arguments_str = self.make_arguments_row(command_props[1])
411
 
                        str = _('Usage: %(basename)s %(command)s %(arguments)s \n\t %(help)s')\
 
416
                        str_ = _('Usage: %(basename)s %(command)s %(arguments)s \n\t %(help)s')\
412
417
                                % {'basename': BASENAME, 'command': command,
413
418
                                'arguments': arguments_str, 'help': command_props[0]}
414
419
                        if len(command_props[1]) > 0:
415
 
                                str += '\n\n' + _('Arguments:') + '\n'
 
420
                                str_ += '\n\n' + _('Arguments:') + '\n'
416
421
                                for argument in command_props[1]:
417
 
                                        str += ' ' +  argument[0] + ' - ' + argument[1] + '\n'
418
 
                        return str
 
422
                                        str_ += ' ' + argument[0] + ' - ' + argument[1] + '\n'
 
423
                        return str_
419
424
                send_error(_('%s not found') % command)
420
425
 
421
426
        def compose_help(self):
422
427
                ''' print usage, and list available commands '''
423
 
                str = _('Usage: %s command [arguments]\nCommand is one of:\n' ) % BASENAME
424
 
                commands = sorted(self.commands.keys())
425
 
                for command in commands:
426
 
                        str += '  ' + command
427
 
                        for argument in self.commands[command][1]:
428
 
                                str += ' '
429
 
                                if argument[2]:
430
 
                                        str += '<'
431
 
                                else:
432
 
                                        str += '['
433
 
                                str += argument[0]
434
 
                                if argument[2]:
435
 
                                        str += '>'
436
 
                                else:
437
 
                                        str += ']'
438
 
                        str += '\n'
439
 
                return str
 
428
                s = _('Usage: %s command [arguments]\nCommand is one of:\n' ) % BASENAME
 
429
                for command in sorted(self.commands):
 
430
                        s += '  ' + command
 
431
                        for arg in self.commands[command][1]:
 
432
                                if arg[2]:
 
433
                                        s += ' <' + arg[0] + '>'
 
434
                                else:
 
435
                                        s += ' [' + arg[0] + ']'
 
436
                        s += '\n'
 
437
                return s
440
438
 
441
439
        def print_info(self, level, prop_dict, encode_return = False):
442
440
                ''' return formated string from data structure '''
522
520
                if not '?' in uri:
523
521
                        self.command = sys.argv[1] = 'open_chat'
524
522
                        return
 
523
                if 'body=' in uri:
 
524
                        # Open chat window and paste the text in the input message dialog
 
525
                        self.command = sys.argv[1] = 'open_chat'
 
526
                        message = uri.split('body=')
 
527
                        message = message[1].split(';')[0]
 
528
                        try:
 
529
                                message = urllib.unquote(message)
 
530
                        except UnicodeDecodeError:
 
531
                                pass
 
532
                        sys.argv[2] = uri.split('?')[0]
 
533
                        if len(sys.argv) == 4:
 
534
                                # jid in the sys.argv
 
535
                                sys.argv.append(message)
 
536
                        else:
 
537
                                sys.argv.append('')
 
538
                                sys.argv.append(message)
 
539
                                sys.argv[3] = ''
 
540
                                sys.argv[4] = message
 
541
                        return
525
542
                (jid, action) = uri.split('?', 1)
526
543
                try:
527
544
                        jid = urllib.unquote(jid)
535
552
                        sys.argv.append(sys.argv[3])
536
553
                        sys.argv[3] = ''
537
554
                        return
538
 
 
 
555
                if action.startswith('roster'):
 
556
                        # Add contact to roster
 
557
                        self.command = sys.argv[1] = 'add_contact'
 
558
                        return
539
559
                sys.exit(0)
540
560
 
541
561
        def call_remote_method(self):