comparison src/bridge/bridge_constructor/bridge_contructor.py @ 359:eb9d33ba4e36

bridge: templates' constants can now be overrided
author Goffi <goffi@goffi.org>
date Mon, 06 Jun 2011 18:35:30 +0200
parents 4402ac630712
children 3ea41a199b36
comparison
equal deleted inserted replaced
358:f147b778511a 359:eb9d33ba4e36
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', 'async'] 40 FLAGS=['deprecated', 'async']
41
42 ENV_OVERRIDE = "SAT_BRIDGE_CONST_" #Prefix used to override a constant
41 43
42 import sys 44 import sys
43 import os 45 import os
44 from os import path 46 from os import path
45 from optparse import OptionParser 47 from optparse import OptionParser
376 """ % completion) 378 """ % completion)
377 379
378 #at this point, signals_part, methods_part and direct_calls should be filled, 380 #at this point, signals_part, methods_part and direct_calls should be filled,
379 #we just have to place them in the right part of the template 381 #we just have to place them in the right part of the template
380 core_bridge = [] 382 core_bridge = []
383 const_override_pref = filter(lambda env: env.startswith(ENV_OVERRIDE), os.environ)
384 const_override = [env[len(ENV_OVERRIDE):] for env in const_override_pref]
381 try: 385 try:
382 with open(self.core_template) as core_template: 386 with open(self.core_template) as core_template:
383 for line in core_template: 387 for line in core_template:
384 if line.startswith('##SIGNALS_PART##'): 388 if line.startswith('##SIGNALS_PART##'):
385 core_bridge.extend(signals_part) 389 core_bridge.extend(signals_part)
386 elif line.startswith('##METHODS_PART##'): 390 elif line.startswith('##METHODS_PART##'):
387 core_bridge.extend(methods_part) 391 core_bridge.extend(methods_part)
388 elif line.startswith('##DIRECT_CALLS##'): 392 elif line.startswith('##DIRECT_CALLS##'):
389 core_bridge.extend(direct_calls) 393 core_bridge.extend(direct_calls)
390 else: 394 else:
395 if line.startswith('const_'):
396 const_name = line[len('const_'):line.find(' = ')]
397 if const_name in const_override:
398 print ("const %s overriden" % const_name)
399 core_bridge.append('const_%s = %s' % (const_name, os.environ[ENV_OVERRIDE+const_name]))
400 continue
391 core_bridge.append(line.replace('\n','')) 401 core_bridge.append(line.replace('\n',''))
392 except IOError: 402 except IOError:
393 print ("Can't open template file [%s]" % self.core_template) 403 print ("Can't open template file [%s]" % self.core_template)
394 sys.exit(1) 404 sys.exit(1)
395 405
428 """ % completion) 438 """ % completion)
429 439
430 #at this point, methods_part should be filled, 440 #at this point, methods_part should be filled,
431 #we just have to place it in the right part of the template 441 #we just have to place it in the right part of the template
432 frontend_bridge = [] 442 frontend_bridge = []
443 const_override_pref = filter(lambda env: env.startswith(ENV_OVERRIDE), os.environ)
444 const_override = [env[len(ENV_OVERRIDE):] for env in const_override_pref]
433 try: 445 try:
434 with open(self.frontend_template) as frontend_template: 446 with open(self.frontend_template) as frontend_template:
435 for line in frontend_template: 447 for line in frontend_template:
436 if line.startswith('##METHODS_PART##'): 448 if line.startswith('##METHODS_PART##'):
437 frontend_bridge.extend(methods_part) 449 frontend_bridge.extend(methods_part)
438 else: 450 else:
451 if line.startswith('const_'):
452 const_name = line[len('const_'):line.find(' = ')]
453 if const_name in const_override:
454 print ("const %s overriden" % const_name)
455 frontend_bridge.append('const_%s = %s' % (const_name, os.environ[ENV_OVERRIDE+const_name]))
456 continue
439 frontend_bridge.append(line.replace('\n','')) 457 frontend_bridge.append(line.replace('\n',''))
440 except IOError: 458 except IOError:
441 print ("Can't open template file [%s]" % self.frontend_template) 459 print ("Can't open template file [%s]" % self.frontend_template)
442 sys.exit(1) 460 sys.exit(1)
443 461