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


Python options.define函数代码示例

本文整理汇总了Python中tornado.options.define函数的典型用法代码示例。如果您正苦于以下问题:Python define函数的具体用法?Python define怎么用?Python define使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: config_app

def config_app(config, default_options_file, replace_options):
    init_env()
    app_log.set_logging_level(app_common_const.LOG_LEVEL)

    with open(default_options_file, 'r') as f:
        default_options = json.load(f)
        if default_options:
            for option in default_options.get('global_option', {}):
                if option:
                    define(option[0], default=option[1],
                           help=option[2], type=get_builtin_type(option[3]))

    options.parse_config_file(config)

    if not check_server_config():
        raise EnvironmentError('app server config')

    if app_common_const.OPTION_LOG_PATH in options:
        app_log.define_file_logging()

    options.template_path = str(os.path.join(app_common_const.PROJECT_BASE_FOLDER, options.template_path))
    options.static_path = str(os.path.join(app_common_const.PROJECT_BASE_FOLDER, options.static_path))

    if replace_options and replace_options['port']:
        options.port = int(replace_options['port'])

    config_jinja2()
开发者ID:LordRoad,项目名称:little,代码行数:27,代码来源:app_config.py

示例2: __init__

 def __init__(self, handlers, **settings):
   define('poolsize', default=10, type=int)
   settings['session_secret'] = options.sessionsecret
   settings['cookie_secret'] = options.cookiesecret
   self.pool = database.Pool.instance()
   self.session_manager = session.SessionManager(session.DatabaseSessionStorage, self.pool, secret=options.sessionsecret)
   super(BaseApplication, self).__init__(handlers, **settings)
开发者ID:jdsieci,项目名称:engine,代码行数:7,代码来源:application.py

示例3: main

def main():
    define("sslcheck", default=1, help="Verify SSL hostname, on by default")
    define("use_simple_http_client", default=0,
           help="Use Tornado SimpleHTTPClient instead of CurlAsyncHTTPClient")
    args = parse_command_line()
    skip_ssl_validation = False
    use_simple_http_client = False

    if unicode(options.sslcheck) == u"0":
        skip_ssl_validation = True

    if unicode(options.use_simple_http_client) == u"1":
        use_simple_http_client = True

    # If we don't have any arguments, run the server.
    if not args:
        app = init_forwarder(skip_ssl_validation, use_simple_http_client=use_simple_http_client)
        try:
            app.run()
        finally:
            ForwarderStatus.remove_latest_status()

    else:
        usage = "%s [help|info]. Run with no commands to start the server" % (sys.argv[0])
        command = args[0]
        if command == 'info':
            logging.getLogger().setLevel(logging.ERROR)
            return ForwarderStatus.print_latest_status()
        elif command == 'help':
            print(usage)
        else:
            print("Unknown command: %s" % command)
            print(usage)
            return -1
    return 0
开发者ID:bluejayKR,项目名称:monasca-agent,代码行数:35,代码来源:daemon.py

示例4: init_define

def init_define():
    define("flag", default=False, help="when system is first time,flag should be set True", type=bool)
    # log
    define("log_file_prefix", default="./log/analysis.log")
    define("log_rotate_mode", default='time')  # 轮询模式: time or size
    define("log_rotate_when", default='H')  # 单位: S / M / H / D / W0 - W6
    define("log_rotate_interval", default=24)  # 间隔: 24小时
开发者ID:alatting,项目名称:smartposter,代码行数:7,代码来源:analysis_server.py

示例5: main

def main():
    define("pycurl", default=1, help="Use pycurl")
    args = parse_command_line()

    if options.pycurl == 0 or options.pycurl == "0":
        os.environ['USE_SIMPLE_HTTPCLIENT'] = '1'

    # If we don't have any arguments, run the server.
    if not args:
        import tornado.httpclient
        app = init()
        try:
            app.run()
        finally:
            ForwarderStatus.remove_latest_status()
            
    else:
        usage = "%s [help|info]. Run with no commands to start the server" % (
                                        sys.argv[0])
        command = args[0]
        if command == 'info':
            return ForwarderStatus.print_latest_status()
        elif command == 'help':
            print usage
        else:
            print "Unknown command: %s" % command
            print usage
            return -1
    return 0
