mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
bitkeeper revision 1.1159.1.292 (41800989G4HjOPTJHRAf8UYug6chUA)
Parse bare words as config files making the -f before a config filename optional. Make parsing intermingled ``getopt'' and ``var=val'' options sane and add support for a default option handler for bare words.
This commit is contained in:
1 parent
86f4b2955d
commit
eb7ab5175a
2 files changed
+36
-20
No files matched your search
@@ -55,6 +55,8 @@ gopts.opt('defconfig', short='f', val='FILE',
|
||||
After the script is loaded, option values that were not set on the
|
||||
command line are replaced by the values set in the script.""")
|
||||
|
||||
gopts.default('defconfig')
|
||||
|
||||
gopts.opt('config', short='F', val='FILE',
|
||||
fn=set_value, default=None,
|
||||
use="""Domain configuration to use (SXP).
|
||||
|
||||
+34
-20
@@ -204,6 +204,8 @@ class Opts:
|
||||
self.vals.quiet = 0
|
||||
# Variables for default scripts.
|
||||
self.vars = {}
|
||||
# Option to use for bare words.
|
||||
self.default_opt = None
|
||||
|
||||
def __repr__(self):
|
||||
return '\n'.join(map(str, self.options))
|
||||
@@ -221,6 +223,15 @@ class Opts:
|
||||
self.options_map[name] = x
|
||||
return x
|
||||
|
||||
def default(self, name):
|
||||
self.default_opt = name
|
||||
|
||||
def getdefault(self, val):
|
||||
if self.default_opt is None:
|
||||
return 0
|
||||
opt = self.option(self.default_opt)
|
||||
return opt.set(val)
|
||||
|
||||
def var(self, name, **args):
|
||||
x = OptVar(self, name, **args)
|
||||
self.options.append(x)
|
||||
@@ -284,27 +295,27 @@ class Opts:
|
||||
"""
|
||||
self.argv = argv
|
||||
|
||||
try:
|
||||
(vals, args) = getopt(argv[1:], self.short_opts(), self.long_opts())
|
||||
except GetoptError, err:
|
||||
self.err(str(err))
|
||||
|
||||
# hack to work around lack of gnu getopts parsing in python 2.2
|
||||
xargs = args
|
||||
while xargs[1:]:
|
||||
(v,xargs) = getopt(xargs[1:], self.short_opts(), self.long_opts())
|
||||
vals = vals + v
|
||||
|
||||
# back to the real work
|
||||
self.args = args
|
||||
for (k, v) in vals:
|
||||
for opt in self.options:
|
||||
if opt.specify(k, v): break
|
||||
else:
|
||||
print >>sys.stderr, "Error: Unknown option:", k
|
||||
self.usage()
|
||||
# hack to work around lack of gnu getopts parsing in python 2.2
|
||||
args = argv[1:]
|
||||
xargs = []
|
||||
for arg in args:
|
||||
while args:
|
||||
# let getopt parse whatever it feels like -- if anything
|
||||
try:
|
||||
(xvals, args) = getopt(args[0:],
|
||||
self.short_opts(), self.long_opts())
|
||||
except GetoptError, err:
|
||||
self.err(str(err))
|
||||
|
||||
for (k, v) in xvals:
|
||||
for opt in self.options:
|
||||
if opt.specify(k, v): break
|
||||
else:
|
||||
print >>sys.stderr, "Error: Unknown option:", k
|
||||
self.usage()
|
||||
|
||||
# then process the 1st arg
|
||||
(arg,args) = (args[0], args[1:])
|
||||
|
||||
isvar = 0
|
||||
if '=' in arg:
|
||||
(k, v) = arg.split('=', 1)
|
||||
@@ -312,8 +323,11 @@ class Opts:
|
||||
if opt.specify(k, v):
|
||||
isvar = 1
|
||||
break
|
||||
elif self.getdefault(arg):
|
||||
isvar = 1
|
||||
if not isvar:
|
||||
xargs.append(arg)
|
||||
|
||||
return xargs
|
||||
|
||||
def short_opts(self):
|
||||
|
||||