diff src/memory/params.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 75f3b3b430ff
children fee00f2e11c2
line wrap: on
line diff
--- a/src/memory/params.py	Sat Apr 19 16:48:26 2014 +0200
+++ b/src/memory/params.py	Sat Apr 19 19:19:19 2014 +0200
@@ -22,7 +22,8 @@
 from sat.core import exceptions
 from sat.core.constants import Const as C
 from xml.dom import minidom, NotFoundErr
-from logging import debug, info, warning, error
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from twisted.internet import defer
 from twisted.python.failure import Failure
 from sat.tools.xml_tools import paramsXML2XMLUI
@@ -115,7 +116,7 @@
         try:
             del self.params[profile]
         except KeyError:
-            error(_("Trying to purge cache of a profile not in memory: [%s]") % profile)
+            log.error(_("Trying to purge cache of a profile not in memory: [%s]") % profile)
 
     def save_xml(self, filename):
         """Save parameters template to xml file"""
@@ -123,7 +124,7 @@
             xml_file.write(self.dom.toxml('utf-8'))
 
     def __init__(self, host, storage):
-        debug("Parameters init")
+        log.debug("Parameters init")
         self.host = host
         self.storage = storage
         self.default_profile = None
@@ -138,7 +139,7 @@
         @return: a Deferred instance
         """
         if self.storage.hasProfile(profile):
-            info(_('The profile name already exists'))
+            log.info(_('The profile name already exists'))
             return defer.fail(Failure(exceptions.ConflictError))
         if not self.host.trigger.point("ProfileCreation", profile):
             return defer.fail(Failure(exceptions.CancelError))
@@ -153,13 +154,13 @@
         @return: a Deferred instance
         """
         if not self.storage.hasProfile(profile):
-            info(_('Trying to delete an unknown profile'))
+            log.info(_('Trying to delete an unknown profile'))
             return defer.fail(Failure(exceptions.ProfileUnknownError))
         if self.host.isConnected(profile):
             if force:
                 self.host.disconnect(profile)
             else:
-                info(_("Trying to delete a connected profile"))
+                log.info(_("Trying to delete a connected profile"))
                 return defer.fail(Failure(exceptions.ConnectedProfileError))
         return self.storage.deleteProfile(profile)
 
@@ -174,11 +175,11 @@
         if profile_key == '@DEFAULT@':
             default = self.host.memory.memory_data.get('Profile_default')
             if not default:
-                info(_('No default profile, returning first one'))  # TODO: manage real default profile
+                log.info(_('No default profile, returning first one'))  # TODO: manage real default profile
                 try:
                     default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0]
                 except IndexError:
-                    info(_('No profile exist yet'))
+                    log.info(_('No profile exist yet'))
                     return ""
             return default  # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
         elif profile_key == C.PROF_KEY_NONE:
@@ -186,7 +187,7 @@
         elif return_profile_keys and profile_key in ["@ALL@"]:
             return profile_key # this value must be managed by the caller
         if not self.storage.hasProfile(profile_key):
-            info(_('Trying to access an unknown profile'))
+            log.info(_('Trying to access an unknown profile'))
             return "" # FIXME: raise exceptions.ProfileUnknownError here (must be well checked, this method is used in lot of places)
         return profile_key
 
@@ -267,23 +268,23 @@
         @param app: name of the frontend registering the parameters
         """
         if not app:
-            warning(_("Trying to register frontends parameters with no specified app: aborted"))
+            log.warning(_("Trying to register frontends parameters with no specified app: aborted"))
             return
         if not hasattr(self, "frontends_cache"):
             self.frontends_cache = []
         if app in self.frontends_cache:
-            debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app}))
+            log.debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app}))
             return
         self.frontends_cache.append(app)
         self.updateParams(xml, security_limit, app)
-        debug("Frontends parameters registered for %(app)s" % {'app': app})
+        log.debug("Frontends parameters registered for %(app)s" % {'app': app})
 
     def __default_ok(self, value, name, category):
         #FIXME: will not work with individual parameters
         self.setParam(name, value, category)
 
     def __default_ko(self, failure, name, category):
-        error(_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category': category, 'name': name, 'reason': str(failure.value)})
+        log.error(_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category': category, 'name': name, 'reason': str(failure.value)})
 
     def setDefault(self, name, category, callback, errback=None):
         """Set default value of parameter
