Mercurial > libervia-backend
comparison sat/bridge/bridge_constructor/constructors/dbus/dbus_core_template.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 60d3861e5996 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
28 | 28 |
29 | 29 |
30 log = getLogger(__name__) | 30 log = getLogger(__name__) |
31 | 31 |
32 # Interface prefix | 32 # Interface prefix |
33 const_INT_PREFIX = config.getConfig( | 33 const_INT_PREFIX = config.config_get( |
34 config.parseMainConf(), | 34 config.parse_main_conf(), |
35 "", | 35 "", |
36 "bridge_dbus_int_prefix", | 36 "bridge_dbus_int_prefix", |
37 "org.libervia.Libervia") | 37 "org.libervia.Libervia") |
38 const_ERROR_PREFIX = const_INT_PREFIX + ".error" | 38 const_ERROR_PREFIX = const_INT_PREFIX + ".error" |
39 const_OBJ_PATH = "/org/libervia/Libervia/bridge" | 39 const_OBJ_PATH = "/org/libervia/Libervia/bridge" |
116 d.addErrback(GenericException.create_and_raise) | 116 d.addErrback(GenericException.create_and_raise) |
117 return d | 117 return d |
118 | 118 |
119 ##METHODS_PART## | 119 ##METHODS_PART## |
120 | 120 |
121 class Bridge: | 121 class bridge: |
122 | 122 |
123 def __init__(self): | 123 def __init__(self): |
124 log.info("Init DBus...") | 124 log.info("Init DBus...") |
125 self._obj = DBusObject(const_OBJ_PATH) | 125 self._obj = DBusObject(const_OBJ_PATH) |
126 | 126 |
127 async def postInit(self): | 127 async def post_init(self): |
128 try: | 128 try: |
129 conn = await client.connect(reactor) | 129 conn = await client.connect(reactor) |
130 except error.DBusException as e: | 130 except error.DBusException as e: |
131 if e.errName == "org.freedesktop.DBus.Error.NotSupported": | 131 if e.errName == "org.freedesktop.DBus.Error.NotSupported": |
132 log.error( | 132 log.error( |
143 ##SIGNALS_PART## | 143 ##SIGNALS_PART## |
144 def register_method(self, name, callback): | 144 def register_method(self, name, callback): |
145 log.debug(f"registering DBus bridge method [{name}]") | 145 log.debug(f"registering DBus bridge method [{name}]") |
146 self._obj.register_method(name, callback) | 146 self._obj.register_method(name, callback) |
147 | 147 |
148 def emitSignal(self, name, *args): | 148 def emit_signal(self, name, *args): |
149 self._obj.emitSignal(name, *args) | 149 self._obj.emitSignal(name, *args) |
150 | 150 |
151 def addMethod( | 151 def add_method( |
152 self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={} | 152 self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={} |
153 ): | 153 ): |
154 """Dynamically add a method to D-Bus Bridge""" | 154 """Dynamically add a method to D-Bus bridge""" |
155 # FIXME: doc parameter is kept only temporary, the time to remove it from calls | 155 # FIXME: doc parameter is kept only temporary, the time to remove it from calls |
156 log.debug(f"Adding method {name!r} to D-Bus bridge") | 156 log.debug(f"Adding method {name!r} to D-Bus bridge") |
157 self._obj.plugin_iface.addMethod( | 157 self._obj.plugin_iface.addMethod( |
158 Method(name, arguments=in_sign, returns=out_sign) | 158 Method(name, arguments=in_sign, returns=out_sign) |
159 ) | 159 ) |
162 def caller(self_, *args, **kwargs): | 162 def caller(self_, *args, **kwargs): |
163 return self_._callback(name, *args, **kwargs) | 163 return self_._callback(name, *args, **kwargs) |
164 setattr(self._obj, f"dbus_{name}", MethodType(caller, self._obj)) | 164 setattr(self._obj, f"dbus_{name}", MethodType(caller, self._obj)) |
165 self.register_method(name, method) | 165 self.register_method(name, method) |
166 | 166 |
167 def addSignal(self, name, int_suffix, signature, doc={}): | 167 def add_signal(self, name, int_suffix, signature, doc={}): |
168 """Dynamically add a signal to D-Bus Bridge""" | 168 """Dynamically add a signal to D-Bus bridge""" |
169 log.debug(f"Adding signal {name!r} to D-Bus bridge") | 169 log.debug(f"Adding signal {name!r} to D-Bus bridge") |
170 self._obj.plugin_iface.addSignal(Signal(name, signature)) | 170 self._obj.plugin_iface.addSignal(Signal(name, signature)) |
171 setattr(Bridge, name, partialmethod(Bridge.emitSignal, name)) | 171 setattr(bridge, name, partialmethod(bridge.emit_signal, name)) |