开发者ID:shawnsmith,项目名称:dd-agent,代码行数:29,代码来源:ddagent.py

示例6: parse_config

    def parse_config(self):
        """Parses the command line arguments, and assign their
        values to our local traits.
        """

        if not self.command_line_options_inited:
            for traitlet_name, traitlet in self.traits().items():
                    define(
                        traitlet_name,
                        default=traitlet.default_value,
                        type=type(traitlet.default_value),
                        help=traitlet.help)

        self.__class__.command_line_options_inited = True

        tornado.options.parse_command_line()

        # Workaround for change in jupyterhub 0.7.0.
        # Args are passed with quotes, that are preserved in the arguments when
        # we retrieve them. We just get rid of the quotes, until a better
        # solution comes along.
        # See jupyterhub/jupyterhub#836 for details.
        opts = {k: remove_quotes(v) for k, v in options.as_dict().items()}
        set_traits_from_dict(self, opts)

        # Normalize the base_urlpath to end with a slash
        self.base_urlpath = with_end_slash(self.base_urlpath)
开发者ID:simphony,项目名称:simphony-remote,代码行数:27,代码来源:command_line_config.py

示例7: main

def main(args=None):
    if args is None:
        args = sys.argv

    options.define('root', default='.', help='document root')
    options.define('proxy', default='', help='http proxy')

    options.parse_command_line()

    log.enable_pretty_logging()

    main_loop = ioloop.IOLoop.instance()

    pool = cf.ThreadPoolExecutor(max_workers=4)

    application = web.Application([
        (r'/(.*)', IndexHandler, {
            'root': options.options.root,
            'pool': pool,
            'proxy': options.options.proxy,
        }),
    ], debug=True)

    application.listen(8000)

    main_loop.start()
    pool.shutdown()
    main_loop.close()

    return 0
开发者ID:legnaleurc,项目名称:autoindex,代码行数:30,代码来源:autoindex.py

示例8: start

def start():
    #tornado.options.parse_command_line()

    # 定义Tornado url
    urls = \
        [
            (r'/login', LoginHandler),
            (r'/logout', LogoutHandler),
            (r'/main', MainHandler),
            #(r'/assets[/]?(.*)', TestHandler),
            (r'/assets/test.html', TestHandler),
            (r'/assets/user_list.html', UserListHandler),
            (r'/assets/user_list_add.html', UserListAddHandler),

            (r'/getdata', API2MysqlHandler),
            #(r'/assets/asset_children/(.*)', tornado.web.StaticFileHandler, {"path": settings['asset_children']}),    # 后台文件路径
        ]

    #Tornado监听IP/端口
    define("host", default=LISTEN_HOST, help="run on the given host", type=str)
    define("port", default=LISTEN_PORT, help="run on the given port", type=int)

    application = tornado.web.Application(urls,**settings)

    try:
        http_server = tornado.httpserver.HTTPServer(application,xheaders=True)
        http_server.listen(port=options.port, address=options.host)
        print 'Tornado load config finished,run at %s:%d; locate test url http://127.0.0.1:%d' % (LISTEN_HOST,LISTEN_PORT,LISTEN_PORT)

        tornado.ioloop.IOLoop.instance().start()
    except Exception,err:
        print 'Tornado 启动失败'
        raise err
开发者ID:Drizztx,项目名称:giter,代码行数:33,代码来源:server.py

示例9: main

def main():
    define("port", default=Config.data['web']['port'], help="run on the given port", type=int)
    options.parse_command_line()
    logger.set_logger('web-{}.log'.format(options.port))
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
开发者ID:thomaserlang,项目名称:TLog,代码行数:7,代码来源:app.py

