comparison src/bridge/bridge_constructor/bridge_constructor.py @ 1024:7e43ea75cce8

bridge (constructor): fixed D-Bus frontend generator for async method without sig_in + fixed --debug option + regenerated bridge to fix bad frontend D-Bus bridge.
author Goffi <goffi@goffi.org>
date Thu, 15 May 2014 16:35:28 +0200
parents 1fe00f0c9a91
children 95758ef3faa8
comparison
equal deleted inserted replaced
1023:8bae81e254a2 1024:7e43ea75cce8
38 38
39 ENV_OVERRIDE = "SAT_BRIDGE_CONST_" # Prefix used to override a constant 39 ENV_OVERRIDE = "SAT_BRIDGE_CONST_" # Prefix used to override a constant
40 40
41 import sys 41 import sys
42 import os 42 import os
43 from os import path
44 from optparse import OptionParser 43 from optparse import OptionParser
45 from ConfigParser import SafeConfigParser as Parser 44 from ConfigParser import SafeConfigParser as Parser
46 from ConfigParser import NoOptionError 45 from ConfigParser import NoOptionError
47 import re 46 import re
48 from datetime import datetime 47 from datetime import datetime
371 'category': 'PLUGIN' if function['category'] == 'plugin' else 'CORE', 370 'category': 'PLUGIN' if function['category'] == 'plugin' else 'CORE',
372 'name': section, 371 'name': section,
373 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)} 372 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)}
374 373
375 if function["type"] == "signal": 374 if function["type"] == "signal":
376 completion['body'] = "pass" if not self.options.debug else 'debug ("%s")' % section 375 completion['body'] = "pass" if not self.options.debug else 'log.debug ("%s")' % section
377 signals_part.append("""\ 376 signals_part.append("""\
378 @dbus.service.signal(const_INT_PREFIX+const_%(category)s_SUFFIX, 377 @dbus.service.signal(const_INT_PREFIX+const_%(category)s_SUFFIX,
379 signature='%(sig_in)s') 378 signature='%(sig_in)s')
380 def %(name)s(self, %(args)s): 379 def %(name)s(self, %(args)s):
381 %(body)s 380 %(body)s
384 def %(name)s(self, %(args)s): 383 def %(name)s(self, %(args)s):
385 self.dbus_bridge.%(name)s(%(args)s) 384 self.dbus_bridge.%(name)s(%(args)s)
386 """ % completion) 385 """ % completion)
387 386
388 elif function["type"] == "method": 387 elif function["type"] == "method":
389 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section, 8 * ' ') 388 completion['debug'] = "" if not self.options.debug else 'log.debug ("%s")\n%s' % (section, 8 * ' ')
390 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode) 389 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode)
391 completion['async_comma'] = ', ' if async and function['sig_in'] else '' 390 completion['async_comma'] = ', ' if async and function['sig_in'] else ''
392 completion['async_args_def'] = 'callback=None, errback=None' if async else '' 391 completion['async_args_def'] = 'callback=None, errback=None' if async else ''
393 completion['async_args_call'] = 'callback=callback, errback=errback' if async else '' 392 completion['async_args_call'] = 'callback=callback, errback=errback' if async else ''
394 completion['async_callbacks'] = "('callback', 'errback')" if async else "None" 393 completion['async_callbacks'] = "('callback', 'errback')" if async else "None"
445 'category': 'plugin' if function['category'] == 'plugin' else 'core', 444 'category': 'plugin' if function['category'] == 'plugin' else 'core',
446 'name': section, 445 'name': section,
447 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)} 446 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)}
448 447
449 if function["type"] == "method": 448 if function["type"] == "method":
450 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section, 8 * ' ') 449 completion['debug'] = "" if not self.options.debug else 'log.debug ("%s")\n%s' % (section, 8 * ' ')
451 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc) 450 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc)
452 completion['async_args'] = ', callback=None, errback=None' if async else '' 451 completion['async_args'] = 'callback=None, errback=None' if async else ''
453 completion['async_comma'] = ', ' if async and function['sig_in'] else '' 452 completion['async_comma'] = ', ' if async and function['sig_in'] else ''
454 completion['async_args_result'] = 'reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])' if async else '' 453 completion['async_args_result'] = 'reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])' if async else ''
455 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion 454 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion
456 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result 455 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result
457 methods_part.append("""\ 456 methods_part.append("""\
458 def %(name)s(self, %(args)s%(async_args)s): 457 def %(name)s(self, %(args)s%(async_comma)s%(async_args)s):
459 %(debug)sreturn %(result)s 458 %(debug)sreturn %(result)s
460 """ % completion) 459 """ % completion)
461 460
462 #at this point, methods_part should be filled, 461 #at this point, methods_part should be filled,
463 #we just have to place it in the right part of the template 462 #we just have to place it in the right part of the template