当前位置: 首页>>代码示例>>Python>>正文


Python optparse.IndentedHelpFormatter类代码示例

本文整理汇总了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')
开发者ID:roman-kutlak,项目名称:nlglib,代码行数:32,代码来源:qm.py

示例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)
开发者ID:JohnReid,项目名称:bioinf-utilities,代码行数:8,代码来源:deoptparse.py

示例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
开发者ID:jnpkrn,项目名称:clufter,代码行数:9,代码来源:main.py

示例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)
开发者ID:asntech,项目名称:rSeqPipeline,代码行数:10,代码来源:misc.py

示例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()
开发者ID:pombredanne,项目名称:anvil,代码行数:7,代码来源:opts.py

示例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")
     )
开发者ID:gravitationalarry,项目名称:bayestar-localization,代码行数:7,代码来源:command.py

示例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)
开发者ID:BackupTheBerlios,项目名称:tel-svn,代码行数:12,代码来源:cmdoptparse.py

示例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()
开发者ID:AsherBond,项目名称:anvil,代码行数:13,代码来源:opts.py

示例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)
开发者ID:rvalles,项目名称:vmpuppeteer,代码行数:14,代码来源:PosOptionParser.py

示例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
开发者ID:BackupTheBerlios,项目名称:tel-svn,代码行数:18,代码来源:cmdoptparse.py

示例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
开发者ID:ashmew2,项目名称:gentoo-mirrorselect,代码行数:20,代码来源:output.py

示例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
开发者ID:BackupTheBerlios,项目名称:tel-svn,代码行数:22,代码来源:cmdoptparse.py

示例13: format_description

 def format_description(self, description):
     if self.preformatted_description:
         return description if description else ''
     else:
         return IndentedHelpFormatter.format_description(self, description)
开发者ID:gvalkov,项目名称:optparse-pretty,代码行数:5,代码来源:optparse_mooi.py

示例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
开发者ID:mcevoyandy,项目名称:neptune,代码行数:5,代码来源:cli.py

示例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 []))
开发者ID:jnpkrn,项目名称:clufter,代码行数:5,代码来源:main.py


注:本文中的optparse.IndentedHelpFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。