Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/src/bridge/bridge_constructor/bridge_contructor.py Mon Jun 06 18:34:40 2011 +0200 +++ b/src/bridge/bridge_constructor/bridge_contructor.py Mon Jun 06 18:35:30 2011 +0200 @@ -39,6 +39,8 @@ DEFAULT_PROTOCOLE='dbus' FLAGS=['deprecated', 'async'] +ENV_OVERRIDE = "SAT_BRIDGE_CONST_" #Prefix used to override a constant + import sys import os from os import path @@ -378,6 +380,8 @@ #at this point, signals_part, methods_part and direct_calls should be filled, #we just have to place them in the right part of the template core_bridge = [] + const_override_pref = filter(lambda env: env.startswith(ENV_OVERRIDE), os.environ) + const_override = [env[len(ENV_OVERRIDE):] for env in const_override_pref] try: with open(self.core_template) as core_template: for line in core_template: @@ -388,6 +392,12 @@ elif line.startswith('##DIRECT_CALLS##'): core_bridge.extend(direct_calls) else: + if line.startswith('const_'): + const_name = line[len('const_'):line.find(' = ')] + if const_name in const_override: + print ("const %s overriden" % const_name) + core_bridge.append('const_%s = %s' % (const_name, os.environ[ENV_OVERRIDE+const_name])) + continue core_bridge.append(line.replace('\n','')) except IOError: print ("Can't open template file [%s]" % self.core_template) @@ -430,12 +440,20 @@ #at this point, methods_part should be filled, #we just have to place it in the right part of the template frontend_bridge = [] + const_override_pref = filter(lambda env: env.startswith(ENV_OVERRIDE), os.environ) + const_override = [env[len(ENV_OVERRIDE):] for env in const_override_pref] try: with open(self.frontend_template) as frontend_template: for line in frontend_template: if line.startswith('##METHODS_PART##'): frontend_bridge.extend(methods_part) else: + if line.startswith('const_'): + const_name = line[len('const_'):line.find(' = ')] + if const_name in const_override: + print ("const %s overriden" % const_name) + frontend_bridge.append('const_%s = %s' % (const_name, os.environ[ENV_OVERRIDE+const_name])) + continue frontend_bridge.append(line.replace('\n','')) except IOError: print ("Can't open template file [%s]" % self.frontend_template)