On Mon, Aug 10, 2009 at 12:05 PM, Iustin Pop<ius...@google.com> wrote: > From: Guido Trotter <ultrot...@google.com> > > 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: Guido Trotter <ultrot...@google.com> > Reviewed-by: Iustin Pop <ius...@google.com> > (cherry picked from commit 560428be4f5852813972cd2791f425cf708ca7c6)
LGTM :) Guido > --- > lib/objects.py | 10 ++++++++++ > 1 files changed, 10 insertions(+), 0 deletions(-) > > diff --git a/lib/objects.py b/lib/objects.py > index acb24d8..23bb0f9 100644 > --- a/lib/objects.py > +++ b/lib/objects.py > @@ -58,6 +58,7 @@ class ConfigObject(object): > def __init__(self, **kwargs): > for k, v in kwargs.iteritems(): > setattr(self, k, v) > + self.UpgradeConfig() > > def __getattr__(self, name): > if name not in self.__slots__: > @@ -165,6 +166,15 @@ class ConfigObject(object): > """Implement __repr__ for ConfigObjects.""" > 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): > """An generic class supporting tags. > -- > 1.6.3.3 > > -- Guido Trotter Google - Sysops Team Google Ireland Ltd. : Registered in Ireland with company number 368047. Gordon House, Barrow Street, Dublin 4, Ireland.