本文整理汇总了Python中tornado.options.options.parse_command_line方法的典型用法代码示例。如果您正苦于以下问题:Python options.parse_command_line方法的具体用法?Python options.parse_command_line怎么用?Python options.parse_command_line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.options.options
的用法示例。
在下文中一共展示了options.parse_command_line方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_dict
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def group_dict(self, group):
"""The names and values of options in a group.
Useful for copying options into Application settings::
from tornado.options import define, parse_command_line, options
define('template_path', group='application')
define('static_path', group='application')
parse_command_line()
application = Application(
handlers, **options.group_dict('application'))
.. versionadded:: 3.1
"""
return dict(
(opt.name, opt.value()) for name, opt in self._options.items()
if not group or group == opt.group_name)
示例2: group_dict
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def group_dict(self, group: str) -> Dict[str, Any]:
"""The names and values of options in a group.
Useful for copying options into Application settings::
from tornado.options import define, parse_command_line, options
define('template_path', group='application')
define('static_path', group='application')
parse_command_line()
application = Application(
handlers, **options.group_dict('application'))
.. versionadded:: 3.1
"""
return dict(
(opt.name, opt.value())
for name, opt in self._options.items()
if not group or group == opt.group_name
)
示例3: group_dict
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def group_dict(self, group):
"""The names and values of options in a group.
Useful for copying options into Application settings::
from tornado.options import define, parse_command_line, options
define('template_path', group='application')
define('static_path', group='application')
parse_command_line()
application = Application(
handlers, **options.group_dict('application'))
.. versionadded:: 3.1
"""
return dict(
(name, opt.value()) for name, opt in self._options.items()
if not group or group == opt.group_name)
示例4: parse_command_line
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def parse_command_line(extra_args_func=None):
"""Parse command line arguments for any Pyaiot application."""
if not hasattr(options, "config"):
define("config", default=None, help="Config file")
if not hasattr(options, "broker_host"):
define("broker_host", default="localhost", help="Broker host")
if not hasattr(options, "broker_port"):
define("broker_port", default=8000, help="Broker websocket port")
if not hasattr(options, "debug"):
define("debug", default=False, help="Enable debug mode.")
if not hasattr(options, "key_file"):
define("key_file", default=DEFAULT_KEY_FILENAME,
help="Secret and private keys filename.")
if extra_args_func is not None:
extra_args_func()
options.parse_command_line()
if options.config:
options.parse_config_file(options.config)
# Parse the command line a second time to override config file options
options.parse_command_line()
示例5: parse_command_line
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def parse_command_line(args=None, final=True):
"""Parses global options from the command line.
See `OptionParser.parse_command_line`.
"""
return options.parse_command_line(args, final=final)
示例6: parse_options
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def parse_options():
define("host", default=server.DEFAULT_HOST, help="Server run on the given host", type=str)
define("port", default=server.DEFAULT_PORT, help="Server run on the given port", type=int)
define("rpc_host", default=rpc.DEFAULT_RPC_HOST, help="RPC Server run on the given host", type=str)
define("rpc_port", default=rpc.DEFAULT_RPC_PORT, help="RPC Server run on the given port", type=int)
define("debug", default=server.DEBUG_MODE, help="Debug mode")
define("database", default=settings.DEFAULT_DATABASE, help="Debug mode")
options.parse_command_line()
return options
示例7: parse_command_line
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def parse_command_line(args: List[str] = None, final: bool = True) -> List[str]:
"""Parses global options from the command line.
See `OptionParser.parse_command_line`.
"""
return options.parse_command_line(args, final=final)
示例8: main
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def main():
options.parse_command_line()
check_encoding_setting(options.encoding)
loop = tornado.ioloop.IOLoop.current()
app = make_app(make_handlers(loop, options), get_app_settings(options))
ssl_ctx = get_ssl_context(options)
server_settings = get_server_settings(options)
app_listen(app, options.port, options.address, server_settings)
if ssl_ctx:
server_settings.update(ssl_options=ssl_ctx)
app_listen(app, options.sslport, options.ssladdress, server_settings)
loop.start()
示例9: parse_command_line
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def parse_command_line(self, args=None):
if args is None:
args = sys.argv
remaining = []
for i in xrange(1, len(args)):
# All things after the last option are command line arguments
if not args[i].startswith("-"):
remaining = args[i:]
break
if args[i] == "--":
remaining = args[i + 1:]
break
arg = args[i].lstrip("-")
name, equals, value = arg.partition("=")
name = name.replace('-', '_')
if not name in self:
print_help()
raise Error('Unrecognized command line option: %r' % name)
option = self[name]
if not equals:
if option.type == bool:
value = "true"
else:
raise Error('Option %r requires a value' % name)
option.parse(value)
if self.help:
print_help()
sys.exit(0)
# Set up log level and pretty console logging by default
if self.logging != 'none':
logging.getLogger().setLevel(getattr(logging, self.logging.upper()))
enable_pretty_logging()
return remaining
示例10: define
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def define(name, default=None, type=None, help=None, metavar=None,
multiple=False, group=None):
"""Defines a new command line option.
If type is given (one of str, float, int, datetime, or timedelta)
or can be inferred from the default, we parse the command line
arguments based on the given type. If multiple is True, we accept
comma-separated values, and the option value is always a list.
For multi-value integers, we also accept the syntax x:y, which
turns into range(x, y) - very useful for long integer ranges.
help and metavar are used to construct the automatically generated
command line help string. The help message is formatted like::
--name=METAVAR help string
group is used to group the defined options in logical groups. By default,
command line options are grouped by the defined file.
Command line option names must be unique globally. They can be parsed
from the command line with parse_command_line() or parsed from a
config file with parse_config_file.
"""
return options.define(name, default=default, type=type, help=help,
metavar=metavar, multiple=multiple, group=group)
示例11: enable_pretty_logging
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def enable_pretty_logging(options=options):
"""Turns on formatted logging output as configured.
This is called automatically by `parse_command_line`.
"""
root_logger = logging.getLogger()
if options.log_file_prefix:
channel = logging.handlers.RotatingFileHandler(
filename=options.log_file_prefix,
maxBytes=options.log_file_max_size,
backupCount=options.log_file_num_backups)
channel.setFormatter(_LogFormatter(color=False))
root_logger.addHandler(channel)
if (options.log_to_stderr or
(options.log_to_stderr is None and not root_logger.handlers)):
# Set up color if we are in a tty and curses is installed
color = False
if curses and sys.stderr.isatty():
try:
curses.setupterm()
if curses.tigetnum("colors") > 0:
color = True
except Exception:
pass
channel = logging.StreamHandler()
channel.setFormatter(_LogFormatter(color=color))
root_logger.addHandler(channel)
示例12: main
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def main():
options.parse_command_line()
loop = tornado.ioloop.IOLoop.current()
app = make_app(make_handlers(loop, options), get_app_settings(options))
ssl_ctx = get_ssl_context(options)
server_settings = get_server_settings(options)
app_listen(app, options.port, options.address, server_settings)
if ssl_ctx:
server_settings.update(ssl_options=ssl_ctx)
app_listen(app, options.sslport, options.ssladdress, server_settings)
loop.start()
示例13: start
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import parse_command_line [as 别名]
def start(cap):
"""启动服务器"""
options.parse_command_line()
server = EchoServer(cap)
server.listen(options.port)
logger.info("Listening on TCP port %d", options.port)
IOLoop.current().start()