# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 4f7b4ca2e30c83caf40e10876db62b5b48e7dd1f
# Parent 508bc376c1dd719ad683e4a2835f465f87ffb393
Added reset method to Opts so that create.parseCommandLine can be used more than
once. This makes it possible to unit test this code. Remove the odd aliasing
of gopts to opts inside parseCommandLine.
Rename local variables globals and locals inside opts.load -- these are built-in
functions.
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
diff -r 508bc376c1dd -r 4f7b4ca2e30c tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py Mon Nov 21 11:55:51 2005
+++ b/tools/python/xen/xm/create.py Mon Nov 21 12:00:36 2005
@@ -879,33 +879,33 @@
def parseCommandLine(argv):
- opts = gopts
- args = opts.parse(argv)
- if opts.vals.help:
- opts.usage()
- if opts.vals.help or opts.vals.help_config:
- opts.load_defconfig(help=1)
- if opts.vals.help or opts.vals.help_config:
+ gopts.reset()
+ args = gopts.parse(argv)
+ if gopts.vals.help:
+ gopts.usage()
+ if gopts.vals.help or gopts.vals.help_config:
+ gopts.load_defconfig(help=1)
+ if gopts.vals.help or gopts.vals.help_config:
return (None, None)
- if not opts.vals.display:
- opts.vals.display = os.getenv("DISPLAY")
+ if not gopts.vals.display:
+ gopts.vals.display = os.getenv("DISPLAY")
# Process remaining args as config variables.
for arg in args:
if '=' in arg:
(var, val) = arg.strip().split('=', 1)
gopts.setvar(var.strip(), val.strip())
- if opts.vals.config:
- config = opts.vals.config
+ if gopts.vals.config:
+ config = gopts.vals.config
else:
- opts.load_defconfig()
- preprocess(opts.vals)
- if not opts.getopt('name') and opts.getopt('defconfig'):
- opts.setopt('name', os.path.basename(opts.getopt('defconfig')))
- config = make_config(opts.vals)
-
- return (opts, config)
+ gopts.load_defconfig()
+ preprocess(gopts.vals)
+ if not gopts.getopt('name') and gopts.getopt('defconfig'):
+ gopts.setopt('name', os.path.basename(gopts.getopt('defconfig')))
+ config = make_config(gopts.vals)
+
+ return (gopts, config)
def main(argv):
diff -r 508bc376c1dd -r 4f7b4ca2e30c tools/python/xen/xm/opts.py
--- a/tools/python/xen/xm/opts.py Mon Nov 21 11:55:51 2005
+++ b/tools/python/xen/xm/opts.py Mon Nov 21 12:00:36 2005
@@ -60,6 +60,14 @@
self.value = None
self.set(default)
+
+ def reset(self):
+ self.specified_opt = None
+ self.specified_val = None
+ self.value = None
+ self.set(self.default)
+
+
def __repr__(self):
return self.name + '=' + str(self.specified_val)
@@ -222,6 +230,14 @@
self.vars = {}
# Option to use for bare words.
self.default_opt = None
+
+
+ def reset(self):
+ self.vals = OptVals()
+ self.vars = {}
+ for opt in self.options:
+ opt.reset()
+
def __repr__(self):
return '\n'.join(map(str, self.options))
@@ -416,22 +432,22 @@
are used to set options with the same names.
Variables are not used to set options that are already specified.
"""
- # Create global and lobal dicts for the file.
+ # Create global and local dicts for the file.
# Initialize locals to the vars.
# Use exec to do the standard imports and
# define variables we are passing to the script.
- globals = {}
- locals = {}
- locals.update(self.vars)
+ globs = {}
+ locs = {}
+ locs.update(self.vars)
cmd = '\n'.join(self.imports +
[ "from xen.xm.help import Vars",
"xm_file = '%s'" % defconfig,
"xm_help = %d" % help,
"xm_vars = Vars(xm_file, xm_help, locals())"
])
- exec cmd in globals, locals
+ exec cmd in globs, locs
try:
- execfile(defconfig, globals, locals)
+ execfile(defconfig, globs, locs)
except:
if not help: raise
if help:
@@ -444,7 +460,7 @@
types.IntType,
types.FloatType
]
- for (k, v) in locals.items():
+ for (k, v) in locs.items():
if self.specified(k): continue
if not(type(v) in vtypes): continue
self.setopt(k, v)
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|