[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] [XM] Text wrapping fix, xm create --help_config fix.
# HG changeset patch # User atse@xxxxxxxxxxxxxxxxxxxxxxxx # Node ID a49f9c33aa9372a86f79a54e12b24d1de82db3b7 # Parent d4b99e615af25d510302ee3bac552621a19123a1 [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@xxxxxxxxxxxxx> --- tools/python/xen/xm/create.py | 12 +++++----- tools/python/xen/xm/opts.py | 46 ++++++++++++++++++++-------------------- tools/python/xen/xm/shutdown.py | 1 3 files changed, 29 insertions(+), 30 deletions(-) diff -r d4b99e615af2 -r a49f9c33aa93 tools/python/xen/xm/create.py --- a/tools/python/xen/xm/create.py Fri Sep 22 14:57:19 2006 +0100 +++ b/tools/python/xen/xm/create.py Fri Sep 22 15:06:00 2006 +0100 @@ -56,7 +56,8 @@ gopts.opt('help', short='h', gopts.opt('help_config', fn=set_true, default=0, - use="Print help for the configuration script.") + use="Print the available configuration variables (vars) for the " + "configuration script.") gopts.opt('quiet', short='q', fn=set_true, default=0, @@ -87,7 +88,7 @@ gopts.opt('config', short='F', val='FILE use="Domain configuration to use (SXP).\n" "SXP is the underlying configuration format used by Xen.\n" "SXP configurations can be hand-written or generated from Python " - "configuration scripts, using the -n (dryrun) option to print\n" + "configuration scripts, using the -n (dryrun) option to print " "the configuration.") gopts.opt('dryrun', short='n', @@ -1014,11 +1015,10 @@ def parseCommandLine(argv): def parseCommandLine(argv): gopts.reset() args = gopts.parse(argv) - if gopts.vals.help: - gopts.usage() + if gopts.vals.help or gopts.vals.help_config: - gopts.load_defconfig(help=1) - if gopts.vals.help or gopts.vals.help_config: + if gopts.vals.help_config: + print gopts.val_usage() return (None, None) if not gopts.vals.display: diff -r d4b99e615af2 -r a49f9c33aa93 tools/python/xen/xm/opts.py --- a/tools/python/xen/xm/opts.py Fri Sep 22 14:57:19 2006 +0100 +++ b/tools/python/xen/xm/opts.py Fri Sep 22 15:06:00 2006 +0100 @@ -24,36 +24,32 @@ import sys import sys import types +def _line_wrap(text, width = 70): + lines = [] + current_line = '' + words = text.strip().split() + while words: + word = words.pop(0) + if len(current_line) + len(word) + 1 < width: + current_line += word + ' ' + else: + lines.append(current_line.strip()) + current_line = word + ' ' + + if current_line: + lines.append(current_line.strip()) + return lines + def wrap(text, width = 70): """ Really basic textwrap. Useful because textwrap is not available for Python 2.2, and textwrap.wrap ignores newlines in Python 2.3+. """ - import string - if len(text) < width: return [text] lines = [] for line in text.split('\n'): - line = line.strip() - if len(line) < width: - lines.append(line) - continue - - pos = 0 - while pos <= len(line): - wline = line[pos:pos+width].strip() - if len(wline) < 2: - break - - if wline[-1] in tuple(string.punctuation): - pos += width - else: - lastword = wline.split()[-1] - wline = wline[:-len(lastword)] - pos += width - len(lastword) - lines.append(wline) - + lines += _line_wrap(line, width) return lines class OptionError(Exception): @@ -299,18 +295,22 @@ class Opts: def __str__(self): options = [s for s in self.options if s.optkeys[0][0] == '-'] - optvals = [s for s in self.options if s.optkeys[0][0] != '-'] output = '' if options: output += '\nOptions:\n\n' output += '\n'.join([str(o) for o in options]) output += '\n' + return output + + def val_usage(self): + optvals = [s for s in self.options if s.optkeys[0][0] != '-'] + output = '' if optvals: output += '\nValues:\n\n' output += '\n'.join([str(o) for o in optvals]) output += '\n' return output - + def opt(self, name, **args): """Add an option. diff -r d4b99e615af2 -r a49f9c33aa93 tools/python/xen/xm/shutdown.py --- a/tools/python/xen/xm/shutdown.py Fri Sep 22 14:57:19 2006 +0100 +++ b/tools/python/xen/xm/shutdown.py Fri Sep 22 15:06:00 2006 +0100 @@ -120,7 +120,6 @@ def main(argv): opts = gopts args = opts.parse(argv) if opts.vals.help: - opts.usage() return if opts.vals.all: main_all(opts, args) _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |