本文整理汇总了Python中argparse._StoreFalseAction方法的典型用法代码示例。如果您正苦于以下问题:Python argparse._StoreFalseAction方法的具体用法?Python argparse._StoreFalseAction怎么用?Python argparse._StoreFalseAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类argparse
的用法示例。
在下文中一共展示了argparse._StoreFalseAction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _maybe_apply_flag
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _StoreFalseAction [as 别名]
def _maybe_apply_flag(action, flags):
flag_name = _flag_name(action)
if not flag_name:
log.debug("skipping %s - not a flag option", action)
return
if not isinstance(action, action_types):
log.debug("skipping %s - not an action type", action)
return
flags[flag_name] = attrs = {}
if action.help:
attrs["description"] = action.help
if action.default is not None:
attrs["default"] = _ensure_json_encodable(action.default, flag_name)
if action.choices:
attrs["choices"] = _ensure_json_encodable(action.choices, flag_name)
if action.required:
attrs["required"] = True
if isinstance(action, argparse._StoreTrueAction):
attrs["arg-switch"] = True
elif isinstance(action, argparse._StoreFalseAction):
attrs["arg-switch"] = False
log.debug("added flag %r: %r", flag_name, attrs)
示例2: update_args
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _StoreFalseAction [as 别名]
def update_args(args, arg_parser):
for action in arg_parser._actions:
if isinstance(action, argparse._StoreAction) or isinstance(action, argparse._StoreTrueAction) \
or isinstance(action, argparse._StoreFalseAction):
if not hasattr(args, action.dest):
setattr(args, action.dest, action.default)
示例3: convert_setting_to_command_line_arg
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _StoreFalseAction [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
示例4: format_cli
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _StoreFalseAction [as 别名]
def format_cli (self, report):
usage = self.app.devices[report.fields.get('device')]
task = self.app.actions.commands['add'].usages.commands[usage.name].method.commands[report.fields['use']]
line = [ 'openaps', 'use', usage.name, report.fields.get('use') ]
params = [ ]
config = task.method.from_ini(dict(**report.fields))
for act in task.method.parser._actions:
def accrue (switch):
if switch.startswith('-'):
params.insert(0, switch)
else:
params.append(switch)
# if act.dest in report.fields:
if act.dest in config:
if act.option_strings:
if report.fields.get(act.dest):
if type(act) in [argparse._StoreTrueAction, argparse._StoreFalseAction ]:
expected = act.const
expected = act.default
found = config.get(act.dest)
if type(act) is argparse._StoreFalseAction:
expected = True
found = found
if expected != found:
accrue(act.option_strings[0])
elif type(act) in [argparse._StoreConstAction, ]:
expected = act.default
found = config.get(act.dest)
if expected != found:
accrue(act.option_strings[0])
elif type(act) in [argparse._AppendAction, ]:
if config.get(act.dest) != act.default:
for item in config.get(act.dest):
accrue(act.option_strings[0] + ' ' + item + '')
pass
elif type(act) in [argparse._StoreAction, ]:
if config.get(act.dest) != act.default:
accrue(act.option_strings[0] + ' "' + report.fields.get(act.dest) + '"')
else:
accrue(act.option_strings[0] + ' "' + report.fields.get(act.dest) + '"')
else:
accrue(report.fields.get(act.dest))
return ' '.join(line + params)