Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(20)  |  Call(10)  |  Derive(0)  |  Import(10)
Parse an argument list, given a list of options, with defaults,

Parameter
    str[]   - Indexable sequence of arguments (list or tuple)
    tuple[] - (flag, default, docstring) tuples describing each flag
    int     - Minimum number of non-option arguments
    int     - Maximum number of non-option arguments (no max if None)
    dict    - {flag: value} overrides for default values (default: {})

Return(more...)

        def parseargs(argv, options, minargs=0, maxargs=None, presets={}):
    """Parse an argument list, given a list of options, with defaults,

    Parameter
        str[]   - Indexable sequence of arguments (list or tuple)
        tuple[] - (flag, default, docstring) tuples describing each flag
        int     - Minimum number of non-option arguments
        int     - Maximum number of non-option arguments (no max if None)
        dict    - {flag: value} overrides for default values (default: {})

    Return
        dict    - {flag: value} for each option in input
        str[]   - List of non-option arguments found in argv
    """
    # This is faster than dict comprehensions
    config = {}
    for longname, default, doc in options:
        config[longname] = default

    # presets after defaults but before arguments
    config.update(presets)

    args = []
    while argv:
        arg, argv = argv[0], argv[1:]

        # Non-option
        if arg[:2] != '--':
            args.append(arg)
            continue

        if not argv:
            raise ValueError('parameter passed in at end with no value')
        # Get flag/value
        key, value, argv = arg[2:], argv[0], argv[1:]

        if key not in config:
            raise ValueError('unknown key --' + key)

        # Coerce value type to the type of default arg
        try:
            if isinstance(config[key], (NoneType, str)):
                config[key] = value
            elif isinstance(config[key], (int, long)):
                config[key] = long(value)
            elif isinstance(config[key], float):
                config[key] = float(value)
            else:
                assert 0
        except ValueError as e:
            raise ValueError('wrong format of --%s - %s' % (key, str(e)))

    # Non-optional flags are denoted by a None default argument
    for key, value in config.iteritems():
        if value is None:
            raise ValueError("Option --%s is required." % key)

    # Check number of arguments
    if len(args) < minargs:
        raise ValueError("Must supply at least %d args." % minargs)
    if maxargs is not None and len(args) > maxargs:
        raise ValueError("Too many args - %d max." % maxargs)

    return (config, args)
        


src/f/r/FriendlyTorrent-HEAD/src/tornado/btmakemetafile.py   FriendlyTorrent(Download)
assert version >= '2', "Install Python 2.0 or greater"
from BitTornado.BT1.makemetafile import make_meta_file, defaults, print_announcelist_details
from BitTornado.parseargs import parseargs, formatDefinitions
 
 
 
try:
    config, args = parseargs(argv[1:], defaults, 2, None)
    for file in args[1:]:
        make_meta_file(file, args[0], config, progress = prog)

src/b/i/BitTornado-HEAD/btmakemetafile.py   BitTornado(Download)
from BitTornado.BT1.makemetafile import make_meta_file, defaults, \
    announcelist_details
from BitTornado.parseargs import parseargs, formatDefinitions
 
 
 
    try:
        config, args = parseargs(argv[1:], defaults, 2, None)
        for file in args[1:]:
            make_meta_file(file, args[0], config.copy(), progress=prog)

src/b/i/BitTornado-HEAD/btcompletedir.py   BitTornado(Download)
from BitTornado.BT1.makemetafile import defaults, completedir, \
    announcelist_details
from BitTornado.parseargs import parseargs, formatDefinitions
 
 
 
    try:
        config, args = parseargs(argv[1:], defaults, 2, None)
        for dir in args[1:]:
            completedir(dir, args[0], config)

src/b/i/BitTornado-HEAD/BitTornado/BT1/track.py   BitTornado(Download)
from BitTornado.NetworkAddress import is_ipv4, is_valid_ip, ipv6_to_ipv4, \
    to_ipv4, AddrList
from BitTornado.parseargs import parseargs, formatDefinitions
from BitTornado.RawServer import RawServer, autodetect_socket_style
from BitTornado.HTTPHandler import HTTPHandler, months
        return
    try:
        config, files = parseargs(args, defaults, 0, 0)
    except ValueError as e:
        print 'error: ' + str(e)

src/f/r/FriendlyTorrent-HEAD/src/tornado/BitTornado/BT1/track.py   FriendlyTorrent(Download)
# Written by Bram Cohen
# see LICENSE.txt for license information
 
from BitTornado.parseargs import parseargs, formatDefinitions
from BitTornado.RawServer import RawServer, autodetect_ipv6, autodetect_socket_style
        return
    try:
        config, files = parseargs(args, defaults, 0, 0)
    except ValueError, e:
        print 'error: ' + str(e)

src/o/w/OwnTube-HEAD/videoportal/BitTornadoABC/BitTornado/BT1/track.py   OwnTube(Download)
# Written by Bram Cohen
# see LICENSE.txt for license information
 
from BitTornado.parseargs import parseargs, formatDefinitions
from BitTornado.RawServer import RawServer, autodetect_socket_style
        return
    try:
        config, files = parseargs(args, defaults, 0, 0)
    except ValueError, e:
        print 'error: ' + str(e)

src/b/i/BitTornado-HEAD/btlaunchmanycurses.py   BitTornado(Download)
from BitTornado.launchmanycore import LaunchMany
from BitTornado.download_bt1 import defaults, get_usage
from BitTornado.parseargs import parseargs
from BitTornado import version, report_email
from BitTornado.ConfigDir import ConfigDir
            print get_usage(defaults, 80, configdefaults)
            sys.exit(1)
        config, args = parseargs(sys.argv[1:], defaults, 1, 1, configdefaults)
        if config['save_options']:
            configdir.saveConfig(config)

src/b/i/BitTornado-HEAD/btlaunchmany.py   BitTornado(Download)
from BitTornado.launchmanycore import LaunchMany
from BitTornado.download_bt1 import defaults, get_usage
from BitTornado.parseargs import parseargs
from BitTornado import version, report_email
from BitTornado.ConfigDir import ConfigDir
            print get_usage(defaults, 80, configdefaults)
            sys.exit(1)
        config, args = parseargs(sys.argv[1:], defaults, 1, 1, configdefaults)
        if config['save_options']:
            configdir.saveConfig(config)

src/h/e/Herd-HEAD/BitTornado/BT1/track.py   Herd(Download)
# Written by Bram Cohen
# see LICENSE.txt for license information
 
from BitTornado.parseargs import parseargs, formatDefinitions
from BitTornado.RawServer import RawServer, autodetect_ipv6, autodetect_socket_style
        return
    try:
        config, files = parseargs(args, defaults, 0, 0)
    except ValueError, e:
        print 'error: ' + str(e)

src/s/w/swarm-HEAD/BitTornado/BT1/track.py   swarm(Download)
# Written by Bram Cohen
# see LICENSE.txt for license information
 
from BitTornado.parseargs import parseargs, formatDefinitions
from BitTornado.RawServer import RawServer, autodetect_ipv6, autodetect_socket_style
        return
    try:
        config, files = parseargs(args, defaults, 0, 0)
    except ValueError, e:
        print 'error: ' + str(e)