ia64/xen-unstable

changeset 13048:29ae139a0c72

Fix exit status for failed commands, and tidy up the usage display.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Dec 15 02:01:38 2006 +0000 (2006-12-15)
parents d72237b3cc37
children 6477a182e4e9
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Fri Dec 15 01:42:31 2006 +0000
     1.2 +++ b/tools/python/xen/xm/main.py	Fri Dec 15 02:01:38 2006 +0000
     1.3 @@ -608,7 +608,7 @@ def xm_restore(args):
     1.4          (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
     1.5      except getopt.GetoptError, opterr:
     1.6          err(opterr)
     1.7 -        sys.exit(1)
     1.8 +        usage('restore')
     1.9  
    1.10      paused = False
    1.11      for (k, v) in options:
    1.12 @@ -618,7 +618,6 @@ def xm_restore(args):
    1.13      if len(params) != 1:
    1.14          err("Wrong number of parameters")
    1.15          usage('restore')
    1.16 -        sys.exit(1)
    1.17  
    1.18      savefile = os.path.abspath(params[0])
    1.19  
    1.20 @@ -648,7 +647,6 @@ def xm_list(args):
    1.21      except getopt.GetoptError, opterr:
    1.22          err(opterr)
    1.23          usage('list')
    1.24 -        sys.exit(1)
    1.25      
    1.26      for (k, v) in options:
    1.27          if k in ['-l', '--long']:
    1.28 @@ -869,7 +867,7 @@ def xm_start(args):
    1.29          (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
    1.30      except getopt.GetoptError, opterr:
    1.31          err(opterr)
    1.32 -        sys.exit(1)
    1.33 +        usage('start')
    1.34  
    1.35      paused = False
    1.36      for (k, v) in options:
    1.37 @@ -879,7 +877,6 @@ def xm_start(args):
    1.38      if len(params) != 1:
    1.39          err("Wrong number of parameters")
    1.40          usage('start')
    1.41 -        sys.exit(1)
    1.42  
    1.43      dom = params[0]
    1.44      if serverType == SERVER_XEN_API:
    1.45 @@ -910,7 +907,7 @@ def xm_resume(args):
    1.46          (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
    1.47      except getopt.GetoptError, opterr:
    1.48          err(opterr)
    1.49 -        sys.exit(1)
    1.50 +        usage('resume')
    1.51  
    1.52      paused = False
    1.53      for (k, v) in options:
    1.54 @@ -920,7 +917,6 @@ def xm_resume(args):
    1.55      if len(params) != 1:
    1.56          err("Wrong number of parameters")
    1.57          usage('resume')
    1.58 -        sys.exit(1)
    1.59  
    1.60      dom = params[0]
    1.61      if serverType == SERVER_XEN_API:
    1.62 @@ -1115,7 +1111,7 @@ def xm_sched_sedf(args):
    1.63              ['period=', 'slice=', 'latency=', 'extratime=', 'weight='])
    1.64      except getopt.GetoptError, opterr:
    1.65          err(opterr)
    1.66 -        sys.exit(1)
    1.67 +        usage('sched-sedf')
    1.68      
    1.69      # convert to nanoseconds if needed 
    1.70      for (k, v) in options:
    1.71 @@ -1176,7 +1172,6 @@ def xm_sched_credit(args):
    1.72      except getopt.GetoptError, opterr:
    1.73          err(opterr)
    1.74          usage('sched-credit')
    1.75 -        sys.exit(1)
    1.76  
    1.77      domain = None
    1.78      weight = None
    1.79 @@ -1194,7 +1189,6 @@ def xm_sched_credit(args):
    1.80          # place holder for system-wide scheduler parameters
    1.81          err("No domain given.")
    1.82          usage('sched-credit')
    1.83 -        sys.exit(1)
    1.84  
    1.85      if weight is None and cap is None:
    1.86          print server.xend.domain.sched_credit_get(domain)
    1.87 @@ -1223,7 +1217,7 @@ def xm_console(args):
    1.88          (options, params) = getopt.gnu_getopt(args, 'q', ['quiet'])
    1.89      except getopt.GetoptError, opterr:
    1.90          err(opterr)
    1.91 -        sys.exit(1)
    1.92 +        usage('console')
    1.93  
    1.94      for (k, v) in options:
    1.95          if k in ['-q', '--quiet']:
    1.96 @@ -1234,7 +1228,6 @@ def xm_console(args):
    1.97      if len(params) != 1:
    1.98          err('No domain given')
    1.99          usage('console')
   1.100 -        sys.exit(1)
   1.101  
   1.102      dom = params[0]
   1.103  
   1.104 @@ -1262,7 +1255,7 @@ def xm_uptime(args):
   1.105          (options, params) = getopt.gnu_getopt(args, 's', ['short'])
   1.106      except getopt.GetoptError, opterr:
   1.107          err(opterr)
   1.108 -        sys.exit(1)
   1.109 +        usage('uptime')
   1.110  
   1.111      for (k, v) in options:
   1.112          if k in ['-s', '--short']:
   1.113 @@ -1327,7 +1320,7 @@ def xm_dmesg(args):
   1.114          (options, params) = getopt.gnu_getopt(args, 'c', ['clear'])
   1.115      except getopt.GetoptError, opterr:
   1.116          err(opterr)
   1.117 -        sys.exit(1)
   1.118 +        usage('dmesg')
   1.119      
   1.120      use_clear = 0
   1.121      for (k, v) in options:
   1.122 @@ -1337,7 +1330,6 @@ def xm_dmesg(args):
   1.123      if len(params) :
   1.124          err("No parameter required")
   1.125          usage('dmesg')
   1.126 -        sys.exit(1)
   1.127  
   1.128      if not use_clear:
   1.129          print server.xend.node.dmesg.info()
   1.130 @@ -1576,7 +1568,7 @@ def xm_vnet_list(args):
   1.131          (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
   1.132      except getopt.GetoptError, opterr:
   1.133          err(opterr)
   1.134 -        sys.exit(1)
   1.135 +        usage('vnet-list')
   1.136      
   1.137      use_long = 0
   1.138      for (k, v) in options:
   1.139 @@ -1743,8 +1735,7 @@ def main(argv=sys.argv):
   1.140          # strip off prog name and subcmd
   1.141          args = argv[2:]
   1.142          _, rc = _run_cmd(cmd, cmd_name, args)
   1.143 -        if rc:
   1.144 -            usage(cmd_name)
   1.145 +        sys.exit(rc)
   1.146      else:
   1.147          usage()
   1.148  
   1.149 @@ -1780,8 +1771,8 @@ def _run_cmd(cmd, cmd_name, args):
   1.150              err("Most commands need root access.  Please try again as root.")
   1.151          else:
   1.152              err("Unable to connect to xend: %s." % ex[1])
   1.153 -    except SystemExit:
   1.154 -        return True, ''
   1.155 +    except SystemExit, code:
   1.156 +        return code == 0, code
   1.157      except XenAPI.Failure, exn:
   1.158          err(str(exn))
   1.159      except xmlrpclib.Fault, ex: