本文整理汇总了Python中optparse.Option方法的典型用法代码示例。如果您正苦于以下问题:Python optparse.Option方法的具体用法?Python optparse.Option怎么用?Python optparse.Option使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optparse
的用法示例。
在下文中一共展示了optparse.Option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def process(self, opt, value, values, parser):
"""
Call the validator function on applicable settings and
evaluate the 'overrides' option.
Extends `optparse.Option.process`.
"""
result = optparse.Option.process(self, opt, value, values, parser)
setting = self.dest
if setting:
if self.validator:
value = getattr(values, setting)
try:
new_value = self.validator(setting, value, parser)
except Exception as error:
raise optparse.OptionValueError(
'Error in option "%s":\n %s'
% (opt, ErrorString(error)))
setattr(values, setting, new_value)
if self.overrides:
setattr(values, self.overrides, None)
return result
示例2: process
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def process(self, opt, value, values, parser):
"""
Call the validator function on applicable settings and
evaluate the 'overrides' option.
Extends `optparse.Option.process`.
"""
result = optparse.Option.process(self, opt, value, values, parser)
setting = self.dest
if setting:
if self.validator:
value = getattr(values, setting)
try:
new_value = self.validator(setting, value, parser)
except Exception, error:
raise (optparse.OptionValueError(
'Error in option "%s":\n %s'
% (opt, ErrorString(error))),
None, sys.exc_info()[2])
setattr(values, setting, new_value)
if self.overrides:
setattr(values, self.overrides, None)
示例3: __init__
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def __init__(self, *opts, **attrs):
optparse.Option.__init__(self, *opts, **attrs)
if hasattr(self, "hide") and self.hide:
self.help = optparse.SUPPRESS_HELP
示例4: reset_parsers
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def reset_parsers(self, usage='', version=None):
# configuration file parser
self.cfgfile_parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
# command line parser
self.cmdline_parser = OptionParser(Option, usage=usage, version=version)
self.cmdline_parser.options_manager = self
self._optik_option_attrs = set(self.cmdline_parser.option_class.ATTRS)
示例5: exists_action
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def exists_action():
return Option(
# Option when path already exist
'--exists-action',
dest='exists_action',
type='choice',
choices=['s', 'i', 'w', 'b', 'a'],
default=[],
action='append',
metavar='action',
help="Default action when a path already exists: "
"(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.")
示例6: extra_index_url
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def extra_index_url():
return Option(
'--extra-index-url',
dest='extra_index_urls',
metavar='URL',
action='append',
default=[],
help="Extra URLs of package indexes to use in addition to "
"--index-url. Should follow the same rules as "
"--index-url."
)
示例7: find_links
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def find_links():
return Option(
'-f', '--find-links',
dest='find_links',
action='append',
default=[],
metavar='url',
help="If a url or path to an html file, then parse for links to "
"archives. If a local path or file:// url that's a directory, "
"then look for archives in the directory listing.")
示例8: allow_external
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def allow_external():
return Option(
"--allow-external",
dest="allow_external",
action="append",
default=[],
metavar="PACKAGE",
help=SUPPRESS_HELP,
)
示例9: trusted_host
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def trusted_host():
return Option(
"--trusted-host",
dest="trusted_hosts",
action="append",
metavar="HOSTNAME",
default=[],
help="Mark this host as trusted, even though it does not have valid "
"or any HTTPS.",
)
# Remove after 7.0
示例10: constraints
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def constraints():
return Option(
'-c', '--constraint',
dest='constraints',
action='append',
default=[],
metavar='file',
help='Constrain versions using the given constraints file. '
'This option can be used multiple times.')
示例11: requirements
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def requirements():
return Option(
'-r', '--requirement',
dest='requirements',
action='append',
default=[],
metavar='file',
help='Install from the given requirements file. '
'This option can be used multiple times.')
示例12: editable
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def editable():
return Option(
'-e', '--editable',
dest='editables',
action='append',
default=[],
metavar='path/url',
help=('Install a project in editable mode (i.e. setuptools '
'"develop mode") from a local project path or a VCS url.'),
)
示例13: no_binary
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def no_binary():
return Option(
"--no-binary", dest="format_control", action="callback",
callback=_handle_no_binary, type="str",
default=FormatControl(set(), set()),
help="Do not use binary packages. Can be supplied multiple times, and "
"each time adds to the existing value. Accepts either :all: to "
"disable all binary packages, :none: to empty the set, or one or "
"more package names with commas between them. Note that some "
"packages are tricky to compile and may fail to install when "
"this option is used on them.")
示例14: only_binary
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def only_binary():
return Option(
"--only-binary", dest="format_control", action="callback",
callback=_handle_only_binary, type="str",
default=FormatControl(set(), set()),
help="Do not use source packages. Can be supplied multiple times, and "
"each time adds to the existing value. Accepts either :all: to "
"disable all source packages, :none: to empty the set, or one or "
"more package names with commas between them. Packages without "
"binary distributions will fail to install when this option is "
"used on them.")
示例15: exists_action
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import Option [as 别名]
def exists_action():
return Option(
# Option when path already exist
'--exists-action',
dest='exists_action',
type='choice',
choices=['s', 'i', 'w', 'b'],
default=[],
action='append',
metavar='action',
help="Default action when a path already exists: "
"(s)witch, (i)gnore, (w)ipe, (b)ackup.")