@@ -295,17 +296,17 @@
         """
         #TODO: send signal param update if value changed
         #TODO: manage individual paramaters
-        debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name})
+        log.debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name})
         node = self._getParamNode(name, category, '@ALL@')
         if not node:
-            error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
+            log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
             return
         if node[1].getAttribute('default_cb') == 'yes':
             # del node[1].attributes['default_cb'] # default_cb is not used anymore as a flag to know if we have to set the default value,
                                                    # and we can still use it later e.g. to call a generic setDefault method
             value = self._getParam(category, name, C.GENERAL)
             if value is None: # no value set by the user: we have the default value
-                debug ("Default value to set, using callback")
+                log.debug ("Default value to set, using callback")
                 d = defer.maybeDeferred(callback)
                 d.addCallback(self.__default_ok, name, category)
                 d.addErrback(errback or self.__default_ko, name, category)
@@ -343,7 +344,7 @@
         #FIXME: looks really dirty and buggy, need to be reviewed/refactored
         node = self._getParamNode(name, category)
         if not node:
-            error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
+            log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
             raise exceptions.NotFound
 
         if node[0] == C.GENERAL:
@@ -354,11 +355,11 @@
 
         profile = self.getProfileName(profile_key)
         if not profile:
-            error(_('Requesting a param for an non-existant profile'))
+            log.error(_('Requesting a param for an non-existant profile'))
             raise exceptions.ProfileUnknownError
 
         if profile not in self.params:
-            error(_('Requesting synchronous param for not connected profile'))
+            log.error(_('Requesting synchronous param for not connected profile'))
             raise exceptions.NotConnectedProfileError(profile)
 
         if attr == "value":
@@ -378,11 +379,11 @@
            @param profile: owner of the param (@ALL@ for everyone)"""
         node = self._getParamNode(name, category)
         if not node:
-            error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
+            log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
             return None
 
         if not self.checkSecurityLimit(node[1], security_limit):
-            warning(_("Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
+            log.warning(_("Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
                       % {'param': name, 'cat': category}))
             return None
 
@@ -394,7 +395,7 @@
 
         profile = self.getProfileName(profile_key)
         if not profile:
-            error(_('Requesting a param for a non-existant profile'))
+            log.error(_('Requesting a param for a non-existant profile'))
             return defer.fail()
 
         if attr != "value":
@@ -538,7 +539,7 @@
         """
         profile = self.getProfileName(profile_key)
         if not profile:
-            error(_("Asking params for inexistant profile"))
+            log.error(_("Asking params for inexistant profile"))
             return ""
         d = self.getParams(security_limit, app, profile)
         return d.addCallback(lambda param_xml: paramsXML2XMLUI(param_xml))
@@ -554,7 +555,7 @@
         """
         profile = self.getProfileName(profile_key)
         if not profile:
-            error(_("Asking params for inexistant profile"))
+            log.error(_("Asking params for inexistant profile"))
             return defer.succeed("")
 
         def returnXML(prof_xml):
@@ -577,7 +578,7 @@
         #TODO: manage category of general type (without existant profile)
         profile = self.getProfileName(profile_key)
         if not profile:
-            error(_("Asking params for inexistant profile"))
+            log.error(_("Asking params for inexistant profile"))
             return ""
 
         def returnCategoryXml(prof_xml):
@@ -629,17 +630,17 @@
         if profile_key != C.PROF_KEY_NONE:
             profile = self.getProfileName(profile_key)
             if not profile:
-                error(_('Trying to set parameter for an unknown profile'))
+                log.error(_('Trying to set parameter for an unknown profile'))
                 return  # TODO: throw an error
 
         node = self._getParamNode(name, category, '@ALL@')
         if not node:
-            error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
+            log.error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
                   % {'category': category, 'name': name})
             return
 
         if not self.checkSecurityLimit(node[1], security_limit):
-            warning(_("Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
+            log.warning(_("Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
                           % {'param': name, 'cat': category}))
             return