Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mig/shared/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import os
import sys

from mig.shared.configuration import RuntimeConfiguration
from mig.shared.defaults import MIG_ENV
from mig.shared.fileio import unpickle

Expand All @@ -42,7 +43,6 @@ def get_configuration_object(config_file=None, skip_log=False,
and disable_auth_log arguments are passed on to allow skipping the default
log initialization and disabling auth log for unit tests.
"""
from mig.shared.configuration import Configuration
if config_file:
_config_file = config_file
elif os.environ.get('MIG_CONF', None):
Expand All @@ -63,7 +63,7 @@ def get_configuration_object(config_file=None, skip_log=False,
skip_log = True
disable_auth_log = True

configuration = Configuration(_config_file, False, skip_log,
configuration = RuntimeConfiguration(_config_file, False, skip_log,
disable_auth_log)
return configuration

Expand Down
41 changes: 41 additions & 0 deletions mig/shared/configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -2851,6 +2851,47 @@
return peers_dict


class RuntimeConfiguration(Configuration):
"""A more specific version of the Configuration which additionally supports
the notion of a context.

Contextual information that is relevant to the duration of a request is
required in certain cases e.g. to support templating. Given Configuration
objects are threaded into and throough almost all the necessary codepaths
to make this information available, they are an attractive place to put
this - but a Configuration is currently loaded from static per-site data.

Resolv this ambiguity with this subclass - a raw Confioguration will
continute to represent the static data while a specialised but entirely
compatible object is handed to request processing codepaths.
"""

def __init__(self, config_file, verbose=False, skip_log=False,
disable_auth_log=False):
super().__init__(config_file, verbose, skip_log, disable_auth_log)
self._context = None

def context(self, namespace=None):
"""Retrieve the context or a previously registered namespace.
"""

if self._context is None:
self._context = {}
if namespace is None:
return self._context
# allow the KeyError to escape if the registered namespace is missing
return self._context[namespace]

def context_set(self, value, namespace=None):
"""Attach a value as named namespace within the active congifuration.
"""
assert namespace is not None

context = self.context()
context[namespace] = value
return value


if '__main__' == __name__:
conf = Configuration(os.path.expanduser('~/mig/server/MiGserver.conf'),
True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mig_shared_configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
Expand Down Expand Up @@ -42,7 +42,7 @@

def _to_dict(obj):
return {k: v for k, v in inspect.getmembers(obj)
if not (k.startswith('__') or _is_method(v))}
if not (k.startswith('_') or _is_method(v))}


class MigSharedConfiguration(MigTestCase):
Expand Down
Loading