# HG changeset patch # User dkendall # Date 1161957184 -3600 # Node ID 6c528a82d57b5fc32c517ebaab5b7c985f2b338c # Parent 4a320d26fc24bc49ae24f31dec2bf006a9ddc7a8 Create postcheck() that calls postcheck routines registered using the new xm_vars.reg_postcheck(). Each of these receives dictionary of the vars and changes made to var values are permanent. Kinda like an all in one check() that knows about all defined vars. Allows for more generic config files. Signed-off-by: dan kendall diff -r 4a320d26fc24 -r 6c528a82d57b tools/python/xen/xm/help.py --- a/tools/python/xen/xm/help.py Thu Oct 26 16:56:16 2006 +0100 +++ b/tools/python/xen/xm/help.py Fri Oct 27 14:53:04 2006 +0100 @@ -35,6 +35,7 @@ class Vars: self.help = help self.env = env self.vars = [] + self.postchecks = [] def var(self, name, use=None, check=None): """Define a configuration variable. @@ -58,6 +59,34 @@ class Vars: else: for v in self.vars: v.doCheck(self.env) + + def reg_postcheck(self, pcheck): + """Register routine to run after check + """ + self.postchecks.append(pcheck) + + def vars_export_dict(self): + """Export the var list to a dictionary + """ + d = {} + for v in self.vars: + d[v.name] = self.env[v.name] + return d + + def vars_import_dict(self,d): + """Import var list from dictionary + Note we only import already declared vars + """ + for v in self.vars: + self.env[v.name] = d[v.name] + + def postcheck(self): + """Perform any register post check routines + """ + for c in self.postchecks: + d = self.vars_export_dict() + c(d) + self.vars_import_dict(d) def doHelp(self, out=sys.stderr): """Print help for the variables. @@ -86,7 +115,12 @@ class Var: def doCheck(self, env): """Execute the check and set the variable to the new value. """ - if not self.check: return + #ensure variable gets back to config variable 'space' even + #if no check registered + #if not self.check: return + if not self.check: + env[self.name] = '' + return try: env[self.name] = self.check(self.name, env.get(self.name)) except StandardError, ex: