ia64/xen-unstable

changeset 8173:5d8a5e7187d5

Use getopt.gnu_getopt rather than getopt.getopt, so that xm list VM --long is
parsed the same as xm list --long VM. This is only in Python 2.3 -- for
Python 2.2 we keep the old getopt.getopt behaviour.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Fri Dec 02 01:04:09 2005 +0000 (2005-12-02)
parents 43582de050c6
children 43a1f899e302 db6d667f5168
files tools/python/xen/xm/main.py tools/python/xen/xm/opts.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Fri Dec 02 01:00:01 2005 +0000
     1.2 +++ b/tools/python/xen/xm/main.py	Fri Dec 02 01:04:09 2005 +0000
     1.3 @@ -25,7 +25,7 @@ import os
     1.4  import os.path
     1.5  import sys
     1.6  import re
     1.7 -from getopt import getopt
     1.8 +import getopt
     1.9  import socket
    1.10  import warnings
    1.11  warnings.filterwarnings('ignore', category=FutureWarning)
    1.12 @@ -39,6 +39,14 @@ from xen.xm.opts import *
    1.13  
    1.14  import console
    1.15  
    1.16 +
    1.17 +# getopt.gnu_getopt is better, but only exists in Python 2.3+.  Use
    1.18 +# getopt.getopt if gnu_getopt is not available.  This will mean that options
    1.19 +# may only be specified before positional arguments.
    1.20 +if not hasattr(getopt, 'gnu_getopt'):
    1.21 +    getopt.gnu_getopt = getopt.getopt
    1.22 +
    1.23 +
    1.24  # Strings for shorthelp
    1.25  console_help = "console <DomId>                  Attach to domain DomId's console."
    1.26  create_help =  """create [-c] <ConfigFile>
    1.27 @@ -332,8 +340,8 @@ def xm_list(args):
    1.28      use_long = 0
    1.29      show_vcpus = 0
    1.30      try:
    1.31 -        (options, params) = getopt(args, 'lv', ['long','vcpus'])
    1.32 -    except GetoptError, opterr:
    1.33 +        (options, params) = getopt.gnu_getopt(args, 'lv', ['long','vcpus'])
    1.34 +    except getopt.GetoptError, opterr:
    1.35          err(opterr)
    1.36          sys.exit(1)
    1.37      
    1.38 @@ -729,8 +737,8 @@ def xm_network_detach(args):
    1.39  def xm_vnet_list(args):
    1.40      from xen.xend.XendClient import server
    1.41      try:
    1.42 -        (options, params) = getopt(args, 'l', ['long'])
    1.43 -    except GetoptError, opterr:
    1.44 +        (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
    1.45 +    except getopt.GetoptError, opterr:
    1.46          err(opterr)
    1.47          sys.exit(1)
    1.48      
     2.1 --- a/tools/python/xen/xm/opts.py	Fri Dec 02 01:00:01 2005 +0000
     2.2 +++ b/tools/python/xen/xm/opts.py	Fri Dec 02 01:04:09 2005 +0000
     2.3 @@ -13,11 +13,12 @@
     2.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.5  #============================================================================
     2.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
     2.7 +# Copyright (C) 2005 XenSource Ltd.
     2.8  #============================================================================
     2.9  
    2.10  """Object-oriented command-line option support.
    2.11  """
    2.12 -from getopt import getopt, GetoptError
    2.13 +import getopt
    2.14  import os
    2.15  import os.path
    2.16  import sys
    2.17 @@ -333,9 +334,10 @@ class Opts:
    2.18          while args:
    2.19              # let getopt parse whatever it feels like -- if anything
    2.20              try:
    2.21 -                (xvals, args) = getopt(args[0:],
    2.22 -                                       self.short_opts(), self.long_opts())
    2.23 -            except GetoptError, err:
    2.24 +                (xvals, args) = getopt.getopt(args[0:],
    2.25 +                                              self.short_opts(),
    2.26 +                                              self.long_opts())
    2.27 +            except getopt.GetoptError, err:
    2.28                  self.err(str(err))
    2.29                  
    2.30              for (k, v) in xvals: