當前位置: 首頁>>代碼示例>>Python>>正文


Python options.define方法代碼示例

本文整理匯總了Python中tornado.options.options.define方法的典型用法代碼示例。如果您正苦於以下問題:Python options.define方法的具體用法?Python options.define怎麽用?Python options.define使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.options.options的用法示例。


在下文中一共展示了options.define方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: group_dict

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:22,代碼來源:options.py

示例2: group_dict

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [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
        ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:24,代碼來源:options.py

示例3: define

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def define(
    name: str,
    default: Any = None,
    type: type = None,
    help: str = None,
    metavar: str = None,
    multiple: bool = False,
    group: str = None,
    callback: Callable[[Any], None] = None,
) -> None:
    """Defines an option in the global namespace.

    See `OptionParser.define`.
    """
    return options.define(
        name,
        default=default,
        type=type,
        help=help,
        metavar=metavar,
        multiple=multiple,
        group=group,
        callback=callback,
    ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:26,代碼來源:options.py

示例4: define_logging_options

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def define_logging_options(options=None):
    if options is None:
        # late import to prevent cycle
        from tornado.options import options
    options.define("logging", default="info",
                   help=("Set the Python log level. If 'none', tornado won't touch the "
                         "logging configuration."),
                   metavar="debug|info|warning|error|none")
    options.define("log_to_stderr", type=bool, default=None,
                   help=("Send log output to stderr (colorized if possible). "
                         "By default use stderr if --log_file_prefix is not set and "
                         "no other logging is configured."))
    options.define("log_file_prefix", type=str, default=None, metavar="PATH",
                   help=("Path prefix for log files. "
                         "Note that if you are running multiple tornado processes, "
                         "log_file_prefix must be different for each of them (e.g. "
                         "include the port number)"))
    options.define("log_file_max_size", type=int, default=100 * 1000 * 1000,
                   help="max size of log files before rollover")
    options.define("log_file_num_backups", type=int, default=10,
                   help="number of log files to keep")

    options.add_parse_callback(enable_pretty_logging) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:25,代碼來源:log.py

示例5: group_dict

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [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) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:22,代碼來源:options.py

示例6: define

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def define(self, name, default=None, type=None, help=None, metavar=None,
               multiple=False, group=None):
        if name in self:
            raise Error("Option %r already defined in %s", name,
                        self[name].file_name)
        frame = sys._getframe(0)
        options_file = frame.f_code.co_filename
        file_name = frame.f_back.f_code.co_filename
        if file_name == options_file:
            file_name = ""
        if type is None:
            if not multiple and default is not None:
                type = default.__class__
            else:
                type = str
        if group:
            group_name = group
        else:
            group_name = file_name
        self[name] = _Option(name, file_name=file_name, default=default,
                             type=type, help=help, metavar=metavar,
                             multiple=multiple, group_name=group_name) 
開發者ID:omererdem,項目名稱:honeything,代碼行數:24,代碼來源:options.py

示例7: define_logging_options

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def define_logging_options(options=None):
    """Add logging-related flags to ``options``.

    These options are present automatically on the default options instance;
    this method is only necessary if you have created your own `.OptionParser`.

    .. versionadded:: 4.2
        This function existed in prior versions but was broken and undocumented until 4.2.
    """
    if options is None:
        # late import to prevent cycle
        from tornado.options import options
    options.define("logging", default="info",
                   help=("Set the Python log level. If 'none', tornado won't touch the "
                         "logging configuration."),
                   metavar="debug|info|warning|error|none")
    options.define("log_to_stderr", type=bool, default=None,
                   help=("Send log output to stderr (colorized if possible). "
                         "By default use stderr if --log_file_prefix is not set and "
                         "no other logging is configured."))
    options.define("log_file_prefix", type=str, default=None, metavar="PATH",
                   help=("Path prefix for log files. "
                         "Note that if you are running multiple tornado processes, "
                         "log_file_prefix must be different for each of them (e.g. "
                         "include the port number)"))
    options.define("log_file_max_size", type=int, default=100 * 1000 * 1000,
                   help="max size of log files before rollover")
    options.define("log_file_num_backups", type=int, default=10,
                   help="number of log files to keep")

    options.define("log_rotate_when", type=str, default='midnight',
                   help=("specify the type of TimedRotatingFileHandler interval "
                         "other options:('S', 'M', 'H', 'D', 'W0'-'W6')"))
    options.define("log_rotate_interval", type=int, default=1,
                   help="The interval value of timed rotating")

    options.define("log_rotate_mode", type=str, default='size',
                   help="The mode of rotating files(time or size)")

    options.add_parse_callback(lambda: enable_pretty_logging(options)) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:42,代碼來源:log.py

示例8: __init__

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def __init__(self):
        # we have to use self.__dict__ because we override setattr.
        self.__dict__['_options'] = {}
        self.__dict__['_parse_callbacks'] = []
        self.define("help", type=bool, help="show this help information",
                    callback=self._help_callback) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:8,代碼來源:options.py

示例9: groups

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def groups(self):
        """The set of option-groups created by ``define``.

        .. versionadded:: 3.1
        """
        return set(opt.group_name for opt in self._options.values()) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:8,代碼來源:options.py

示例10: define

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def define(name, default=None, type=None, help=None, metavar=None,
           multiple=False, group=None, callback=None):
    """Defines an option in the global namespace.

    See `OptionParser.define`.
    """
    return options.define(name, default=default, type=type, help=help,
                          metavar=metavar, multiple=multiple, group=group,
                          callback=callback) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:11,代碼來源:options.py

示例11: __init__

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def __init__(self) -> None:
        # we have to use self.__dict__ because we override setattr.
        self.__dict__["_options"] = {}
        self.__dict__["_parse_callbacks"] = []
        self.define(
            "help",
            type=bool,
            help="show this help information",
            callback=self._help_callback,
        ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:options.py

示例12: groups

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def groups(self) -> Set[str]:
        """The set of option-groups created by ``define``.

        .. versionadded:: 3.1
        """
        return set(opt.group_name for opt in self._options.values()) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:8,代碼來源:options.py

示例13: parse_command

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def parse_command(self, args=None, final=False):
        """
        解析命令行參數,解析logger配置
        :return:
        """
        self.define()
        add_parse_callback(self.parse_logger_callback)
        parse_command_line(args, final)
        options.run_parse_callbacks() 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:11,代碼來源:webserver.py

示例14: parse_logger_callback

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def parse_logger_callback(self):
        if options.disable_log:
            options.logging = None
        if options.log_file_prefix and options.log_port_prefix:
            options.log_file_prefix += ".%s" % options.port
        if options.log_patch:
            logging.handlers.TimedRotatingFileHandler = ProcessLogTimedFileHandler
        tornado_logger = logging.getLogger('tornado')
        enable_pretty_logging(logger=tornado_logger)
        logdir = options.logging_dir or settings.LOGGING_DIR
        for log in settings.LOGGING:
            opt = OptionParser()
            define_logging_options(opt)
            self.define(opt)
            opt.log_rotate_when = log.get('when', 'midnight')
            opt.log_to_stderr = log.get('log_to_stderr', False) if options.log_to_stderr is None else options.log_to_stderr
            opt.logging = log.get('level', 'INFO')
            opt.log_file_prefix = os.path.join(logdir, log['filename'])
            if log.get('backups'):
                opt.log_file_num_backups = log.get('backups')
            if opt.log_port_prefix:
                opt.log_file_prefix += ".%s" % options.port
            opt.log_rotate_interval = log.get('interval', 1)
            opt.log_rotate_mode = 'time'
            logger = logging.getLogger(log['name'])
            logger.propagate = 0
            enable_pretty_logging(options=opt, logger=logger)
            map(lambda h: h.setFormatter(LogFormatter(fmt=log.get("formatter", LogFormatter.DEFAULT_FORMAT),
                                                      color=settings.DEBUG)), logger.handlers) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:31,代碼來源:webserver.py

示例15: define

# 需要導入模塊: from tornado.options import options [as 別名]
# 或者: from tornado.options.options import define [as 別名]
def define(self, options=options):
        """
        定義命令行參數,你可以自定義很多自己的命令行參數,或重寫此方法覆蓋默認參數
        :return:
        """
        try:
            # 增加timerotating日誌配置
            options.define("log_rotate_when", type=str, default='midnight',
                           help=("specify the type of TimedRotatingFileHandler interval "
                                 "other options:('S', 'M', 'H', 'D', 'W0'-'W6')"))
            options.define("log_rotate_interval", type=int, default=1,
                           help="The interval value of timed rotating")

            options.define("log_rotate_mode", type=str, default='time',
                           help="The mode of rotating files(time or size)")
        except:
            pass
        options.define("port", default=8000, help="run server on it", type=int)
        options.define("settings", default='', help="setting module name", type=str)
        options.define("address", default='0.0.0.0', help='listen host,default:0.0.0.0', type=str)
        options.define("log_patch", default=True,
                       help='Use ProcessTimedRotatingFileHandler instead of the default TimedRotatingFileHandler.',
                       type=bool)

        options.define("log_port_prefix", default=None, help='add port to log file prefix.', type=bool)
        options.define("logging_dir", default='', help='custom log dir.')
        options.define("disable_log", default=True, help='disable tornado log function.') 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:29,代碼來源:webserver.py


注:本文中的tornado.options.options.define方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。