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


Python optparse.OptionParser方法代码示例

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


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

示例1: main

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def main():
    e_parser = OptionParser()
    e_parser.add_option("--e_mode",
                        dest="e_mode",
                        type="choice",
                        choices=["convert_conll_to_fe", "count_frame_elements", "compare_fefiles"],
                        default="convert_conll_to_fe")
    e_parser.add_option("--conll_file", type="str", metavar="FILE")
    e_parser.add_option("--fe_file", type="str", metavar="FILE")
    e_parser.add_option("--fe_file_other", type="str", metavar="FILE")
    e_options, _ = e_parser.parse_args()

    if e_options.e_mode == "convert_conll_to_fe":
        assert e_options.conll_file and e_options.fe_file
        convert_conll_to_frame_elements(e_options.conll_file, e_options.fe_file)
    elif e_options.e_mode == "count_frame_elements":
        assert e_options.fe_file
        count_frame_elements(e_options.fe_file)
    elif e_options.e_mode == "compare_fefiles":
        assert e_options.fe_file and e_options.fe_file_other
        compare_fefiles(e_options.fe_file, e_options.fe_file_other) 
开发者ID:swabhs,项目名称:open-sesame,代码行数:23,代码来源:semafor_evaluation.py

示例2: ParseOptions

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def ParseOptions(argv):
  """Parse command-line options."""
  parser = optparse.OptionParser(usage='%prog [options]')
  parser.add_option('-D', '--debug', action='store_true', default=False)
  parser.add_option('-F', '--formatted', action='store_true', default=False,
                    help=('Output experiments as one "experiment,status" '
                          'per line'))
  parser.add_option(
      '-e', '--enable', action='store', dest='manually_enable',
      help='Comma-delimited list of experiments to manually enable.')
  parser.add_option(
      '-d', '--disable', action='store', dest='manually_disable',
      help='Comma-delimited list of experiments to manually enable.')
  parser.add_option(
      '-r', '--recommended', action='store', dest='recommended',
      help='Comma-delimited list of experiments to no longer manually manage.')
  opts, args = parser.parse_args(argv)
  return opts, args 
开发者ID:google,项目名称:macops,代码行数:20,代码来源:experiments.py

示例3: main

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def main():
    parser = OptionParser(
        usage="%s WHEEL1 WHEEL2\n\n" % sys.argv[0] + __doc__,
        version="%prog " + __version__)
    parser.add_option(
        Option("-w", "--wheel-dir",
               action="store", type='string',
               help="Directory to store delocated wheels (default is to "
               "overwrite WHEEL1 input)"))
    parser.add_option(
        Option("-v", "--verbose",
               action="store_true",
               help="Show libraries copied during fix"))
    (opts, wheels) = parser.parse_args()
    if len(wheels) != 2:
        parser.print_help()
        sys.exit(1)
    wheel1, wheel2 = [abspath(expanduser(wheel)) for wheel in wheels]
    if opts.wheel_dir is None:
        out_wheel = wheel1
    else:
        out_wheel = pjoin(abspath(expanduser(opts.wheel_dir)),
                          basename(wheel1))
    fuse_wheels(wheel1, wheel2, out_wheel) 
开发者ID:matthew-brett,项目名称:delocate,代码行数:26,代码来源:delocate_fuse.py

示例4: get_cli_config_vars

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def get_cli_config_vars():
    """ get CLI options """
    usage = "Usage: %prog [options]"
    parser = OptionParser(usage=usage)
    parser.add_option("-v", "--verbose",
                      action="store_true", dest="verbose", help="Enable verbose logging")
    parser.add_option("-t", "--testing",
                      action="store_true", dest="testing", help="Set to testing mode (do not send data)."
                                                                " Automatically turns on verbose logging")
    (options, args) = parser.parse_args()

    config_vars = dict()
    config_vars['testing'] = False
    if options.testing:
        config_vars['testing'] = True
    config_vars['logLevel'] = logging.INFO
    if options.verbose or options.testing:
        config_vars['logLevel'] = logging.DEBUG

    return config_vars 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:22,代码来源:getmetrics_zipkin.py

示例5: main

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def main():
    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option(
        '-j',
        '--json',
        metavar='FILE',
        nargs=1,
        help='Save output as JSON into file, pass in ' "'-' to output to stdout",
    )

    (options, args) = parser.parse_args()

    if options.json == '-':
        options.json = True

    show_versions(as_json=options.json)

    return 0 
开发者ID:NCAR,项目名称:esmlab,代码行数:22,代码来源:print_versions.py

