Mercurial > libervia-backend
changeset 359:eb9d33ba4e36
bridge: templates' constants can now be overrided
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 06 Jun 2011 18:35:30 +0200 |
parents | f147b778511a |
children | 6b5626c37909 |
files | src/bridge/bridge_constructor/bridge_contructor.py src/bridge/bridge_constructor/dbus_core_template.py src/bridge/bridge_constructor/dbus_frontend_template.py |
diffstat | 3 files changed, 29 insertions(+), 5 deletions(-) [+] |
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)
--- a/src/bridge/bridge_constructor/dbus_core_template.py Mon Jun 06 18:34:40 2011 +0200 +++ b/src/bridge/bridge_constructor/dbus_core_template.py Mon Jun 06 18:35:30 2011 +0200 @@ -27,6 +27,7 @@ from logging import debug, info const_INT_PREFIX = "org.goffi.SAT" #Interface prefix +const_OBJ_PATH = '/org/goffi/SAT/bridge' const_COMM_SUFFIX = ".communication" const_REQ_SUFFIX = ".request" @@ -125,7 +126,7 @@ info ("Init DBus...") self.session_bus = dbus.SessionBus() self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) - self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') + self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH) ##DIRECT_CALLS##
--- a/src/bridge/bridge_constructor/dbus_frontend_template.py Mon Jun 06 18:34:40 2011 +0200 +++ b/src/bridge/bridge_constructor/dbus_frontend_template.py Mon Jun 06 18:35:30 2011 +0200 @@ -23,6 +23,11 @@ import dbus, dbus.glib from logging import debug +const_INT_PREFIX = "org.goffi.SAT" #Interface prefix +const_OBJ_PATH = '/org/goffi/SAT/bridge' +const_COMM_SUFFIX = ".communication" +const_REQ_SUFFIX = ".request" + class BridgeExceptionNoService(Exception): pass @@ -30,12 +35,12 @@ def __init__(self): try: self.sessions_bus = dbus.SessionBus() - self.db_object = self.sessions_bus.get_object('org.goffi.SAT', - '/org/goffi/SAT/bridge') + self.db_object = self.sessions_bus.get_object(const_INT_PREFIX, + const_OBJ_PATH) self.db_comm_iface = dbus.Interface(self.db_object, - dbus_interface='org.goffi.SAT.communication') + dbus_interface=const_INT_PREFIX + const_COMM_SUFFIX) self.db_req_iface = dbus.Interface(self.db_object, - dbus_interface='org.goffi.SAT.request') + dbus_interface=const_INT_PREFIX + const_REQ_SUFFIX) except dbus.exceptions.DBusException,e: if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': raise BridgeExceptionNoService