本文整理汇总了Python中argparse._CountAction方法的典型用法代码示例。如果您正苦于以下问题:Python argparse._CountAction方法的具体用法?Python argparse._CountAction怎么用?Python argparse._CountAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类argparse
的用法示例。
在下文中一共展示了argparse._CountAction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_test
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _CountAction [as 别名]
def run_test(**options):
"""Runs a molotov test.
"""
parser = _parser()
fields = {}
cli = []
for action in parser._actions:
if action.dest in ("help", "scenario"):
continue
op_str = action.option_strings[0]
fields[action.dest] = op_str, action.const, type(action)
for key, value in options.items():
if key in fields:
opt, const, type_ = fields[key]
is_count = type_ is argparse._CountAction
if const or is_count:
if is_count:
cli += [opt] * value
else:
cli.append(opt)
else:
cli.append(opt)
cli.append(str(value))
cli.append(options.pop("scenario", "loadtest.py"))
args = parser.parse_args(args=cli)
print("Running: molotov %s" % " ".join(cli))
return run(args)
示例2: add_dynamic_attr
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _CountAction [as 别名]
def add_dynamic_attr(cls, klass):
parser = klass.create_parser()
import argparse
for action in parser._actions:
if isinstance(action, argparse._HelpAction):
continue
if isinstance(action, (argparse._StoreTrueAction, argparse._StoreTrueAction)):
cls.locals[action.dest] = [bool]
elif isinstance(action, argparse._CountAction):
cls.locals[action.dest] = [int]
elif isinstance(action, (argparse._AppendAction, argparse._AppendConstAction)):
cls.locals[action.dest] = [list]
else:
cls.locals[action.dest] = [action.type]
示例3: convert_setting_to_command_line_arg
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _CountAction [as 别名]
def convert_setting_to_command_line_arg(self, action, key, value):
args = []
if action is None:
command_line_key = \
self.get_command_line_key_for_unknown_config_file_setting(key)
else:
command_line_key = action.option_strings[-1]
if isinstance(action, argparse._StoreTrueAction):
if value is True:
args.append(command_line_key)
elif isinstance(action, argparse._StoreFalseAction):
if value is False:
args.append(command_line_key)
elif isinstance(action, argparse._StoreConstAction):
if value == action.const:
args.append(command_line_key)
elif isinstance(action, argparse._CountAction):
for _ in range(value):
args.append(command_line_key)
elif action is not None and value == action.default:
pass
elif isinstance(value, list):
args.append(command_line_key)
args.extend([str(e) for e in value])
else:
args.append(command_line_key)
args.append(str(value))
return args