core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
This commit is contained in:
parent
dc5c042fe7
commit
501bc92528
2 changed files with 707 additions and 941 deletions
|
|
@ -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 @@ class DbusObject(dbus.service.Object):
|
|||
|
||||
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 @@ class DbusObject(dbus.service.Object):
|
|||
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 @@ class DbusObject(dbus.service.Object):
|
|||
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 ###
|
||||
|
|
@ -194,7 +196,7 @@ class DbusObject(dbus.service.Object):
|
|||
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]
|
||||
|
|
@ -209,25 +211,25 @@ class DBusBridge(Bridge):
|
|||
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)
|
||||
|
||||
##DIRECT_CALLS##
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
from sat.core.i18n import _
|
||||
from bridge_frontend import BridgeFrontend
|
||||
import dbus
|
||||
from logging import debug, error
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
|
||||
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
|
|
@ -47,7 +48,7 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown':
|
||||
raise BridgeExceptionNoService
|
||||
elif 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
|
||||
else:
|
||||
raise e
|
||||
|
|
@ -59,7 +60,7 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
elif iface == "plugin":
|
||||
self.db_plugin_iface.connect_to_signal(functionName, handler)
|
||||
else:
|
||||
error(_('Unknown interface'))
|
||||
log.error(_('Unknown interface'))
|
||||
|
||||
def __getattribute__(self, name):
|
||||
""" usual __getattribute__ if the method exists, else try to find a plugin method """
|
||||
|
|
|
|||
Loading…
Reference in a new issue