Python argparse._CountAction() Examples

The following are code examples for showing how to use argparse._CountAction(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: django-corenlp   Author: arunchaganty   File: config.py    (license) View Source Project 5 votes vote down vote up
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 
Example 2
Project: django-corenlp   Author: arunchaganty   File: config.py    (license) View Source Project 5 votes vote down vote up
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