示例6: _getOptParser

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def _getOptParser(self):
        import optparse
        parser = optparse.OptionParser()
        parser.prog = self.progName
        parser.add_option('-v', '--verbose', dest='verbose', default=False,
                          help='Verbose output', action='store_true')
        parser.add_option('-q', '--quiet', dest='quiet', default=False,
                          help='Quiet output', action='store_true')

        if self.failfast != False:
            parser.add_option('-f', '--failfast', dest='failfast', default=False,
                              help='Stop on first fail or error',
                              action='store_true')
        if self.catchbreak != False:
            parser.add_option('-c', '--catch', dest='catchbreak', default=False,
                              help='Catch ctrl-C and display results so far',
                              action='store_true')
        if self.buffer != False:
            parser.add_option('-b', '--buffer', dest='buffer', default=False,
                              help='Buffer stdout and stderr during tests',
                              action='store_true')
        return parser 
开发者ID:war-and-code,项目名称:jawfish,代码行数:24,代码来源:main.py

示例7: main

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def main():
    parser = optparse.OptionParser(version = "%%prog %s" % VERSION)
    parser.add_option("--file", dest="file", help="FILE to test")
    parser.add_option("--function", dest="func", help="FUNCTION to test")
    parser.add_option("--file-at-a-time", action="store_true", dest="faat",
        default = False, help="run tests from each file in the same"
        " process (faster, but coarser if tests fail)")

    (opts, args) = parser.parse_args()

    if opts.file:
        return doTest(opts)
    else:
        return doTests(opts)

# returns a list of all function names from the given file that start with
# "test". 
开发者ID:trelby,项目名称:trelby,代码行数:19,代码来源:do_tests.py

示例8: __init__

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def __init__(self, sslyze_version: str) -> None:
        """Generate SSLyze's command line parser.
        """
        self._parser = OptionParser(version=sslyze_version, usage=self.SSLYZE_USAGE)

        # Add generic command line options to the parser
        self._add_default_options()

        # Add plugin .ie scan command options to the parser
        scan_commands_group = OptionGroup(self._parser, "Scan commands", "")
        for option in self._get_plugin_scan_commands():
            scan_commands_group.add_option(f"--{option.option}", help=option.help, action=option.action)
        self._parser.add_option_group(scan_commands_group)

        # Add the --regular command line parameter as a shortcut if possible
        self._parser.add_option(
            "--regular",
            action="store_true",
            dest=None,
            help=f"Regular HTTPS scan; shortcut for --{'--'.join(self.REGULAR_CMD)}",
        ) 
开发者ID:nabla-c0d3,项目名称:sslyze,代码行数:23,代码来源:command_line_parser.py

示例9: action_runserver

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def action_runserver(name, args):
    """run a llvmlab instance"""

    import llvmlab
    from optparse import OptionParser, OptionGroup
    parser = OptionParser("%%prog %s [options]" % name)
    parser.add_option("", "--reloader", dest="reloader", default=False,
                      action="store_true", help="use WSGI reload monitor")
    parser.add_option("", "--debugger", dest="debugger", default=False,
                      action="store_true", help="use WSGI debugger")
    parser.add_option("", "--profiler", dest="profiler", default=False,
                      action="store_true", help="enable WSGI profiler")
    (opts, args) = parser.parse_args(args)

    if len(args) != 0:
        parser.error("invalid number of arguments")

    app = llvmlab.ui.app.App.create_standalone()
    if opts.debugger:
        app.debug = True
    if opts.profiler:
        app.wsgi_app = werkzeug.contrib.profiler.ProfilerMiddleware(
            app.wsgi_app, stream = open('profiler.log', 'w'))
    app.run(use_reloader = opts.reloader,
            use_debugger = opts.debugger) 
开发者ID:llvm,项目名称:llvm-zorg,代码行数:27,代码来源:main.py

示例10: _parse_args

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def _parse_args():
    """
    Parse the command line for options
    """
    parser = optparse.OptionParser()
    parser.add_option(
        '--user', dest='user_install', action='store_true', default=False,
        help='install in user site package (requires Python 2.6 or later)')
    parser.add_option(
        '--download-base', dest='download_base', metavar="URL",
        default=DEFAULT_URL,
        help='alternative URL from where to download the setuptools package')
    parser.add_option(
        '--insecure', dest='downloader_factory', action='store_const',
        const=lambda: download_file_insecure, default=get_best_downloader,
        help='Use internal, non-validating downloader'
    )
    parser.add_option(
        '--version', help="Specify which version to download",
        default=DEFAULT_VERSION,
    )
    options, args = parser.parse_args()
    # positional arguments are ignored
    return options 
开发者ID:fangpenlin,项目名称:bugbuzz-python,代码行数:26,代码来源:ez_setup.py

示例11: get_option_parser

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def get_option_parser():
    parser = OptionParser(usage='usage: %prog [options] database_name')
    ao = parser.add_option
    ao('-H', '--host', dest='host')
    ao('-p', '--port', dest='port', type='int')
    ao('-u', '--user', dest='user')
    ao('-P', '--password', dest='password', action='store_true')
    engines = sorted(DATABASE_MAP)
    ao('-e', '--engine', dest='engine', default='postgresql', choices=engines,
       help=('Database type, e.g. sqlite, mysql or postgresql. Default '
             'is "postgresql".'))
    ao('-s', '--schema', dest='schema')
    ao('-t', '--tables', dest='tables',
       help=('Only generate the specified tables. Multiple table names should '
             'be separated by commas.'))
    ao('-i', '--info', dest='info', action='store_true',
       help=('Add database information and other metadata to top of the '
             'generated file.'))
    ao('-o', '--preserve-order', action='store_true', dest='preserve_order',
       help='Model definition column ordering matches source table.')
    return parser 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:23,代码来源:pwiz.py

示例12: main

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def main():
    usage = """usage: %prog [options] arg1=value, arg2=value

    Enables sharding on the specified arctic library.
    """
    setup_logging()

    parser = optparse.OptionParser(usage=usage)
    parser.add_option("--host", default='localhost', help="Hostname, or clustername. Default: localhost")
    parser.add_option("--library", help="The name of the library. e.g. 'arctic_jblackburn.lib'")

    (opts, _) = parser.parse_args()

    if not opts.library or '.' not in opts.library:
        parser.error('must specify the full path of the library e.g. arctic_jblackburn.lib!')

    print("Enabling-sharding: %s on mongo %s" % (opts.library, opts.host))

    c = pymongo.MongoClient(get_mongodb_uri(opts.host))
    credentials = get_auth(opts.host, 'admin', 'admin')
    if credentials:
        authenticate(c.admin, credentials.user, credentials.password)
    store = Arctic(c)
    enable_sharding(store, opts.library) 
开发者ID:man-group,项目名称:arctic,代码行数:26,代码来源:arctic_enable_sharding.py

示例13: main

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def main():
    usage = """usage: %prog [options] [prefix ...]

    Lists the libraries available in a user's database.   If any prefix parameters
    are given, list only libraries with names that start with one of the prefixes.

    Example:
        %prog --host=hostname rgautier
    """
    setup_logging()

    parser = optparse.OptionParser(usage=usage)
    parser.add_option("--host", default='localhost', help="Hostname, or clustername. Default: localhost")

    (opts, args) = parser.parse_args()

    store = Arctic(opts.host)
    for name in sorted(store.list_libraries()):
        if (not args) or [n for n in args if name.startswith(n)]:
            print(name) 
开发者ID:man-group,项目名称:arctic,代码行数:22,代码来源:arctic_list_libraries.py

示例14: _expand_default

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def _expand_default(self, option):
    """Patch OptionParser.expand_default with custom behaviour

    This will handle defaults to avoid overriding values in the
    configuration file.
    """
    if self.parser is None or not self.default_tag:
        return option.help
    optname = option._long_opts[0][2:]
    try:
        provider = self.parser.options_manager._all_options[optname]
    except KeyError:
        value = None
    else:
        optdict = provider.get_option_def(optname)
        optname = provider.option_attrname(optname, optdict)
        value = getattr(provider.config, optname, optdict)
        value = utils._format_option_value(optdict, value)
    if value is optparse.NO_DEFAULT or not value:
        value = self.NO_DEFAULT_VALUE
    return option.help.replace(self.default_tag, str(value)) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:23,代码来源:config.py

示例15: lambda_handler

# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionParser [as 别名]
def lambda_handler(event, context):
    parser = OptionParser()
    parser.add_option("-a", "--access-key", dest="AWS_ACCESS_KEY_ID", help="Provide AWS access key")
    parser.add_option("-s", "--secret-key", dest="AWS_SECRET_ACCESS_KEY", help="Provide AWS secret key")
    parser.add_option("-d", "--dry-run", action="store_true", dest="DRY_RUN", default=False, help="Dry run the process")
    (options, args) = parser.parse_args()

    if options.AWS_ACCESS_KEY_ID and options.AWS_SECRET_ACCESS_KEY:
        os.environ['AWS_ACCESS_KEY_ID'] = options.AWS_ACCESS_KEY_ID
        os.environ['AWS_SECRET_ACCESS_KEY'] = options.AWS_SECRET_ACCESS_KEY
    elif options.AWS_ACCESS_KEY_ID or options.AWS_SECRET_ACCESS_KEY:
        print 'AWS key or secret are missing'

    runType = 'dry' if options.DRY_RUN else 'normal'
    main(run=runType) 
开发者ID:omerxx,项目名称:ecscale,代码行数:17,代码来源:ecscale.py


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