Command line parser.
509811
def _parse_args():
    """"""
    parser = argparse.ArgumentParser(description='{} service.'.
                                     format(__service_id__))
    parser.add_argument('--random_errors', action='store_true',
                        help='Enable random errors')
    parser.add_argument('-v', action='store_true',
                        help='Verbose mode (enable debug printing)')
    parser.add_argument('-vv', action='store_true', help='Extra verbose mode')
    args = parser.parse_args()

    if args.vv:
        init_logger(log_level='DEBUG', show_log_origin=True)
    elif args.v:
        init_logger(logger_name='sip.ec.master_controller', log_level='DEBUG')
    else:
        init_logger(log_level='INFO')

    return args
1156612
def parser(scope, usage=''):
    
    subcmds = []
    for cmd in commands(scope):
        subcmds.append(cmd.usage())

    if subcmds:
        subcmds.sort()
        usage += '\n\nSub-Commands:\n  '
        usage += '\n  '.join(subcmds)

    parse = PARSER_CLASS(usage=usage)
    parse.prog = PROGRAM_NAME
    return parse
578394
def main():
    """"""
    parser = OptionParser()
    parser.add_option('-a', '--hostname',
                      help='ClamAV source server hostname',
                      dest='hostname',
                      type='str',
                      default='db.de.clamav.net')
    parser.add_option('-r', '--text-record',
                      help='ClamAV Updates TXT record',
                      dest='txtrecord',
                      type='str',
                      default='current.cvd.clamav.net')
    parser.add_option('-w', '--work-directory',
                      help='Working directory',
                      dest='workdir',
                      type='str',
                      default='/var/spool/clamav-mirror')
    parser.add_option('-d', '--mirror-directory',
                      help='The mirror directory',
                      dest='mirrordir',
                      type='str',
                      default='/srv/www/clamav')
    parser.add_option('-u', '--user',
                      help='Change file owner to this user',
                      dest='user',
                      type='str',
                      default='nginx')
    parser.add_option('-g', '--group',
                      help='Change file group to this group',
                      dest='group',
                      type='str',
                      default='nginx')
    parser.add_option('-l', '--locks-directory',
                      help='Lock files directory',
                      dest='lockdir',
                      type='str',
                      default='/var/lock/subsys')
    parser.add_option('-v', '--verbose',
                      help='Display verbose output',
                      dest='verbose',
                      action='store_true',
                      default=False)
    options, _ = parser.parse_args()
    try:
        lockfile = os.path.join(options.lockdir, 'clamavmirror')
        with open(lockfile, 'w+') as lock:
            fcntl.lockf(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
            work(options)
    except IOError:
        info("=> Another instance is already running")
        sys.exit(254)
1034449
def parser():
    """"""
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('-r', '--read-only', action='store_true',
                        help='open notmuch database in read-only mode')
    parser.add_argument('-c', '--config', metavar='FILENAME',
                        action=cargparse.ValidatedStoreAction,
                        validator=cargparse.require_file,
                        help='configuration file')
    parser.add_argument('-n', '--notmuch-config', metavar='FILENAME',
                        default=os.environ.get(
                            'NOTMUCH_CONFIG',
                            os.path.expanduser('~/.notmuch-config')),
                        action=cargparse.ValidatedStoreAction,
                        validator=cargparse.require_file,
                        help='notmuch configuration file')
    parser.add_argument('-C', '--colour-mode', metavar='COLOURS',
                        choices=(1, 16, 256), type=int,
                        help='number of colours to use')
    parser.add_argument('-p', '--mailindex-path', metavar='PATH',
                        action=cargparse.ValidatedStoreAction,
                        validator=cargparse.require_dir,
                        help='path to notmuch index')
    parser.add_argument('-d', '--debug-level', metavar='LEVEL', default='info',
                        choices=('debug', 'info', 'warning', 'error'),
                        help='debug level [default: %(default)s]')
    parser.add_argument('-l', '--logfile', metavar='FILENAME',
                        default='/dev/null',
                        action=cargparse.ValidatedStoreAction,
                        validator=cargparse.optional_file_like,
                        help='log file [default: %(default)s]')
    parser.add_argument('-h', '--help', action='help',
                        help='display this help and exit')
    parser.add_argument('-v', '--version', action='version',
                        version=alot.__version__,
                        help='output version information and exit')
    # We will handle the subcommands in a separate run of argparse as argparse
    # does not support optional subcommands until now.
    parser.add_argument('command', nargs=argparse.REMAINDER,
                        help='possible subcommands are {}'.format(
                            ', '.join(_SUBCOMMANDS)))
    options = parser.parse_args()

    if options.command:
        # We have a command after the initial options so we also parse that.
        # But we just use the parser that is already defined for the internal
        # command that will back this subcommand.
        parser = argparse.ArgumentParser()
        subparsers = parser.add_subparsers(dest='subcommand')
        for subcommand in _SUBCOMMANDS:
            subparsers.add_parser(subcommand,
                                  parents=[COMMANDS['global'][subcommand][1]])
        command = parser.parse_args(options.command)
    else:
        command = None

    return options, command
1024133
def main(argv=None):
    """"""

    parser = argparse.ArgumentParser(
        description='Commands as arguments'
    )
    command_help = 'optional command to run, if no command given, enter an interactive shell'
    parser.add_argument('command', nargs='?',
                        help=command_help)
    arg_help = 'optional arguments for command'
    parser.add_argument('command_args', nargs=argparse.REMAINDER,
                        help=arg_help)

    args = parser.parse_args(argv)

    c = CmdLineApp()

    if args.command:
        # we have a command, run it and then exit
        c.onecmd_plus_hooks('{} {}'.format(args.command, ' '.join(args.command_args)))
    else:
        # we have no command, drop into interactive mode
        c.cmdloop()
529143
def main():
    """"""
    parser = get_parser()
    args = parser.parse_args()
    if hasattr(args, 'func') and args.func:
        args.func(args)
    else:
        parser.print_help()
1268326
def main():
    """"""
    from argparse import ArgumentParser
    description = "Download a bunch of thumbnails from Wikimedia Commons"
    parser = ArgumentParser(description=description)
    source_group = parser.add_mutually_exclusive_group()
    source_group.add_argument("-l", "--list", metavar="LIST",
                              dest="file_list",
                              type=argparse.FileType('r'),
                              help='A list of files <filename,width>')
    source_group.add_argument("-c", "--category", metavar="CATEGORY",
                              dest="category_name",
                              type=str,
                              help='A category name (without prefix)')
    parser.add_argument("files", nargs='*',
                        metavar="FILES",
                        help='A list of filenames')
    parser.add_argument("-o", "--output", metavar="FOLDER",
                        dest="output_path",
                        action=Folder,
                        default=os.getcwd(),
                        help='The directory to download the files to')
    parser.add_argument("-w", "--width",
                        dest="width",
                        type=int,
                        default=100,
                        help='The width of the thumbnail (default: 100)')
    verbosity_group = parser.add_mutually_exclusive_group()
    verbosity_group.add_argument("-v",
                                 action="count",
                                 dest="verbose",
                                 default=1,
                                 help="Verbosity level. -v for DEBUG")
    verbosity_group.add_argument("-q", "--quiet",
                                 action="store_const",
                                 dest="verbose",
                                 const=0,
                                 help="To silence the INFO messages")
    args = parser.parse_args()
    logging_map = {0: logging.WARNING,
                   1: logging.INFO,
                   2: logging.DEBUG}
    logging_level = logging_map.get(args.verbose, logging.DEBUG)
    logging.basicConfig(level=logging_level)
    logging.info("Starting")

    if args.file_list:
        download_from_file_list(args.file_list, args.output_path)
    elif args.category_name:
        download_from_category(args.category_name, args.output_path, args.width)
    elif args.files:
        download_from_files(args.files, args.output_path, args.width)
    else:
        parser.print_help()
1016343
def parse(self, line=None):
        """"""
        args = self.parser.parse_args(args=line)
        return args.func(args)
603255
def main():
    """"""
    actions = []
    try:
        # Parse the command line arguments.
        options, arguments = getopt.getopt(sys.argv[1:], 'cdh', [
            'convert', 'to-html', 'demo', 'help',
        ])
        # Map command line options to actions.
        for option, value in options:
            if option in ('-c', '--convert', '--to-html'):
                actions.append(functools.partial(convert_command_output, *arguments))
                arguments = []
            elif option in ('-d', '--demo'):
                actions.append(demonstrate_colored_logging)
            elif option in ('-h', '--help'):
                usage(__doc__)
                return
            else:
                assert False, "Programming error: Unhandled option!"
        if not actions:
            usage(__doc__)
            return
    except Exception as e:
        warning("Error: %s", e)
        sys.exit(1)
    for function in actions:
        function()
570701
def parse(args):
    """"""

    import argparse

    parser = argparse.ArgumentParser(
        add_help=False,
        description="Remove spam and advertising from subtitle files.",
        usage="%(prog)s [OPTION]... TARGET...")
    parser.add_argument(
        "-a", "--aeidon",
        action="store_true",
        dest="aeidon",
        help="use python3-aeidon to process subtitles")
    parser.add_argument(
        "-f", "--file",
        action="append",
        dest="pattern_files",
        help="obtain matches from FILE")
    parser.add_argument(
        "--fix",
        action="store_true",
        dest="fix",
        help="repair potentially damaged subtitle files with aeidon")
    parser.add_argument(
        "-g", "--gui",
        action="store_true",
        dest="gui",
        help="indicate use from a GUI")
    parser.add_argument(
        "-h", "--help",
        action="help",
        help=argparse.SUPPRESS)
    parser.add_argument(
        "-r", "--regex",
        action="store_true",
        dest="regex",
        help="perform regex matching")
    parser.add_argument(
        "-s", "--case-sensitive",
        action="store_true",
        default=False,
        dest="case_sensitive",
        help="match case-sensitively")
    parser.add_argument(
        "-y", "--yes",
        action="store_true",
        dest="autoyes",
        help="automatic yes to prompts")
    parser.add_argument(
        "--version",
        action="version",
        version='%(prog)s ' + __version__)
    parser.add_argument(
        dest="targets",
        help=argparse.SUPPRESS,
        nargs="*")

    options = parser.parse_args(args)
    arguments = options.targets

    return options, arguments
1323342
def main():
    """"""

    # Quit when interrupted
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    # Arguments:
    # --separator STRING/REGEX - how to split a row into cells (only relevant for CSV parser)
    # --flatten - flatten item hashes. {'a':{'b':'c'}} --> {'a_b':'c'}
    import argparse
    parser = argparse.ArgumentParser(description='View tabulated data via GUI')
    parser.add_argument('-p','--parser',type=str, default='autosplit',help='Type of parser to use') #TODO add possible parsers
    parser.add_argument('--headers',type=str, help='Headers are this comma-delimited names instead of ones supplied in file. Use colons to specify types, like "colname:int"')
    parser.add_argument('--filter',type=str, help='Pre-populate filter box')
    parser.add_argument('-s', '--separator', help='How to seperate columns. Applies only to some parsers')
    parser.add_argument('files', nargs='*', help='Files to show. Each file opens a new window')
    args = parser.parse_args()

    GObject.threads_init()

    default_config = {'format': args.parser}
    if args.filter:
        default_config['filter']=args.filter
    if args.separator:
        default_config['separator']=args.separator
    if args.headers:
        default_config['headers']=map(lambda s: s.strip(),args.headers.split(','))
    inputs = [ (open(f,'r'),default_config) for f in args.files ]
    # Add stdin as input, if it's not a tty
    if not sys.stdin.isatty():
        inputs.append((sys.stdin, default_config))

    global windows
    windows = [Window(i[0],i[1]) for i in inputs]
    for win in windows:
      win.start_read()
      win.connect("destroy",window_closed)
    if windows:
        Gtk.main()
    else:
        print 'No input supplied so no windows are created'
223080
def main():
    """"""
    parser = get_args_parser()
    args = parser.parse_args()
    config = Config.from_parse_args(args)
    migrate(config)
1057468
def main():
    """"""
    import sys

    output = []
    line = sys.stdin.readline()

    while line:
        line = line.strip("\n")
        output.append(transform(line))

        line = sys.stdin.readline()
    output.reverse()
    print("\n".join(output))
84063
def _parse_arguments():
    """"""
    parser = argparse.ArgumentParser(description="CMake AST Dumper")
    parser.add_argument("filename", nargs=1, metavar=("FILE"),
                        help="read FILE")
    return parser.parse_args()
48024
def main(manual_args=None):
    """"""
    parser = argparse.ArgumentParser(description=main.__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.set_defaults(func=parser.print_help)
    add_debug(parser)
    parser.add_argument(
        '-s',
        '--short-log',
        action='store_const',
        const=SHORT_LOGGING_FORMAT,
        default=LOGGING_FORMAT,
        help='Truncated logging format')
    parser.add_argument('-v', '--version', action='store_true', help=print_version.__doc__)

    subparsers = parser.add_subparsers(title='Commands', description='Available activies')

    add_infra(subparsers)
    add_pipeline(subparsers)
    add_rebuild(subparsers)
    add_autoscaling(subparsers)
    add_validate(subparsers)

    CliArgs = collections.namedtuple('CliArgs', ['parsed', 'extra'])

    parsed, extra = parser.parse_known_args(args=manual_args)
    args = CliArgs(parsed, extra)

    logging.basicConfig(format=args.parsed.short_log)

    package, *_ = __package__.split('.')
    logging.getLogger(package).setLevel(args.parsed.debug)

    LOG.debug('Arguments: %s', args)

    if args.parsed.version:
        args.parsed.func = print_version

    try:
        args.parsed.func(args)
    except (AttributeError, TypeError):
        args.parsed.func()
976157
def get_parser():
    """"""

    # initialize the parser
    parser = argparse.ArgumentParser(
        description=(
            'Command line tool for extracting text from any document. '
        ) % locals(),
    )

    # define the command line options here
    parser.add_argument(
        'filename', help='Filename to extract text.',
    ).completer = argcomplete.completers.FilesCompleter
    parser.add_argument(
        '-e', '--encoding', type=str, default=DEFAULT_ENCODING,
        choices=_get_available_encodings(),
        help='Specify the encoding of the output.',
    )
    parser.add_argument(
        '--extension', type=str, default=None,
        choices=_get_available_extensions(),
        help='Specify the extension of the file.',
    )
    parser.add_argument(
        '-m', '--method', default='',
        help='Specify a method of extraction for formats that support it',
    )
    parser.add_argument(
        '-o', '--output', type=FileType('wb'), default='-',
        help='Output raw text in this file',
    )
    parser.add_argument(
        '-O', '--option', type=str, action=AddToNamespaceAction,
        help=(
            'Add arbitrary options to various parsers of the form '
            'KEYWORD=VALUE. A full list of available KEYWORD options is '
            'available at http://bit.ly/textract-options'
        ),
    )
    parser.add_argument(
        '-v', '--version', action='version', version='%(prog)s '+VERSION,
    )

    # enable autocompletion with argcomplete
    argcomplete.autocomplete(parser)

    return parser
610956
def main(args=None):
	""""""
	import sys, pprint
	from argparse import ArgumentParser, FileType
	parser = ArgumentParser(description=main.__doc__)
	parser.add_argument('infile',  nargs='?', type=FileType('rb'), default=sys.stdin.buffer,
		help='bencoded file (e.g. torrent) [Default: stdin]')
	parser.add_argument('outfile', nargs='?', type=FileType('w'), default=sys.stdout,
		help='python-syntax serialization [Default: stdout]')
	args = parser.parse_args(args)
	
	data = bdecode(args.infile)
	pprint.pprint(data, stream=args.outfile)