[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Use getopt.gnu_getopt rather than getopt.getopt, so that xm list VM --long is
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID 5d8a5e7187d56964b3916a368fbecb8773bdd6b6 # Parent 43582de050c69548a233206354a782d92f79701c 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@xxxxxxxxxxxxx> diff -r 43582de050c6 -r 5d8a5e7187d5 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Fri Dec 2 01:00:01 2005 +++ b/tools/python/xen/xm/main.py Fri Dec 2 01:04:09 2005 @@ -25,7 +25,7 @@ import os.path import sys import re -from getopt import getopt +import getopt import socket import warnings warnings.filterwarnings('ignore', category=FutureWarning) @@ -38,6 +38,14 @@ from xen.xm.opts import * import console + + +# getopt.gnu_getopt is better, but only exists in Python 2.3+. Use +# getopt.getopt if gnu_getopt is not available. This will mean that options +# may only be specified before positional arguments. +if not hasattr(getopt, 'gnu_getopt'): + getopt.gnu_getopt = getopt.getopt + # Strings for shorthelp console_help = "console <DomId> Attach to domain DomId's console." @@ -332,8 +340,8 @@ use_long = 0 show_vcpus = 0 try: - (options, params) = getopt(args, 'lv', ['long','vcpus']) - except GetoptError, opterr: + (options, params) = getopt.gnu_getopt(args, 'lv', ['long','vcpus']) + except getopt.GetoptError, opterr: err(opterr) sys.exit(1) @@ -729,8 +737,8 @@ def xm_vnet_list(args): from xen.xend.XendClient import server try: - (options, params) = getopt(args, 'l', ['long']) - except GetoptError, opterr: + (options, params) = getopt.gnu_getopt(args, 'l', ['long']) + except getopt.GetoptError, opterr: err(opterr) sys.exit(1) diff -r 43582de050c6 -r 5d8a5e7187d5 tools/python/xen/xm/opts.py --- a/tools/python/xen/xm/opts.py Fri Dec 2 01:00:01 2005 +++ b/tools/python/xen/xm/opts.py Fri Dec 2 01:04:09 2005 @@ -13,11 +13,12 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #============================================================================ # Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx> +# Copyright (C) 2005 XenSource Ltd. #============================================================================ """Object-oriented command-line option support. """ -from getopt import getopt, GetoptError +import getopt import os import os.path import sys @@ -333,9 +334,10 @@ 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: + (xvals, args) = getopt.getopt(args[0:], + self.short_opts(), + self.long_opts()) + except getopt.GetoptError, err: self.err(str(err)) for (k, v) in xvals: _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |