summaryrefslogtreecommitdiffstats
path: root/src/python
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-09-25 14:26:09 +0200
committerPeter Schiffer <pschiffe@redhat.com>2013-09-25 14:26:09 +0200
commitcb5d40a7166ea5f4566ce19de49780656c69b1b4 (patch)
treed1a193e7aedc68ea2d17a544a615053fc1eeb732 /src/python
parent2e20f92522b659b206c907007d6f5757b406bb61 (diff)
parent3370cfe4beb83a31c0fd5f6e5ac6d8b1c3be9fd5 (diff)
downloadopenlmi-providers-cb5d40a7166ea5f4566ce19de49780656c69b1b4.tar.gz
openlmi-providers-cb5d40a7166ea5f4566ce19de49780656c69b1b4.tar.xz
openlmi-providers-cb5d40a7166ea5f4566ce19de49780656c69b1b4.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/openlmi-providers
Conflicts: src/hardware/LMI_PCIBridgeProvider.c src/hardware/LMI_PCIBridgeSystemDeviceProvider.c src/hardware/LMI_PCIDeviceProvider.c src/hardware/LMI_PCIDeviceSystemDeviceProvider.c
Diffstat (limited to 'src/python')
-rw-r--r--src/python/lmi/base/BaseConfiguration.py40
-rw-r--r--src/python/lmi/providers/cmpi_logging.py65
2 files changed, 73 insertions, 32 deletions
diff --git a/src/python/lmi/base/BaseConfiguration.py b/src/python/lmi/base/BaseConfiguration.py
index 8790acf..275fc0f 100644
--- a/src/python/lmi/base/BaseConfiguration.py
+++ b/src/python/lmi/base/BaseConfiguration.py
@@ -72,9 +72,12 @@ class BaseConfiguration(Singleton):
There should be only one instance of this class.
"""
- CONFIG_DIRECTORY_TEMPLATE = '/etc/openlmi/%(provider_prefix)s/'
- CONFIG_FILE_PATH_TEMPLATE = \
- CONFIG_DIRECTORY_TEMPLATE + '%(provider_prefix)s.conf'
+ CONFIG_DIRECTORY_TEMPLATE_TOPLEVEL = '/etc/openlmi/'
+ CONFIG_DIRECTORY_TEMPLATE_PROVIDER = '/etc/openlmi/%(provider_prefix)s/'
+ CONFIG_FILE_PATH_TEMPLATE_TOPLEVEL = \
+ CONFIG_DIRECTORY_TEMPLATE_TOPLEVEL + 'openlmi.conf'
+ CONFIG_FILE_PATH_TEMPLATE_PROVIDER = \
+ CONFIG_DIRECTORY_TEMPLATE_PROVIDER + '%(provider_prefix)s.conf'
PERSISTENT_PATH_TEMPLATE = '/var/lib/openlmi-%(provider_prefix)s/'
SETTINGS_DIR = 'settings/'
@@ -106,11 +109,17 @@ class BaseConfiguration(Singleton):
return cls.DEFAULT_OPTIONS
@classmethod
- def config_directory(cls):
- """ Base directory with configuration settings. """
- return cls.CONFIG_DIRECTORY_TEMPLATE % {
+ def config_directory_toplevel(cls):
+ """ Base directory with toplevel configuration settings. """
+ return cls.CONFIG_DIRECTORY_TEMPLATE_TOPLEVEL
+
+ @classmethod
+ def config_directory_provider(cls):
+ """ Base directory with provider specific configuration settings. """
+ return cls.CONFIG_DIRECTORY_TEMPLATE_PROVIDER % {
'provider_prefix' : cls.provider_prefix() }
+
@classmethod
def persistent_path(cls):
""" Base directory with persistent settings. """
@@ -118,11 +127,17 @@ class BaseConfiguration(Singleton):
'provider_prefix': cls.provider_prefix() }
@classmethod
- def config_file_path(cls):
- """ File path of configuration file. """
- return cls.CONFIG_FILE_PATH_TEMPLATE % {
+ def config_file_path_toplevel(cls):
+ """ File path of toplevel configuration file. """
+ return cls.CONFIG_FILE_PATH_TEMPLATE_TOPLEVEL
+
+ @classmethod
+ def config_file_path_provider(cls):
+ """ File path of provider specific configuration file. """
+ return cls.CONFIG_FILE_PATH_TEMPLATE_PROVIDER % {
'provider_prefix' : cls.provider_prefix() }
+
@classmethod
def mandatory_sections(cls):
"""
@@ -163,10 +178,11 @@ class BaseConfiguration(Singleton):
def load(self):
"""
- Load configuration from config file path.
- The file does not need to exist.
+ Load configuration from config files. Provider specific options
+ overrides toplevel openlmi configuration.
+ The files do not need to exist.
"""
- self.config.read(self.config_file_path())
+ self.config.read([self.config_file_path_toplevel(), self.config_file_path_provider()])
for section in self.mandatory_sections():
if not self.config.has_section(section):
self.config.add_section(section)
diff --git a/src/python/lmi/providers/cmpi_logging.py b/src/python/lmi/providers/cmpi_logging.py
index 1eb9e3a..c1e29c9 100644
--- a/src/python/lmi/providers/cmpi_logging.py
+++ b/src/python/lmi/providers/cmpi_logging.py
@@ -30,9 +30,9 @@ import os
import sys
# Custom logging levels
-TRACE_WARNING = logging.INFO - 1
-TRACE_INFO = logging.INFO - 2
-TRACE_VERBOSE = logging.DEBUG
+TRACE_WARNING = logging.DEBUG - 1
+TRACE_INFO = logging.DEBUG - 2
+TRACE_VERBOSE = logging.DEBUG - 3
# Mapping from level name to its number
LOGGING_LEVELS = {
@@ -41,10 +41,10 @@ LOGGING_LEVELS = {
"warning" : logging.WARNING,
"warn" : logging.WARNING,
"info" : logging.INFO,
+ "debug" : logging.DEBUG,
"trace_warning" : TRACE_WARNING,
"trace_info" : TRACE_INFO,
- "trace_verbose" : TRACE_VERBOSE,
- "debug" : logging.DEBUG
+ "trace_verbose" : TRACE_VERBOSE
}
DEFAULT_LOGGING_CONFIG = {
@@ -130,11 +130,13 @@ class CMPILogHandler(logging.Handler):
self.cmpi_logger.log_warn(msg)
elif record.levelno >= logging.INFO:
self.cmpi_logger.log_info(msg)
+ elif record.levelno >= logging.DEBUG:
+ self.cmpi_logger.log_debug(msg)
elif record.levelno >= TRACE_WARNING:
self.cmpi_logger.trace_warn(record.filename, msg)
elif record.levelno >= TRACE_INFO:
self.cmpi_logger.trace_info(record.filename, msg)
- elif record.levelno >= logging.DEBUG:
+ elif record.levelno >= TRACE_VERBOSE:
self.cmpi_logger.trace_verbose(record.filename, msg)
class CMPILogger(logging.getLoggerClass()):
@@ -184,6 +186,41 @@ class CMPILogger(logging.getLoggerClass()):
logging.setLoggerClass(CMPILogger)
+def render_value(val):
+ """
+ When logging values, we want to avoid excessively long messages caused
+ by rendering argument values like lists, dictionaries etc.
+ Let's shorten these iterable objects to just one or few items.
+
+ :param val: Any value for rendering.
+ :returns: Representation string of value, possibly shortened.
+ :rtype: string
+ """
+ if isinstance(val, list):
+ if len(val) < 2:
+ return repr(val)
+ else:
+ return "[%s, ... (%d more items)]" % (
+ render_value(val[0]), len(val) - 1)
+ elif isinstance(val, dict):
+ if len(val) < 2:
+ return repr(val)
+ else:
+ key = next(iter(val))
+ return '{%s: %s, ... (%d more items)}' % (
+ render_value(key), render_value(val[key]), len(val) - 1)
+ elif isinstance(val, set):
+ if len(val) < 2:
+ return repr(val)
+ else:
+ return '{%s, ... (%d more items)}' % (
+ render_value(val[0]), len(val) - 1)
+ elif isinstance(val, tuple):
+ return "(%s%s)" % (
+ ", ".join(render_value(i) for i in val),
+ ", " if len(val) < 2 else '')
+ return repr(val)
+
def trace_function_or_method(is_method=False, frame_level=1):
"""
Factory for function and method decorators. Generated decorators
@@ -211,18 +248,6 @@ def trace_function_or_method(is_method=False, frame_level=1):
if not inspect.ismethod(func) and not inspect.isfunction(func):
raise TypeError("func must be a function")
- def _print_value(val):
- """
- Used here for printing function arguments. Shortens the output
- string, if that would be too long.
- """
- if isinstance(val, list):
- if len(val) < 2:
- return str(val)
- else:
- return "[%s, ...]" % _print_value(val[0])
- return str(val)
-
module = func.__module__.split('.')[-1]
frm = inspect.currentframe()
for _ in range(frame_level):
@@ -250,8 +275,8 @@ def trace_function_or_method(is_method=False, frame_level=1):
"lineno" : lineno,
"action" : "entering",
"args" : ", ".join(chain(
- (_print_value(a) for a in args),
- ( "%s=%s"%(k, _print_value(v))
+ (render_value(a) for a in args),
+ ( "%s=%s"%(k, render_value(v))
for k, v in kwargs.items())))
})