Mercurial > libervia-backend
diff src/bridge/DBus.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | 723f28cd15c7 |
children | fee00f2e11c2 |
line wrap: on
line diff
--- a/src/bridge/DBus.py Sat Apr 19 16:48:26 2014 +0200 +++ b/src/bridge/DBus.py Sat Apr 19 19:19:19 2014 +0200 @@ -17,12 +17,14 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from sat.core.i18n import _ from bridge import Bridge import dbus import dbus.service import dbus.mainloop.glib import inspect -from logging import debug, info, error +from sat.core.log import getLogger +log = getLogger(__name__) from twisted.internet.defer import Deferred from sat.core.exceptions import BridgeInitError @@ -69,7 +71,7 @@ def __init__(self, bus, path): dbus.service.Object.__init__(self, bus, path) - debug("Init DbusObject...") + log.debug("Init DbusObject...") self.cb = {} def register(self, name, cb): @@ -84,7 +86,7 @@ if "callback" in kwargs: #we must have errback too if not "errback" in kwargs: - error("errback is missing in method call [%s]" % name) + log.error("errback is missing in method call [%s]" % name) raise InternalError callback = kwargs.pop("callback") errback = kwargs.pop("errback") @@ -94,13 +96,13 @@ result = self.cb[name](*args, **kwargs) if async: if not isinstance(result, Deferred): - error("Asynchronous method [%s] does not return a Deferred." % name) + log.error("Asynchronous method [%s] does not return a Deferred." % name) raise AsyncNotDeferred result.addCallback(lambda result: callback() if result is None else callback(result)) result.addErrback(lambda err: errback(GenericException(err))) else: if isinstance(result, Deferred): - error("Synchronous method [%s] return a Deferred." % name) + log.error("Synchronous method [%s] return a Deferred." % name) raise DeferredNotAsync return result ### signals ### @@ -502,7 +504,7 @@ attributes = ', '.join(self.__attributes(signature)) #TODO: use doc parameter to name attributes - #code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec') #XXX: the debug is too annoying with xmllog + #code = compile ('def '+name+' (self,'+attributes+'): log.debug ("'+name+' signal")', '<DBus bridge>','exec') #XXX: the log.debug is too annoying with xmllog code = compile('def ' + name + ' (self,' + attributes + '): pass', '<DBus bridge>', 'exec') exec (code) signal = locals()[name] @@ -517,12 +519,12 @@ def __init__(self): dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) Bridge.__init__(self) - info("Init DBus...") + log.info("Init DBus...") try: self.session_bus = dbus.SessionBus() except dbus.DBusException as e: if e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported': - print u"D-Bus is not launched, please see README to see instructions on how to launch it" + log.error(_(u"D-Bus is not launched, please see README to see instructions on how to launch it")) raise BridgeInitError self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH) @@ -570,13 +572,13 @@ self.dbus_bridge.subscribe(sub_type, entity_jid, profile) def register(self, name, callback): - debug("registering DBus bridge method [%s]", name) + log.debug("registering DBus bridge method [%s]" % name) self.dbus_bridge.register(name, callback) def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}): """Dynamically add a method to Dbus Bridge""" #FIXME: doc parameter is kept only temporary, the time to remove it from calls - print ("Adding method [%s] to DBus bridge" % name) + log.debug("Adding method [%s] to DBus bridge" % name) self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async) self.register(name, method)