From: kaf24@firebug.cl.cam.ac.uk Date: Tue, 27 Jun 2006 10:05:39 +0000 (+0100) Subject: [TOOLS] Fix cm argument processing some more: X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15913^2~28 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=db57f1b6d8534b39dd1b757cb507d9f285f21ccc;p=xen.git [TOOLS] Fix cm argument processing some more: 1. Remove has_long_option() and add arg_check_for_resource_list() instead. 2. 'args' tells 'options' from 'params' by using gnu_getopt(). 3. 'options' checks whether -l/--long option is specified. 4. If 'params' not given, print out 'No domain parameter given' and usage. 5. If 'params' given multiple domains, print out 'No multiple domain parameters allowed' and usage. 6. Then it displays the resources as usual. Signed-off-by: Masaki Kanno --- diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index ade43d9445..a9be5e661c 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -887,7 +887,7 @@ def parse_dev_info(info): 'ring-ref' : get_info('ring-ref', int, -1), } -def has_long_option(args): +def arg_check_for_resource_list(args, name): use_long = 0 try: (options, params) = getopt.gnu_getopt(args, 'l', ['long']) @@ -898,16 +898,19 @@ def has_long_option(args): for (k, v) in options: if k in ['-l', '--long']: use_long = 1 + + if len(params) == 0: + print 'No domain parameter given' + usage(name) + if len(params) > 1: + print 'No multiple domain parameters allowed' + usage(name) + return (use_long, params) def xm_network_list(args): - arg_check(args, "network-list", 1, 2) + (use_long, params) = arg_check_for_resource_list(args, "network-list") - (use_long, params) = has_long_option(args) - - if len(params) == 0: - print 'No domain parameter given' - sys.exit(1) dom = params[0] if use_long: devs = server.xend.domain.getDeviceSxprs(dom, 'vif') @@ -931,13 +934,8 @@ def xm_network_list(args): % ni) def xm_block_list(args): - arg_check(args, "block-list", 1, 2) + (use_long, params) = arg_check_for_resource_list(args, "block-list") - (use_long, params) = has_long_option(args) - - if len(params) == 0: - print 'No domain parameter given' - sys.exit(1) dom = params[0] if use_long: devs = server.xend.domain.getDeviceSxprs(dom, 'vbd') @@ -960,13 +958,8 @@ def xm_block_list(args): % ni) def xm_vtpm_list(args): - arg_check(args, "vtpm-list", 1, 2) + (use_long, params) = arg_check_for_resource_list(args, "vtpm-list") - (use_long, params) = has_long_option(args) - - if len(params) == 0: - print 'No domain parameter given' - sys.exit(1) dom = params[0] if use_long: devs = server.xend.domain.getDeviceSxprs(dom, 'vtpm')