mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 20:11:20 +00:00
fw/config/core: Implement Configuration structures as Podable
Ensure that the various Configuration structures now have serialization versions.
This commit is contained in:
parent
92cf132cf2
commit
8ee924b896
@ -22,7 +22,7 @@ from wa.utils import log
|
|||||||
from wa.utils.misc import (get_article, merge_config_values)
|
from wa.utils.misc import (get_article, merge_config_values)
|
||||||
from wa.utils.types import (identifier, integer, boolean, list_of_strings,
|
from wa.utils.types import (identifier, integer, boolean, list_of_strings,
|
||||||
list_of, toggle_set, obj_dict, enum)
|
list_of, toggle_set, obj_dict, enum)
|
||||||
from wa.utils.serializer import is_pod
|
from wa.utils.serializer import is_pod, Podable
|
||||||
|
|
||||||
|
|
||||||
# Mapping for kind conversion; see docs for convert_types below
|
# Mapping for kind conversion; see docs for convert_types below
|
||||||
@ -110,7 +110,9 @@ class status_list(list):
|
|||||||
list.append(self, str(item).upper())
|
list.append(self, str(item).upper())
|
||||||
|
|
||||||
|
|
||||||
class LoggingConfig(dict):
|
class LoggingConfig(Podable, dict):
|
||||||
|
|
||||||
|
_pod_serialization_version = 1
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
'file_format': '%(asctime)s %(levelname)-8s %(name)s: %(message)s',
|
'file_format': '%(asctime)s %(levelname)-8s %(name)s: %(message)s',
|
||||||
@ -121,9 +123,14 @@ class LoggingConfig(dict):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_pod(pod):
|
def from_pod(pod):
|
||||||
return LoggingConfig(pod)
|
pod = LoggingConfig._upgrade_pod(pod)
|
||||||
|
pod_version = pod.pop('_pod_version')
|
||||||
|
instance = LoggingConfig(pod)
|
||||||
|
instance._pod_version = pod_version # pylint: disable=protected-access
|
||||||
|
return instance
|
||||||
|
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
|
super(LoggingConfig, self).__init__()
|
||||||
dict.__init__(self)
|
dict.__init__(self)
|
||||||
if isinstance(config, dict):
|
if isinstance(config, dict):
|
||||||
config = {identifier(k.lower()): v for k, v in config.items()}
|
config = {identifier(k.lower()): v for k, v in config.items()}
|
||||||
@ -142,7 +149,14 @@ class LoggingConfig(dict):
|
|||||||
raise ValueError(config)
|
raise ValueError(config)
|
||||||
|
|
||||||
def to_pod(self):
|
def to_pod(self):
|
||||||
return self
|
pod = super(LoggingConfig, self).to_pod()
|
||||||
|
pod.update(self)
|
||||||
|
return pod
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _pod_upgrade_v1(pod):
|
||||||
|
pod['_pod_version'] = pod.get('_pod_version', 1)
|
||||||
|
return pod
|
||||||
|
|
||||||
|
|
||||||
def expanded_path(path):
|
def expanded_path(path):
|
||||||
@ -347,8 +361,9 @@ def _to_pod(cfg_point, value):
|
|||||||
raise ValueError(msg.format(cfg_point.name, value))
|
raise ValueError(msg.format(cfg_point.name, value))
|
||||||
|
|
||||||
|
|
||||||
class Configuration(object):
|
class Configuration(Podable):
|
||||||
|
|
||||||
|
_pod_serialization_version = 1
|
||||||
config_points = []
|
config_points = []
|
||||||
name = ''
|
name = ''
|
||||||
|
|
||||||
@ -357,7 +372,7 @@ class Configuration(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_pod(cls, pod):
|
def from_pod(cls, pod):
|
||||||
instance = cls()
|
instance = super(Configuration, cls).from_pod(pod)
|
||||||
for cfg_point in cls.config_points:
|
for cfg_point in cls.config_points:
|
||||||
if cfg_point.name in pod:
|
if cfg_point.name in pod:
|
||||||
value = pod.pop(cfg_point.name)
|
value = pod.pop(cfg_point.name)
|
||||||
@ -370,6 +385,7 @@ class Configuration(object):
|
|||||||
return instance
|
return instance
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
super(Configuration, self).__init__()
|
||||||
for confpoint in self.config_points:
|
for confpoint in self.config_points:
|
||||||
confpoint.set_value(self, check_mandatory=False)
|
confpoint.set_value(self, check_mandatory=False)
|
||||||
|
|
||||||
@ -393,12 +409,17 @@ class Configuration(object):
|
|||||||
cfg_point.validate(self)
|
cfg_point.validate(self)
|
||||||
|
|
||||||
def to_pod(self):
|
def to_pod(self):
|
||||||
pod = {}
|
pod = super(Configuration, self).to_pod()
|
||||||
for cfg_point in self.config_points:
|
for cfg_point in self.config_points:
|
||||||
value = getattr(self, cfg_point.name, None)
|
value = getattr(self, cfg_point.name, None)
|
||||||
pod[cfg_point.name] = _to_pod(cfg_point, value)
|
pod[cfg_point.name] = _to_pod(cfg_point, value)
|
||||||
return pod
|
return pod
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _pod_upgrade_v1(pod):
|
||||||
|
pod['_pod_version'] = pod.get('_pod_version', 1)
|
||||||
|
return pod
|
||||||
|
|
||||||
|
|
||||||
# This configuration for the core WA framework
|
# This configuration for the core WA framework
|
||||||
class MetaConfiguration(Configuration):
|
class MetaConfiguration(Configuration):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user