當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。