示例10: __init__

    def __init__(self, defines):
        for setting_define in defines:
            if setting_define.name.upper() != setting_define.name:
                raise ValueError("Setting name must be uppercase.")
            if setting_define.content_type not in self._setting_parsers:
                raise ValueError("Unknown setting content type.")
            if setting_define.name in self.__dict__:
                raise ValueError("Invalid setting name.")

            default = os.getenv(
                '{prefix}_{attr}'.format(
                    prefix=self.ENV_PREFIX,
                    attr=setting_define.name),
                setting_define.default
            )

            parser = self._setting_parsers[setting_define.content_type]

            options.define(
                setting_define.name,
                type=parser.OPTIONS_TYPE,
                default=parser.decode(value=default),
                help=setting_define.description
            )

        options.parse_command_line()
开发者ID:nanvel,项目名称:tornado-boilerplate,代码行数:26,代码来源:models.py

示例11: main

def main():
    define('port', default=1013, help='run on the given port', type=int)
    
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
开发者ID:lucienzhu,项目名称:TornadoPhotoExplorer,代码行数:7,代码来源:main.py

示例12: main

def main():
    define("console", default=False, type=bool)
    define("mongo_host", default="localhost")

    parse_command_line()
    basicConfig(options=options)
    db = Connection(options.mongo_host)["crunch"]["company_stats"]
开发者ID:daniyalzade,项目名称:crunchviz,代码行数:7,代码来源:handler.py

示例13: main

def main():
    global config
    global dm

    with open('dm-config.json', 'r') as f:
        config = json.load(f)

    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.getLevelName(config['config']['log_level']),
                        stream=sys.stderr)

    define("port", default=5000, help="run on the given port", type=int)
    tornado.options.parse_command_line()

    logging.info("Starting up...")

    deployer_utils.fill_hadoop_env(config['environment'])

    package_repository = PackageRepoRestClient(config['config']["package_repository"], config['config']['stage_root'])
    dm = deployment_manager.DeploymentManager(package_repository,
                                              package_registrar.HbasePackageRegistrar(
                                                  config['environment']['hbase_thrift_server'],
                                                  config['environment']['webhdfs_host'],
                                                  'hdfs',
                                                  config['environment']['webhdfs_port'],
                                                  config['config']['stage_root']),
                                              application_registrar.HbaseApplicationRegistrar(
                                                  config['environment']['hbase_thrift_server']),
                                              config['environment'],
                                              config['config'])

    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)

    tornado.ioloop.IOLoop.instance().start()
开发者ID:pndaproject,项目名称:platform-deployment-manager,代码行数:35,代码来源:app.py

示例14: main

def main():
    try:
        """
        defining/parsing the options
        """
        define("port", default=8082, help="run on the given port", type=int)
        define("debug", default=False, help="run in debug mode", type=bool)
        tornado.options.parse_command_line()        
        logging.debug(options.logging)
        """
        initalising applications
        """ 
        app = MyApplication(options)

        """
        starting tornado server
        """
        http_server = tornado.httpserver.HTTPServer(app)
        http_server.listen(options.port)
        ioloop = tornado.ioloop.IOLoop.instance()
        tornado.autoreload.add_reload_hook(app.reloadTasks)
        tornado.autoreload.start(ioloop)
        ioloop.start()

    except KeyboardInterrupt:
        pass
    except:
        print traceback.format_exc()
开发者ID:louhibi,项目名称:tornado_app_squeleton,代码行数:28,代码来源:main.py

示例15: mainloop

def mainloop():
    """
    get options configure application and start io loop
    """
    topt.define("alligator", default="tcp://localhost:5555", help="Alligator command server ZMQ endpoint")
    topt.define("port", type=int, default=4444, help="webserver port")
    
    topt.parse_command_line()
    port = topt.options.port

    application = tw.Application([
        (r"/", MainHandler),
        (r"/workbench/(.*)", tw.StaticFileHandler, dict(path="../www")),
        (r"/alligator", AlligatorWsHandler, dict(endpoint=topt.options.alligator)) 
        ])

    log.info('bridge ws to alligator: %s', topt.options.alligator)
    
    application.listen(port)
    log.info('server listening on:    %d', port)

    
    try:
        tio.IOLoop.instance().start()
    except KeyboardInterrupt as u:
        log.info("user interrupted")
    except Exception as e:
        log.error(e)
开发者ID:krystofa,项目名称:alligator,代码行数:28,代码来源:alligator_websocket_bridge.py


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