Skip to content
Snippets Groups Projects
Commit d2d7d5c3 authored by Guido Trotter's avatar Guido Trotter Committed by Iustin Pop
Browse files

objects: add configuration upgrade system


Add a very basic configuration update mechanism to objects.
An object can define the UpgradeConfig method, which will be called at
init time, and use it to fill in missing defaults in the configuration.
In the future we may want to make it more complex, for example adding
the config version, but for now a basic solution will do.

Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
(cherry picked from commit 560428be)
parent 8486ffc0
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,7 @@ class ConfigObject(object): ...@@ -58,6 +58,7 @@ class ConfigObject(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
for k, v in kwargs.iteritems(): for k, v in kwargs.iteritems():
setattr(self, k, v) setattr(self, k, v)
self.UpgradeConfig()
def __getattr__(self, name): def __getattr__(self, name):
if name not in self.__slots__: if name not in self.__slots__:
...@@ -165,6 +166,15 @@ class ConfigObject(object): ...@@ -165,6 +166,15 @@ class ConfigObject(object):
"""Implement __repr__ for ConfigObjects.""" """Implement __repr__ for ConfigObjects."""
return repr(self.ToDict()) return repr(self.ToDict())
def UpgradeConfig(self):
"""Fill defaults for missing configuration values.
This method will be called at object init time, and its implementation will
be object dependent.
"""
pass
class TaggableObject(ConfigObject): class TaggableObject(ConfigObject):
"""An generic class supporting tags. """An generic class supporting tags.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment