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


Python argparse._属性代码示例

本文整理汇总了Python中argparse._属性的典型用法代码示例。如果您正苦于以下问题:Python argparse._属性的具体用法?Python argparse._怎么用?Python argparse._使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在argparse的用法示例。


在下文中一共展示了argparse._属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def main(argv=None):
    print(""" _____                  ____    ____   ____ 
 |  _ \  ___  ___ ____ | __ )  / ___) / ___)
 | | \ \/ _ \/ _ \  _ \|  _ \ | |  _ | |    
 | |_/ /  __/  __/ |_) | |_) || |_| || |___ 
 |____/ \___|\___| ___/|____/  \____| \____)
=================|_|===== version """ + __version__ + " =====", file=sys.stderr)
    try:
        run(argv)
    except KeyboardInterrupt:
        print(' Interrupted by the user')
        sys.exit(0)
    except Exception as e:
        message = e.args[0] if e.args else ''
        logging.exception(message)
        logging.error('='*80)
        logging.error('DeepBGC failed with %s%s', type(e).__name__, ': {}'.format(message) if message else '')
        if len(e.args) > 1:
            logging.error('='*80)
            for arg in e.args[1:]:
                logging.error(arg)
        logging.error('='*80)
        exit(1) 
开发者ID:Merck,项目名称:deepbgc,代码行数:25,代码来源:main.py

示例2: _parse_handle_files

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def _parse_handle_files(self, ns):
		if not all(ns.files):
			self.error(_("Invalid path") + ": ''")

		if ns.names_file is not None:
			assert ns.names_file0 is None
			names_file = ns.names_file
			delim = names_file.newlines
			assert delim != ""
		elif ns.names_file0 is not None:
			names_file = ns.names_file0
			delim = "\0"
		else:
			names_file = None

		del ns.names_file, ns.names_file0

		if names_file is not None:
			with names_file:
				ns.files.extend(filter(None, getlines(names_file, delim)))

		if not ns.files:
			self.error(_("No files to add to the archive.")) 
开发者ID:davidfoerster,项目名称:aptsources-cleanup,代码行数:25,代码来源:zip.py

示例3: error

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def error(self, message):
        if message != _('too few arguments'):
            super(ArgumentParser, self).error(message) 
开发者ID:calmjs,项目名称:calmjs,代码行数:5,代码来源:argparse.py

示例4: soft_error

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def soft_error(self, message):
        """
        Same as error, without the dying in a fire part.
        """

        self.print_usage(sys.stderr)
        args = {'prog': self.prog, 'message': message}
        self._print_message(
            _('%(prog)s: error: %(message)s\n') % args, sys.stderr) 
开发者ID:calmjs,项目名称:calmjs,代码行数:11,代码来源:argparse.py

示例5: unrecognized_arguments_error

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def unrecognized_arguments_error(self, args):
        self.soft_error(_('unrecognized arguments: %s') % ' '.join(args)) 
开发者ID:calmjs,项目名称:calmjs,代码行数:4,代码来源:argparse.py

示例6: test_error

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def test_error(self):
        stub_stdouts(self)
        parser = ArgumentParser()
        parser.error(_('too few arguments'))
        self.assertEqual('', sys.stdout.getvalue())
        self.assertEqual('', sys.stderr.getvalue()) 
开发者ID:calmjs,项目名称:calmjs,代码行数:8,代码来源:test_argparse.py

示例7: _match_argument

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def _match_argument(self, action, arg_strings_pattern):
        # - https://github.com/streamlink/streamlink/issues/971
        # - https://bugs.python.org/issue9334

        # match the pattern for this action to the arg strings
        nargs_pattern = self._get_nargs_pattern(action)
        match = argparse._re.match(nargs_pattern, arg_strings_pattern)

        # if no match, see if we can emulate optparse and return the
        # required number of arguments regardless of their values
        if match is None:
            nargs = action.nargs if action.nargs is not None else 1
            if isinstance(nargs, numbers.Number) and len(arg_strings_pattern) >= nargs:
                return nargs

        # raise an exception if we weren't able to find a match
        if match is None:
            nargs_errors = {
                None: argparse._('expected one argument'),
                argparse.OPTIONAL: argparse._('expected at most one argument'),
                argparse.ONE_OR_MORE: argparse._('expected at least one argument'),
            }
            default = argparse.ngettext('expected %s argument',
                                        'expected %s arguments',
                                        action.nargs) % action.nargs
            msg = nargs_errors.get(action.nargs, default)
            raise argparse.ArgumentError(action, msg)

        # return the number of arguments matched
        return len(match.group(1)) 
开发者ID:streamlink,项目名称:streamlink,代码行数:32,代码来源:argparser.py

示例8: main

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def main():
    parser = get_parser()
    args = parser.parse_args()

    try:
        command_name = args.command
        if not command_name:
            return parser.print_help()
    except AttributeError:
        parser.error(argparse._('too few arguments'))

    return run_command(parser, args, command_name) 
开发者ID:allegroai,项目名称:trains-agent,代码行数:14,代码来源:__main__.py

示例9: error

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def error(self, message):
        if self._usage_on_error and message == argparse._('too few arguments'):
            self.print_help()
            print()
            self.exit(2, argparse._('%s: error: %s\n') % (self.prog, message))
        super(Parser, self).error(message) 
开发者ID:allegroai,项目名称:trains-agent,代码行数:8,代码来源:base.py

示例10: hyphenate

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def hyphenate(s):
    return s.replace('_', '-') 
开发者ID:allegroai,项目名称:trains-agent,代码行数:4,代码来源:base.py

示例11: parse_args

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def parse_args(self, args=None, namespace=None):
        args, argv = self.parse_known_args(args, namespace)
        if argv:
            message = argparse._('unrecognized arguments: %s') % ' '.join(argv)
            if hasattr(args, 'cmd') and args.cmd:
                # Show help for specific command, catch exit and print message
                try:
                    super(DeepBGCParser, self).parse_args(args=[args.cmd, '--help'])
                except:
                    pass
            self.exit(2, "{}\n{}\n".format("="*80, message))
        return args 
开发者ID:Merck,项目名称:deepbgc,代码行数:14,代码来源:main.py

示例12: load_sources_dir

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def load_sources_dir(sourceslist, dirname):
	if not os.path.isdir(dirname):
		termwrap.stderr().print(': '.join(
			(_('Error'), _('No such directory'), dirname)))
		return 1

	import glob
	sourceslist.list.clear()
	foreach(sourceslist.load,
		glob.iglob(os.path.join(dirname, "**/*.list"), recursive=True))
	return 0 
开发者ID:davidfoerster,项目名称:aptsources-cleanup,代码行数:13,代码来源:__main__.py

示例13: __init__

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def __init__(self, option_strings, version=None, dest=argparse.SUPPRESS,
		default=argparse.SUPPRESS, help=None
	):
		if help is None:
			help = _("Show program's version number and exit.")
		super().__init__(option_strings, dest, 0, help=help)
		self.version = version 
开发者ID:davidfoerster,项目名称:aptsources-cleanup,代码行数:9,代码来源:__main__.py

示例14: _parse_handle_executable

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def _parse_handle_executable(self, ns):
		if ns.executable is NotImplemented:
			refname = "sys.executable"
			self.error(
				_("Unable to determine a default interpreter from the runtime "
					"environment ({:s}={!r}). Please specify it explicitly.")
						.format(refname, eval(refname))) 
开发者ID:davidfoerster,项目名称:aptsources-cleanup,代码行数:9,代码来源:zip.py

示例15: handle_duplicates

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _ [as 别名]
def handle_duplicates(sourceslist, apply_changes=None,
	equivalent_schemes=None
):
	"""Interactive disablement of duplicate source entries"""

	stdout = termwrap.stdout()
	stdout_indent1 = stdout.copy(
		subsequent_indent=stdout.subsequent_indent + ' ' * 4)
	stdout_indent2 = stdout_indent1.copy(
		initial_indent=stdout_indent1.subsequent_indent)

	duplicates = tuple(get_duplicates(
		sourceslist, equivalent_schemes=equivalent_schemes))
	if duplicates:
		for dupe_set in duplicates:
			dupe_set = iter(
				sort_dupe_set_by_scheme_class(equivalent_schemes, dupe_set))
			orig = next(dupe_set)
			for dupe in dupe_set:
				stdout.print(_('Overlapping source entries:'))
				for i, se in enumerate((orig, dupe), 1):
					stdout_indent1.print(
						_("{ordinal:2d}. file {file!r}:")
							.format(ordinal=i, file=se.file))
					stdout_indent2.print(se.line)
				stdout.print(_("I disabled all but the first entry."), end="\n\n")
				dupe.disabled = True

		stdout.print(
			_N('{nduplicates:d} source entry was disabled',
				'{nduplicates:d} source entries were disabled',
				len(duplicates)).format(nduplicates=len(duplicates)) + ':')
		stdout_indent2.initial_indent = stdout_indent2.initial_indent[:-2]
		stdout_indent2.print_all(map(str, itertools.chain(*duplicates)), sep='\n')

		if apply_changes is None:
			stdout.file.write('\n')
			answer = (
				Choices(_U('yes'), _U('no'), default='no')
					.ask(_('Do you want to save these changes?')))
			apply_changes = answer is not None and answer.orig == 'yes'
			if not apply_changes:
				termwrap.stderr().print(_('Aborted.'))
				return 2

		if apply_changes:
			sourceslist.save()

	else:
		stdout.print(_('No duplicate entries were found.'))

	return 0 
开发者ID:davidfoerster,项目名称:aptsources-cleanup,代码行数:54,代码来源:__main__.py


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