本文整理汇总了Python中optparse.IndentedHelpFormatter类的典型用法代码示例。如果您正苦于以下问题:Python IndentedHelpFormatter类的具体用法?Python IndentedHelpFormatter怎么用?Python IndentedHelpFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IndentedHelpFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
options = [
Option('-d', '--dontcares', dest='dc', default='',
help='comma-separated don\'t-cares', metavar='D'),
Option('-o', '--ones', dest='ones', default='',
help='comma-separated ones', metavar='O'),
Option('-z', '--zeros', dest='zeros', default='',
help='comma-separated zeros', metavar='Z')
]
f = IndentedHelpFormatter()
def raw_format(s): return s + '\n'
f.format_description = raw_format
optparser = OptionParser(description=__doc__, formatter=f)
optparser.add_options(options)
opts, args = optparser.parse_args()
if len(sys.argv) == 1 or args:
optparser.print_help()
exit()
opts.dc = [int(i) for i in opts.dc.split(',') if i]
opts.ones = [int(i) for i in opts.ones.split(',') if i]
opts.zeros = [int(i) for i in opts.zeros.split(',') if i]
soln = qm(dc=opts.dc, ones=opts.ones, zeros=opts.zeros)
if len(soln) == 0:
sys.stdout.write('contradiction\n')
elif len(soln) == 1 and soln[0].count('X') == len(soln[0]):
sys.stdout.write('tautology\n')
else:
sys.stdout.write(' '.join(soln) + '\n')
示例2: __init__
def __init__ (self,
indent_increment=2,
max_help_position=32,
width=78,
short_first=1):
IndentedHelpFormatter.__init__(
self, indent_increment, max_help_position,
width, short_first)
示例3: __init__
def __init__(self, *args, **kwargs):
from textwrap import fill, wrap
IndentedHelpFormatter.__init__(self, *args, **kwargs)
tw = type('textwrap_mock', (object, ), dict(
fill=staticmethod(fill),
wrap=staticmethod(lambda *args, **kwargs:
wrap(*args, **dict(kwargs, break_on_hyphens=False)),
)))
self.format_option.__globals__['textwrap'] = tw
示例4: __init__
def __init__(self,
indent_increment=0,
max_help_position=80,
width=None,
short_first=1):
IndentedHelpFormatter.__init__(self,
indent_increment=indent_increment,
max_help_position=max_help_position,
width=width,
short_first=short_first)
示例5: format_epilog
def format_epilog(self, epilog):
buf = StringIO()
buf.write(IndentedHelpFormatter.format_epilog(self, epilog))
buf.write("\n")
buf.write(self._wrap_it("For further information check out: " "http://anvil.readthedocs.org"))
buf.write("\n")
return buf.getvalue()
示例6: _format_text
def _format_text(self, text):
__doc__ = IndentedHelpFormatter._format_text
return "\n\n".join(
t if len(t) == 0 or t[0].isspace()
else IndentedHelpFormatter._format_text(self, t)
for t in text.split("\n\n")
)
示例7: format_option_strings
def format_option_strings(self, option):
"""Extend option string formatting to support arguments for
commands"""
if option.action == 'command' and not option.args == 'no':
arg_name = option.metavar or _('indices')
if option.args == 'optional':
arg_name = ''.join(['[', arg_name, ']'])
lopts = [' '.join([lopt, arg_name]) for lopt in
option._long_opts]
return ', '.join(lopts)
else:
return IndentedHelpFormatter.format_option_strings(self, option)
示例8: format_usage
def format_usage(self, usage):
buf = StringIO()
buf.write(IndentedHelpFormatter.format_usage(self, usage))
buf.write("\n")
buf.write(self._wrap_it(OVERVIEW))
buf.write("\n\n")
buf.write(self._wrap_it(STEPS))
buf.write("\n\n")
for k in sorted(STEP_SECTIONS.keys()):
buf.write("%s:\n" % (k.title()))
for line in STEP_SECTIONS[k]:
buf.write(" %s\n" % (line))
return buf.getvalue()
示例9: format_help
def format_help(self, formatter=None):
class Positional(object):
def __init__(self, args):
self.option_groups = []
self.option_list = args
positional = Positional(self.positional)
formatter = IndentedHelpFormatter()
formatter.store_option_strings(positional)
output = ['\n', formatter.format_heading("Positional Arguments")]
formatter.indent()
pos_help = [formatter.format_option(opt) for opt in self.positional]
pos_help = [line.replace('--','') for line in pos_help]
output += pos_help
return OptionParser.format_help(self, formatter) + ''.join(output)
示例10: format_option
def format_option(self, option):
"""Extend option formatting to include formatting of supported
options."""
result = IndentedHelpFormatter.format_option(self, option)
if option.action == 'command' and option.options:
options = ', '.join(option.options)
msg = _('Supported options: ')
# build the complete options string and wrap it to width of the
# help
opt_str = ''.join((msg, options))
initial_indent = ' '*(self.help_position + 4)
subsequent_indent = ' '*(self.help_position + 4 + len(msg))
width = self.help_position + self.help_width
opt_str = textwrap.fill(opt_str, width,
initial_indent=initial_indent,
subsequent_indent=subsequent_indent)
result += opt_str + '\n'
return result
示例11: format_option
def format_option(self, option):
"""Return colorful formatted help for an option."""
option = IndentedHelpFormatter.format_option(self, option)
# long options with args
option = re.sub(
r"--([a-zA-Z]*)=([a-zA-Z]*)",
lambda m: "-%s %s" % (self.output.green(m.group(1)),
self.output.blue(m.group(2))),
option)
# short options with args
option = re.sub(
r"-([a-zA-Z]) ?([0-9A-Z]+)",
lambda m: " -" + self.output.green(m.group(1)) + ' ' + \
self.output.blue(m.group(2)),
option)
# options without args
option = re.sub(
r"-([a-zA-Z\d]+)", lambda m: "-" + self.output.green(m.group(1)),
option)
return option
示例12: format_option
def format_option(self, option):
"""Extend option formatting to include formatting of supported
options."""
result = IndentedHelpFormatter.format_option(self, option)
if option.action == 'command' and option.options:
options = ', '.join(option.options)
msg = _('Supported options: ')
# make sure we have the correct length
# (and are not counting unicode double-bytes twice, which would
# break length calculation e.g. for german umlauts
msg_len = len(msg.decode(_STDOUT_ENCODING))
# build the complete options string and wrap it to width of the
# help
opt_str = ''.join([msg, options])
initial_indent = ' '*(self.help_position + 4)
subsequent_indent = ' '*(self.help_position + 4 + msg_len)
width = self.help_position + self.help_width
opt_str = textwrap.fill(opt_str, width,
initial_indent=initial_indent,
subsequent_indent=subsequent_indent)
result += opt_str + '\n'
return result
示例13: format_description
def format_description(self, description):
if self.preformatted_description:
return description if description else ''
else:
return IndentedHelpFormatter.format_description(self, description)
示例14: format_option
def format_option(self, text):
textwrap.wrap, old = wrap_with_newlines, textwrap.wrap
result = IndentedHelpFormatter.format_option(self, text)
textwrap.wrap = old
return result
示例15: expand_default
def expand_default(self, option):
ret = IndentedHelpFormatter.expand_default(self, option)
if isinstance(option, ExpertOption):
ret = "(Advanced) " + ret
return ret.replace(self.choices_tag, ", ".join(option.choices or []))