From 859804fbea8588edb57a15ba4e625d2cc07c2a0b Mon Sep 17 00:00:00 2001 From: "xenrtd@shispar-rt.testdev.hq.xensource.com" Date: Mon, 21 Nov 2005 18:52:40 +0100 Subject: [PATCH 1/2] Catch parsing errors in xm create. --- tools/python/xen/xm/create.py | 8 +++++--- tools/python/xen/xm/help.py | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index 6d90f85d03..8bf3c5f6ef 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -909,7 +909,10 @@ def parseCommandLine(argv): def main(argv): - (opts, config) = parseCommandLine(argv) + try: + (opts, config) = parseCommandLine(argv) + except StandardError, ex: + err(str(ex)) if not opts: return @@ -924,8 +927,7 @@ def main(argv): dom0_min_mem = xroot.get_dom0_min_mem() if dom0_min_mem != 0: if balloon_out(dom0_min_mem, opts): - print >>sys.stderr, "error: cannot allocate enough memory for domain" - sys.exit(1) + err("cannot allocate enough memory for domain") dom = make_domain(opts, config) if opts.vals.console_autoconnect: diff --git a/tools/python/xen/xm/help.py b/tools/python/xen/xm/help.py index 276cfbbf4a..9db2e31fdf 100644 --- a/tools/python/xen/xm/help.py +++ b/tools/python/xen/xm/help.py @@ -87,7 +87,10 @@ class Var: """Execute the check and set the variable to the new value. """ if not self.check: return - env[self.name] = self.check(self.name, env.get(self.name)) + try: + env[self.name] = self.check(self.name, env.get(self.name)) + except StandardError, ex: + raise sys.exc_type, self.name + " - " + str(ex) def doHelp(self, out): """Print help for the variable. From b12096d7038cc4780265ee6bcb0f66bd4f061736 Mon Sep 17 00:00:00 2001 From: "kgrant@localhost.localdomain" Date: Mon, 21 Nov 2005 18:53:31 +0100 Subject: [PATCH 2/2] use help in create.py for "xm help create" --- tools/python/xen/xm/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index ba89e6a766..143e521a7a 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -182,7 +182,7 @@ For more help on xm create, see the xmdomain.cfg(5) man page""" help = { "--long": longhelp, "console": console_help, - "create": create_help, +# create is handled specially "destroy": destroy_help, "domid ": domid_help, "domname": domname_help, @@ -846,6 +846,9 @@ def deprecated(old,new): err('Option %s is the new replacement, see "xm help %s" for more info' % (new, new)) def usage(cmd=None): + if cmd = 'create' + xm_subcommand("create", "--help") + sys.exit(1) if help.has_key(cmd): print " " + help[cmd] else: