コード例 #1
0
def main(
    filenames: Tuple[str],
    port: int,
    host: str,
    prefix: str,
    incognito: bool,
    debug: bool,
    profile: bool,
    profile_dir: str,
) -> None:  # pragma: no cover
    """Start Fava for FILENAMES on http://<host>:<port>.

    If the `BEANCOUNT_FILE` environment variable is set, Fava will use the
    files (space-delimited) specified there in addition to FILENAMES.

    Note you can also specify command-line options via environment variables.
    For example, `--host=0.0.0.0` is equivalent to setting the environment
    variable `FAVA_HOST=0.0.0.0`.
    """

    if profile:
        debug = True

    env_filename = os.environ.get("BEANCOUNT_FILE")
    all_filenames = (filenames + tuple(env_filename.split())
                     if env_filename else filenames)

    if not all_filenames:
        raise click.UsageError("No file specified")

    app.config["BEANCOUNT_FILES"] = all_filenames
    app.config["INCOGNITO"] = incognito

    if prefix:
        app.wsgi_app = DispatcherMiddleware(  # type: ignore
            simple_wsgi, {prefix: app.wsgi_app})

    if not debug:
        server = Server((host, port), app)
        print(f"Running Fava on http://{host}:{port}")
        server.safe_start()
    else:
        if profile:
            app.config["PROFILE"] = True
            app.wsgi_app = ProfilerMiddleware(  # type: ignore
                app.wsgi_app,
                restrictions=(30, ),
                profile_dir=profile_dir if profile_dir else None,
            )

        app.jinja_env.auto_reload = True
        try:
            app.run(host, port, debug)
        except OSError as error:
            if error.errno == errno.EADDRINUSE:
                raise click.UsageError(
                    "Can not start webserver because the port is already in "
                    "use. Please choose another port with the '-p' option.")
            raise
コード例 #2
0
def main(filenames, port, host, settings, debug, profile, profile_dir,
         profile_restriction):
    """Start fava for FILENAMES on http://host:port."""

    if profile_dir:
        profile = True
    if profile:
        debug = True

    env_filename = os.environ.get('BEANCOUNT_FILE', None)
    if env_filename:
        filenames = filenames + (env_filename,)

    if not filenames:
        raise click.UsageError('No file specified')

    app.config['BEANCOUNT_FILES'] = filenames
    app.config['USER_SETTINGS'] = settings

    load_settings()
    load_file()

    if debug:
        if profile:
            from werkzeug.contrib.profiler import ProfilerMiddleware
            app.config['PROFILE'] = True
            app.wsgi_app = ProfilerMiddleware(
                app.wsgi_app,
                restrictions=(profile_restriction,),
                profile_dir=profile_dir if profile_dir else None)

        app.run(host, port, debug)
    else:
        server = Server(app.wsgi_app)
        if settings:
            server.watch(settings, load_settings)

        def reload_source_files(api):
            filename = api.options['filename']
            api.load_file()
            include_path = os.path.dirname(filename)
            for filename in api.options['include'] + \
                    api.options['documents']:
                server.watch(os.path.join(include_path, filename),
                             lambda: reload_source_files(api))

        for api in app.config['APIS'].values():
            reload_source_files(api)

        try:
            server.serve(port=port, host=host, debug=debug)
        except OSError as error:
            if error.errno == errno.EADDRINUSE:
                print("Error: Can not start webserver because the port/address"
                      "is already in use.")
                print("Please choose another port with the '-p' option.")
            else:
                raise
コード例 #3
0
def main(
    filenames, port, host, prefix, incognito, debug, profile, profile_dir
):
    """Start Fava for FILENAMES on http://<host>:<port>.

    If the `BEANCOUNT_FILE` environment variable is set, Fava will use the
    files (space-delimited) specified there in addition to FILENAMES.
    """

    if profile:  # pragma: no cover
        debug = True

    env_filename = os.environ.get("BEANCOUNT_FILE")
    if env_filename:
        filenames = filenames + tuple(env_filename.split())

    if not filenames:
        raise click.UsageError("No file specified")

    app.config["BEANCOUNT_FILES"] = filenames
    app.config["INCOGNITO"] = incognito

    if prefix:
        app.wsgi_app = DispatcherMiddleware(
            simple_wsgi, {prefix: app.wsgi_app}
        )

    if not debug:
        server = wsgi.Server((host, port), app)
        print("Running Fava on http://{}:{}".format(host, port))
        server.safe_start()
    else:
        if profile:
            from werkzeug.contrib.profiler import ProfilerMiddleware

            app.config["PROFILE"] = True
            app.wsgi_app = ProfilerMiddleware(
                app.wsgi_app,
                restrictions=(30,),
                profile_dir=profile_dir if profile_dir else None,
            )

        app.jinja_env.auto_reload = True
        try:
            app.run(host, port, debug)
        except OSError as error:
            if error.errno == errno.EADDRINUSE:
                raise click.UsageError(
                    "Can not start webserver because the port is already in "
                    "use. Please choose another port with the '-p' option."
                )
            else:  # pragma: no cover
                raise
コード例 #4
0
ファイル: cli.py プロジェクト: cgrinds/fava
def main(filename, port, host, settings, debug, profile, profile_dir,
         profile_restriction):
    """Start fava for FILENAME on http://host:port."""

    if profile_dir:
        profile = True
    if profile:
        debug = True

    app.config['BEANCOUNT_FILE'] = filename
    app.config['USER_SETTINGS'] = settings

    load_settings()

    if debug:
        load_file()
        if profile:
            from werkzeug.contrib.profiler import ProfilerMiddleware
            app.config['PROFILE'] = True
            app.wsgi_app = ProfilerMiddleware(
                app.wsgi_app,
                restrictions=(profile_restriction,),
                profile_dir=profile_dir if profile_dir else None)

        app.run(host, port, debug)
    else:
        server = Server(app.wsgi_app)
        if settings:
            server.watch(settings, load_settings)

        def reload_source_files():
            load_file()
            include_path = os.path.dirname(app.config['BEANCOUNT_FILE'])
            for filename in api.options['include'] + api.options['documents']:
                server.watch(os.path.join(include_path, filename),
                             reload_source_files)
        reload_source_files()

        try:
            server.serve(port=port, host=host, debug=debug)
        except OSError as e:
            if e.errno == errno.EADDRINUSE:
                print("Error: Can not start webserver because the port/address"
                      "is already in use.")
                print("Please choose another port with the '-p' option.")
            else:
                raise
        except:
            print("Unexpected error:", e)
            raise
コード例 #5
0
ファイル: cli.py プロジェクト: TomJohnZ/fava
def main(filenames, port, host, prefix, debug, profile, profile_dir,
         profile_restriction):
    """Start Fava for FILENAMES on http://host:port.

    If the `BEANCOUNT_FILE` environment variable is set, Fava will use the file
    specified there in addition to FILENAMES.
    """

    if profile_dir:  # pragma: no cover
        profile = True
    if profile:  # pragma: no cover
        debug = True

    env_filename = os.environ.get('BEANCOUNT_FILE')
    if env_filename:
        filenames = filenames + (env_filename, )

    if not filenames:
        raise click.UsageError('No file specified')

    app.config['BEANCOUNT_FILES'] = filenames

    load_file()

    if prefix:
        app.wsgi_app = DispatcherMiddleware(simple_wsgi,
                                            {prefix: app.wsgi_app})

    if debug:  # pragma: no cover
        if profile:
            # pylint: disable=redefined-variable-type
            from werkzeug.contrib.profiler import ProfilerMiddleware
            app.config['PROFILE'] = True
            app.wsgi_app = ProfilerMiddleware(
                app.wsgi_app,
                restrictions=(profile_restriction, ),
                profile_dir=profile_dir if profile_dir else None)

        app.jinja_env.auto_reload = True

    try:
        app.run(host, port, debug)
    except OSError as error:
        if error.errno == errno.EADDRINUSE:
            raise click.UsageError(
                "Can not start webserver because the port is already in "
                "use. Please choose another port with the '-p' option.")
        else:  # pragma: no cover
            raise
コード例 #6
0
ファイル: cli.py プロジェクト: yagebu/fava
def main(filenames, port, host, prefix, debug, profile, profile_dir,
         profile_restriction):
    """Start Fava for FILENAMES on http://host:port.

    If the `BEANCOUNT_FILE` environment variable is set, Fava will use the file
    specified there in addition to FILENAMES.
    """

    if profile_dir:  # pragma: no cover
        profile = True
    if profile:  # pragma: no cover
        debug = True

    env_filename = os.environ.get('BEANCOUNT_FILE', None)
    if env_filename:
        filenames = filenames + (env_filename,)

    if not filenames:
        raise click.UsageError('No file specified')

    app.config['BEANCOUNT_FILES'] = filenames

    load_file()

    if prefix:
        app.wsgi_app = DispatcherMiddleware(simple_wsgi,
                                            {prefix: app.wsgi_app})

    if debug:  # pragma: no cover
        if profile:
            from werkzeug.contrib.profiler import ProfilerMiddleware
            app.config['PROFILE'] = True
            app.wsgi_app = ProfilerMiddleware(
                app.wsgi_app,
                restrictions=(profile_restriction,),
                profile_dir=profile_dir if profile_dir else None)

        app.jinja_env.auto_reload = True

    try:
        app.run(host, port, debug)
    except OSError as error:
        if error.errno == errno.EADDRINUSE:
            raise click.UsageError(
                "Can not start webserver because the port is already in "
                "use. Please choose another port with the '-p' option.")
        else:  # pragma: no cover
            raise
コード例 #7
0
ファイル: cli.py プロジェクト: yegle/fava
def main(
    filenames: tuple[str],
    port: int,
    host: str,
    prefix: str,
    incognito: bool,
    debug: bool,
    profile: bool,
    profile_dir: str,
) -> None:  # pragma: no cover
    """Start Fava for FILENAMES on http://<host>:<port>.

    If the `BEANCOUNT_FILE` environment variable is set, Fava will use the
    files (space-delimited) specified there in addition to FILENAMES.

    Note you can also specify command-line options via environment variables.
    For example, `--host=0.0.0.0` is equivalent to setting the environment
    variable `FAVA_HOST=0.0.0.0`.
    """

    if profile:
        debug = True

    env_filename = os.environ.get("BEANCOUNT_FILE")
    all_filenames = (
        filenames + tuple(env_filename.split()) if env_filename else filenames
    )

    if not all_filenames:
        raise click.UsageError("No file specified")

    app.config["BEANCOUNT_FILES"] = all_filenames
    app.config["INCOGNITO"] = incognito

    if prefix:
        app.wsgi_app = DispatcherMiddleware(  # type: ignore
            simple_wsgi, {prefix: app.wsgi_app}
        )

    if host == "localhost":
        # ensure that cheroot does not use IP6 for localhost
        host = "127.0.0.1"

    click.echo(f"Starting Fava on http://{host}:{port}")
    if not debug:
        server = Server((host, port), app)
        try:
            server.start()
        except KeyboardInterrupt:
            click.echo("Keyboard interrupt received: stopping Fava", err=True)
            server.stop()
        except OSError as error:
            if "No socket could be created" in str(error):
                click.echo(
                    f"Cannot start Fava because port {port} is already in use."
                    "\nPlease choose a different port with the '-p' option."
                )
            raise click.Abort
    else:
        if profile:
            app.config["PROFILE"] = True
            app.wsgi_app = ProfilerMiddleware(  # type: ignore
                app.wsgi_app,
                restrictions=(30,),
                profile_dir=profile_dir if profile_dir else None,
            )

        app.jinja_env.auto_reload = True
        try:
            app.run(host, port, debug)
        except OSError as error:
            if error.errno == errno.EADDRINUSE:
                click.echo(
                    f"Cannot start Fava because port {port} is already in use."
                    "\nPlease choose a different port with the '-p' option."
                )
                raise click.Abort
            raise