ia64/xen-unstable
changeset 11584:a49f9c33aa93
[XM] Text wrapping fix, xm create --help_config fix.
* Fix text wrap so it doesn't chop off last word in help message for
certain cases.
* Fix handling of xm create --help_config
* Remove redundant gopts.usage() call.
Signed-off-by: Alastair Tse <atse@xensource.com>
* Fix text wrap so it doesn't chop off last word in help message for
certain cases.
* Fix handling of xm create --help_config
* Remove redundant gopts.usage() call.
Signed-off-by: Alastair Tse <atse@xensource.com>
author | atse@norwich.uk.xensource.com |
---|---|
date | Fri Sep 22 15:06:00 2006 +0100 (2006-09-22) |
parents | d4b99e615af2 |
children | 1db4e40b4d83 |
files | tools/python/xen/xm/create.py tools/python/xen/xm/opts.py tools/python/xen/xm/shutdown.py |
line diff
1.1 --- a/tools/python/xen/xm/create.py Fri Sep 22 14:57:19 2006 +0100 1.2 +++ b/tools/python/xen/xm/create.py Fri Sep 22 15:06:00 2006 +0100 1.3 @@ -56,7 +56,8 @@ gopts.opt('help', short='h', 1.4 1.5 gopts.opt('help_config', 1.6 fn=set_true, default=0, 1.7 - use="Print help for the configuration script.") 1.8 + use="Print the available configuration variables (vars) for the " 1.9 + "configuration script.") 1.10 1.11 gopts.opt('quiet', short='q', 1.12 fn=set_true, default=0, 1.13 @@ -87,7 +88,7 @@ gopts.opt('config', short='F', val='FILE 1.14 use="Domain configuration to use (SXP).\n" 1.15 "SXP is the underlying configuration format used by Xen.\n" 1.16 "SXP configurations can be hand-written or generated from Python " 1.17 - "configuration scripts, using the -n (dryrun) option to print\n" 1.18 + "configuration scripts, using the -n (dryrun) option to print " 1.19 "the configuration.") 1.20 1.21 gopts.opt('dryrun', short='n', 1.22 @@ -1014,11 +1015,10 @@ def get_xauthority(): 1.23 def parseCommandLine(argv): 1.24 gopts.reset() 1.25 args = gopts.parse(argv) 1.26 - if gopts.vals.help: 1.27 - gopts.usage() 1.28 + 1.29 if gopts.vals.help or gopts.vals.help_config: 1.30 - gopts.load_defconfig(help=1) 1.31 - if gopts.vals.help or gopts.vals.help_config: 1.32 + if gopts.vals.help_config: 1.33 + print gopts.val_usage() 1.34 return (None, None) 1.35 1.36 if not gopts.vals.display:
2.1 --- a/tools/python/xen/xm/opts.py Fri Sep 22 14:57:19 2006 +0100 2.2 +++ b/tools/python/xen/xm/opts.py Fri Sep 22 15:06:00 2006 +0100 2.3 @@ -24,36 +24,32 @@ import os.path 2.4 import sys 2.5 import types 2.6 2.7 +def _line_wrap(text, width = 70): 2.8 + lines = [] 2.9 + current_line = '' 2.10 + words = text.strip().split() 2.11 + while words: 2.12 + word = words.pop(0) 2.13 + if len(current_line) + len(word) + 1 < width: 2.14 + current_line += word + ' ' 2.15 + else: 2.16 + lines.append(current_line.strip()) 2.17 + current_line = word + ' ' 2.18 + 2.19 + if current_line: 2.20 + lines.append(current_line.strip()) 2.21 + return lines 2.22 + 2.23 def wrap(text, width = 70): 2.24 """ Really basic textwrap. Useful because textwrap is not available 2.25 for Python 2.2, and textwrap.wrap ignores newlines in Python 2.3+. 2.26 """ 2.27 - import string 2.28 - 2.29 if len(text) < width: 2.30 return [text] 2.31 2.32 lines = [] 2.33 for line in text.split('\n'): 2.34 - line = line.strip() 2.35 - if len(line) < width: 2.36 - lines.append(line) 2.37 - continue 2.38 - 2.39 - pos = 0 2.40 - while pos <= len(line): 2.41 - wline = line[pos:pos+width].strip() 2.42 - if len(wline) < 2: 2.43 - break 2.44 - 2.45 - if wline[-1] in tuple(string.punctuation): 2.46 - pos += width 2.47 - else: 2.48 - lastword = wline.split()[-1] 2.49 - wline = wline[:-len(lastword)] 2.50 - pos += width - len(lastword) 2.51 - lines.append(wline) 2.52 - 2.53 + lines += _line_wrap(line, width) 2.54 return lines 2.55 2.56 class OptionError(Exception): 2.57 @@ -299,18 +295,22 @@ class Opts: 2.58 2.59 def __str__(self): 2.60 options = [s for s in self.options if s.optkeys[0][0] == '-'] 2.61 - optvals = [s for s in self.options if s.optkeys[0][0] != '-'] 2.62 output = '' 2.63 if options: 2.64 output += '\nOptions:\n\n' 2.65 output += '\n'.join([str(o) for o in options]) 2.66 output += '\n' 2.67 + return output 2.68 + 2.69 + def val_usage(self): 2.70 + optvals = [s for s in self.options if s.optkeys[0][0] != '-'] 2.71 + output = '' 2.72 if optvals: 2.73 output += '\nValues:\n\n' 2.74 output += '\n'.join([str(o) for o in optvals]) 2.75 output += '\n' 2.76 return output 2.77 - 2.78 + 2.79 def opt(self, name, **args): 2.80 """Add an option. 2.81
3.1 --- a/tools/python/xen/xm/shutdown.py Fri Sep 22 14:57:19 2006 +0100 3.2 +++ b/tools/python/xen/xm/shutdown.py Fri Sep 22 15:06:00 2006 +0100 3.3 @@ -120,7 +120,6 @@ def main(argv): 3.4 opts = gopts 3.5 args = opts.parse(argv) 3.6 if opts.vals.help: 3.7 - opts.usage() 3.8 return 3.9 if opts.vals.all: 3.10 main_all(opts, args)