mirror of
https://github.com/xen-project/xen.git
synced 2026-10-30 03:00:05 +01:00
[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>
This commit is contained in:
1 parent
e790efba8a
commit
1681108c98
3 files changed
+29
-30
No files matched your search
@@ -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 get_xauthority():
|
||||
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:
|
||||
|
||||
+23
-23
@@ -24,36 +24,32 @@ import os.path
|
||||
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.
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||