Mercurial > libervia-backend
comparison src/bridge/bridge_constructor/bridge_contructor.py @ 337:4402ac630712
bridge: async callback managed in bridge_constructor + misc
- the new flag async make the method asynchronous
- new method asyncConnect (connect which return when the user is connected)
- setMicroblogAccess added to DBus frontend
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 May 2011 16:47:09 +0200 |
parents | a00e87d48213 |
children | eb9d33ba4e36 |
comparison
equal
deleted
inserted
replaced
336:953536246d9d | 337:4402ac630712 |
---|---|
35 | 35 |
36 This script construct a SàT bridge using the given protocol | 36 This script construct a SàT bridge using the given protocol |
37 """ | 37 """ |
38 MANAGED_PROTOCOLES=['dbus','mediawiki'] | 38 MANAGED_PROTOCOLES=['dbus','mediawiki'] |
39 DEFAULT_PROTOCOLE='dbus' | 39 DEFAULT_PROTOCOLE='dbus' |
40 FLAGS=['deprecated'] | 40 FLAGS=['deprecated', 'async'] |
41 | 41 |
42 import sys | 42 import sys |
43 import os | 43 import os |
44 from os import path | 44 from os import path |
45 from optparse import OptionParser | 45 from optparse import OptionParser |
250 sections.sort() | 250 sections.sort() |
251 for section in sections: | 251 for section in sections: |
252 function = self.getValues(section) | 252 function = self.getValues(section) |
253 print ("Adding %s %s" % (section, function["type"])) | 253 print ("Adding %s %s" % (section, function["type"])) |
254 default = self.getDefault(section) | 254 default = self.getDefault(section) |
255 async_msg = """<br />'''This method is asynchrone'''""" | |
255 deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''""" | 256 deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''""" |
256 signature_signal = \ | 257 signature_signal = \ |
257 """\ | 258 """\ |
258 ! scope=row | signature | 259 ! scope=row | signature |
259 | %s | 260 | %s |
272 'signature':signature_signal if function['type']=="signal" else signature_method, | 273 'signature':signature_signal if function['type']=="signal" else signature_method, |
273 'sig_out':function['sig_out'] or '', | 274 'sig_out':function['sig_out'] or '', |
274 'category':function['category'], | 275 'category':function['category'], |
275 'name':section, | 276 'name':section, |
276 'doc':self.getDoc(section) or "FIXME: No description available", | 277 'doc':self.getDoc(section) or "FIXME: No description available", |
278 'async':async_msg if "async" in self.getFlags(section) else "", | |
277 'deprecated':deprecated_msg if "deprecated" in self.getFlags(section) else "", | 279 'deprecated':deprecated_msg if "deprecated" in self.getFlags(section) else "", |
278 'parameters':self._wikiParameter(section, function['sig_in']), | 280 'parameters':self._wikiParameter(section, function['sig_in']), |
279 'return':self._wikiReturn(section) if function['type'] == 'method' else '' | 281 'return':self._wikiReturn(section) if function['type'] == 'method' else '' |
280 } | 282 } |
281 | 283 |
282 dest = signals_part if function['type'] == "signal" else methods_part | 284 dest = signals_part if function['type'] == "signal" else methods_part |
283 dest.append("""\ | 285 dest.append("""\ |
284 == %(name)s == | 286 == %(name)s == |
285 ''%(doc)s'' | 287 ''%(doc)s'' |
286 %(deprecated)s | 288 %(deprecated)s |
289 %(async)s | |
287 {| class="wikitable" style="text-align:left; width:80%%;" | 290 {| class="wikitable" style="text-align:left; width:80%%;" |
288 ! scope=row | category | 291 ! scope=row | category |
289 | %(category)s | 292 | %(category)s |
290 |- | 293 |- |
291 %(signature)s | 294 %(signature)s |
333 for section in sections: | 336 for section in sections: |
334 function = self.getValues(section) | 337 function = self.getValues(section) |
335 print ("Adding %s %s" % (section, function["type"])) | 338 print ("Adding %s %s" % (section, function["type"])) |
336 default = self.getDefault(section) | 339 default = self.getDefault(section) |
337 arg_doc = self.getArgumentsDoc(section) | 340 arg_doc = self.getArgumentsDoc(section) |
341 async = "async" in self.getFlags(section) | |
338 completion = { | 342 completion = { |
339 'sig_in':function['sig_in'] or '', | 343 'sig_in':function['sig_in'] or '', |
340 'sig_out':function['sig_out'] or '', | 344 'sig_out':function['sig_out'] or '', |
341 'category':'REQ' if function['category'] == 'request' else 'COMM', | 345 'category':'REQ' if function['category'] == 'request' else 'COMM', |
342 'name':section, | 346 'name':section, |
357 """ % completion) | 361 """ % completion) |
358 | 362 |
359 elif function["type"] == "method": | 363 elif function["type"] == "method": |
360 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') | 364 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') |
361 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode) | 365 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode) |
366 completion['async_comma'] = ', ' if async and function['sig_in'] else '' | |
367 completion['async_args_def'] = 'callback=None, errback=None' if async else '' | |
368 completion['async_args_call'] = 'callback, errback' if async else '' | |
369 completion['async_callbacks'] = "('callback', 'errback')" if async else "None" | |
362 methods_part.append("""\ | 370 methods_part.append("""\ |
363 @dbus.service.method(const_INT_PREFIX+const_%(category)s_SUFFIX, | 371 @dbus.service.method(const_INT_PREFIX+const_%(category)s_SUFFIX, |
364 in_signature='%(sig_in)s', out_signature='%(sig_out)s') | 372 in_signature='%(sig_in)s', out_signature='%(sig_out)s', |
365 def %(name)s(self, %(args)s): | 373 async_callbacks=%(async_callbacks)s) |
366 %(debug)sreturn self.cb["%(name)s"](%(args_result)s) | 374 def %(name)s(self, %(args)s%(async_comma)s%(async_args_def)s): |
375 %(debug)sreturn self.cb["%(name)s"](%(args_result)s%(async_comma)s%(async_args_call)s) | |
367 """ % completion) | 376 """ % completion) |
368 | 377 |
369 #at this point, signals_part, methods_part and direct_calls should be filled, | 378 #at this point, signals_part, methods_part and direct_calls should be filled, |
370 #we just have to place them in the right part of the template | 379 #we just have to place them in the right part of the template |
371 core_bridge = [] | 380 core_bridge = [] |
394 for section in sections: | 403 for section in sections: |
395 function = self.getValues(section) | 404 function = self.getValues(section) |
396 print ("Adding %s %s" % (section, function["type"])) | 405 print ("Adding %s %s" % (section, function["type"])) |
397 default = self.getDefault(section) | 406 default = self.getDefault(section) |
398 arg_doc = self.getArgumentsDoc(section) | 407 arg_doc = self.getArgumentsDoc(section) |
408 async = "async" in self.getFlags(section) | |
399 completion = { | 409 completion = { |
400 'sig_in':function['sig_in'] or '', | 410 'sig_in':function['sig_in'] or '', |
401 'sig_out':function['sig_out'] or '', | 411 'sig_out':function['sig_out'] or '', |
402 'category':'req' if function['category'] == 'request' else 'comm', | 412 'category':'req' if function['category'] == 'request' else 'comm', |
403 'name':section, | 413 'name':section, |
404 'args':self.getArguments(function['sig_in'], name=arg_doc, default=default ) | 414 'args':self.getArguments(function['sig_in'], name=arg_doc, default=default) |
405 } | 415 } |
406 | 416 |
407 if function["type"] == "method": | 417 if function["type"] == "method": |
408 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') | 418 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') |
409 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc) | 419 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc) |
410 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s)" % completion | 420 completion['async_args'] = ', callback=None, errback=None' if async else '' |
421 completion['async_comma'] = ', ' if async and function['sig_in'] else '' | |
422 completion['async_args_result'] = 'reply_handler=callback, error_handler=errback' if async else '' | |
423 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion | |
411 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result | 424 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result |
412 methods_part.append("""\ | 425 methods_part.append("""\ |
413 def %(name)s(self, %(args)s): | 426 def %(name)s(self, %(args)s%(async_args)s): |
414 %(debug)sreturn %(result)s | 427 %(debug)sreturn %(result)s |
415 """ % completion) | 428 """ % completion) |
416 | 429 |
417 #at this point, methods_part should be filled, | 430 #at this point, methods_part should be filled, |
418 #we just have to place it in the right part of the template | 431 #we just have to place it in the right part of the template |