Skip to content

Commit b2b89e3

Browse files
committed
RuntimeConfiguration
1 parent db80968 commit b2b89e3

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

mig/shared/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import os
3333
import sys
3434

35+
from mig.shared.configuration import RuntimeConfiguration
3536
from mig.shared.defaults import MIG_ENV
3637
from mig.shared.fileio import unpickle
3738

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

66-
configuration = Configuration(_config_file, False, skip_log,
66+
configuration = RuntimeConfiguration(_config_file, False, skip_log,
6767
disable_auth_log)
6868
return configuration
6969

mig/shared/configuration.py

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,6 @@ def __init__(self, config_file, verbose=False, skip_log=False,
759759
self.default_page = None
760760
self.auth_logger_obj = None
761761
self.gdp_logger_obj = None
762-
self._context = None
763762

764763
configuration_options = copy.deepcopy(_CONFIGURATION_DEFAULTS)
765764

@@ -771,26 +770,6 @@ def __init__(self, config_file, verbose=False, skip_log=False,
771770
disable_auth_log=disable_auth_log,
772771
_config_file=config_file)
773772

774-
def context(self, namespace=None):
775-
"""Retrieve the context or a previously registered namespace.
776-
"""
777-
778-
if self._context is None:
779-
self._context = {}
780-
if namespace is None:
781-
return self._context
782-
# allow the KeyError to escape if the registered namespace is missing
783-
return self._context[namespace]
784-
785-
def context_set(self, value, namespace=None):
786-
"""Attach a value as named namespace within the active congifuration.
787-
"""
788-
assert namespace is not None
789-
790-
context = self.context()
791-
context[namespace] = value
792-
return value
793-
794773
def reload_config(self, verbose, skip_log=False, disable_auth_log=False,
795774
_config_file=None):
796775
"""Re-read and parse configuration file. Optional skip_log arg
@@ -2872,6 +2851,47 @@ def parse_peers(self, peerfile):
28722851
return peers_dict
28732852

28742853

2854+
class RuntimeConfiguration(Configuration):
2855+
"""A more specific version of the Configuration which additionally supports
2856+
the notion of a context.
2857+
2858+
Contextual information that is relevant to the duration of a request is
2859+
required in certain cases e.g. to support templating. Given Configuration
2860+
objects are threaded into and throough almost all the necessary codepaths
2861+
to make this information available, they are an attractive place to put
2862+
this - but a Configuration is currently loaded from static per-site data.
2863+
2864+
Resolv this ambiguity with this subclass - a raw Confioguration will
2865+
continute to represent the static data while a specialised but entirely
2866+
compatible object is handed to request processing codepaths.
2867+
"""
2868+
2869+
def __init__(self, config_file, verbose=False, skip_log=False,
2870+
disable_auth_log=False):
2871+
super().__init__(config_file, verbose, skip_log, disable_auth_log)
2872+
self._context = None
2873+
2874+
def context(self, namespace=None):
2875+
"""Retrieve the context or a previously registered namespace.
2876+
"""
2877+
2878+
if self._context is None:
2879+
self._context = {}
2880+
if namespace is None:
2881+
return self._context
2882+
# allow the KeyError to escape if the registered namespace is missing
2883+
return self._context[namespace]
2884+
2885+
def context_set(self, value, namespace=None):
2886+
"""Attach a value as named namespace within the active congifuration.
2887+
"""
2888+
assert namespace is not None
2889+
2890+
context = self.context()
2891+
context[namespace] = value
2892+
return value
2893+
2894+
28752895
if '__main__' == __name__:
28762896
conf = Configuration(os.path.expanduser('~/mig/server/MiGserver.conf'),
28772897
True)

0 commit comments

Comments
 (0)