示例#1
0
def run_command(info, host, port, reload, debugger, eager_loading,
                with_threads, cert):
    env = get_env()
    click.echo(' * Environment: {0}'.format(env))

    if env == 'production':
        from ..gunicorn import WSGIApplication
        app = WSGIApplication(loader=info.load_app)
        app.run()

    else:
        debug = get_debug_flag()

        if reload is None:
            reload = debug

        if debugger is None:
            debugger = debug

        if eager_loading is None:
            eager_loading = not reload

        click.echo(' * Debug mode: {0}'.format('on' if debug else 'off'))

        app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)

        from werkzeug.serving import run_simple
        run_simple(host,
                   port,
                   app,
                   use_reloader=reload,
                   use_debugger=debugger,
                   threaded=with_threads,
                   ssl_context=cert)
示例#2
0
def ssl(info, host, port, reload, debugger, eager_loading, with_threads, cert,
        key):
    """Run a local development server.

    This server is for development purposes only. It does not provide
    the stability, security, or performance of production WSGI servers.

    The reloader and debugger are enabled by default if
    FLASK_ENV=development or FLASK_DEBUG=1.
    """
    debug = get_debug_flag()

    if reload is None:
        reload = debug

    if debugger is None:
        debugger = debug

    if eager_loading is None:
        eager_loading = not reload

    show_server_banner(get_env(), debug, info.app_import_path, eager_loading)
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)

    if cert is None:
        ssl = info._loaded_app.config.get('SSL', {})
        if ssl is {}:
            raise Exception("'SSL' section in configuration is missing")

        try:
            certificate = ssl['CERTIFICATE']
            if not os.path.isfile(certificate):
                raise Exception("Certificate file '%s' not preset.")

            keyfile = ssl['KEYFILE']
            if not os.path.isfile(keyfile):
                raise Exception("Certificate file '%s' not preset.")

            cert = (certificate, keyfile)

        except AttributeError:
            pass

        except Exception as exc:
            raise

    from werkzeug.serving import run_simple
    run_simple(host,
               port,
               app,
               use_reloader=reload,
               reloader_type='stat',
               use_debugger=debugger,
               threaded=with_threads,
               ssl_context=cert)
    return
示例#3
0
def dev(info, host, port, reload, debugger, eager_loading, with_threads, cert):
    """Run a local development server.

    This server is for development purposes only. It does not provide
    the stability, security, or performance of production WSGI servers.

    The reloader and debugger are enabled by default if
    FLASK_ENV=development or FLASK_DEBUG=1.
    """
    debug = get_debug_flag()

    if reload is None:
        reload = debug

    if debugger is None:
        debugger = debug

    if eager_loading is None:
        eager_loading = not reload

    show_server_banner(get_env(), debug, info.app_import_path, eager_loading)
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
    applic = info.load_app()
    host = applic.config.get('HOST', host)
    port = applic.config.get('PORT', port)

    from werkzeug.serving import run_simple
    run_simple(host,
               port,
               app,
               use_reloader=reload,
               reloader_type='stat',
               use_debugger=debugger,
               threaded=with_threads,
               ssl_context=cert)
    return
示例#4
0
文件: serve.py 项目: pe2mbs/webapp2
def dev(info, host, port, reload, debugger, eager_loading, with_threads, cert):
    """Run a local development server.

    This server is for development purposes only. It does not provide
    the stability, security, or performance of production WSGI servers.

    The reloader and debugger are enabled by default if
    FLASK_ENV=development or FLASK_DEBUG=1.
    """
    debug = get_debug_flag()

    if reload is None:
        reload = debug

    if debugger is None:
        debugger = debug

    if eager_loading is None:
        eager_loading = not reload

    show_server_banner(get_env(), debug, info.app_import_path, eager_loading)
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
    applic = info.load_app()
    if host is None:
        host = applic.config.get('HOST', 'localhost')

    if port is None:
        port = applic.config.get('PORT', 5000)

    else:
        port = int(port)

    API.logger.info("Serving application on http://{}:{}".format(host, port))
    # appPath     = applic.config.get( 'APP_PATH', os.curdir )
    # appApiMod   = applic.config.get( 'API_MODULE', '' )
    # As those files may change, but are only loaded when the application starts
    # we monitor them, so that the application restart when they change
    extra_files = applic.config.get('EXTRA_FILES', [])
    appPath = applic.config.get('APP_PATH', os.curdir)
    appApiMod = applic.config.get('API_MODULE', '')
    extra_files.extend([
        os.path.join(appPath, appApiMod, 'menu.yaml'),
        os.path.join(appPath, appApiMod, 'release.yaml')
    ])
    if API.socketio is not None:
        app.debug = True
        API.socketio.run(
            app,
            host,
            port,
            debug=debugger,
            use_reloader=reload,
            #                         reloader_type = 'stat',
            #                         threaded = with_threads,
            #                          ssl_context = cert,
            extra_files=extra_files)
    else:
        from werkzeug.serving import run_simple
        run_simple(host,
                   port,
                   app,
                   use_reloader=reload,
                   reloader_type='stat',
                   use_debugger=debugger,
                   threaded=with_threads,
                   ssl_context=cert,
                   extra_files=extra_files)

    return
示例#5
0
文件: serve.py 项目: pe2mbs/webapp2
def ssl(info, host, port, reload, debugger, eager_loading, with_threads, cert,
        key):
    """Run a local development server.

    This server is for development purposes only. It does not provide
    the stability, security, or performance of production WSGI servers.

    The reloader and debugger are enabled by default if
    FLASK_ENV=development or FLASK_DEBUG=1.
    """
    debug = get_debug_flag()

    if reload is None:
        reload = debug

    if debugger is None:
        debugger = debug

    if eager_loading is None:
        eager_loading = not reload

    show_server_banner(get_env(), debug, info.app_import_path, eager_loading)
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
    applic = info.load_app()
    if cert is None:
        ssl = applic.config.get('SSL', {})
        if ssl is {}:
            raise Exception("'SSL' section in configuration is missing")

        try:
            certificate = ssl['CERTIFICATE']
            if not os.path.isfile(certificate):
                raise Exception("Certificate file '%s' not preset.")

            keyfile = ssl['KEYFILE']
            if not os.path.isfile(keyfile):
                raise Exception("Certificate file '%s' not preset.")

            cert = (certificate, keyfile)

        except AttributeError:
            pass

        except Exception as exc:
            raise

    appPath = applic.config.get('APP_PATH', os.curdir)
    appApiMod = applic.config.get('API_MODULE', '')
    # As those files may change, but are only loaded when the application starts
    # we monitor them, so that the application restart when they change
    extra_files = [
        os.path.join(appPath, appApiMod, 'menu.yaml'),
        os.path.join(appPath, appApiMod, 'release.yaml')
    ]
    from werkzeug.serving import run_simple
    API.logger.info("Serving application on https://{}:{}".format(host, port))
    run_simple(host,
               port,
               app,
               use_reloader=reload,
               reloader_type='stat',
               use_debugger=debugger,
               threaded=with_threads,
               ssl_context=cert,
               extra_files=extra_files)
    return