コード例 #1
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
コード例 #2
0
ファイル: test_scrape.py プロジェクト: redstreet/fava
def setup_app(tmpdir):
    filename = tmpdir.join('beancount.example')
    with filename.open('w') as fd:
        today = datetime.date.today()
        write_example_file(datetime.date(1980, 5, 12),
                           datetime.date(today.year - 3, 1, 1),
                           today, True, fd)
    app.config['BEANCOUNT_FILES'] = [str(filename)]
    load_file()
    app.testing = True
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
0
ファイル: conftest.py プロジェクト: corani/beancount-web
def app():
    fava_app.config['BEANCOUNT_FILES'] = [EXAMPLE_FILE]
    load_file()
    fava_app.testing = True
    return fava_app
コード例 #7
0
from fava.application import app as application
from fava.application import load_file, load_settings

application.config['BEANCOUNT_FILES'] = [
        '/home/fava/test1.bean', '/home/fava/test2.bean']
application.config['USER_SETTINGS'] = None

load_settings()
load_file()

# app.user_config = configparser.ConfigParser()
# user_config_defaults_file = '/home/fava/default-settings.conf'
# app.user_config.readfp(open(user_config_defaults_file))
# app.user_config['fava']['file_defaults'] = user_config_defaults_file
# app.user_config['fava']['file_user'] = ''
コード例 #8
0
from fava.application import app as application
from fava.application import load_file, load_settings

application.config['BEANCOUNT_FILES'] = [
    '/home/fava/test1.bean', '/home/fava/test2.bean'
]
application.config['USER_SETTINGS'] = None

load_settings()
load_file()

# app.user_config = configparser.ConfigParser()
# user_config_defaults_file = '/home/fava/default-settings.conf'
# app.user_config.readfp(open(user_config_defaults_file))
# app.user_config['fava']['file_defaults'] = user_config_defaults_file
# app.user_config['fava']['file_user'] = ''
コード例 #9
0
ファイル: conftest.py プロジェクト: bootstrap/beancount-web
def app():
    fava_app.config['BEANCOUNT_FILES'] = [EXAMPLE_FILE]
    load_file()
    fava_app.testing = True
    return fava_app
コード例 #10
0
ファイル: conftest.py プロジェクト: gitter-badger/fava
def setup_app():
    app.config['BEANCOUNT_FILES'] = [EXAMPLE_FILE]
    load_file()
    app.testing = True
コード例 #11
0
ファイル: cli.py プロジェクト: cgrinds/fava
 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)
コード例 #12
0
ファイル: conftest.py プロジェクト: gitter-badger/fava
def setup_app():
    app.config['BEANCOUNT_FILES'] = [EXAMPLE_FILE]
    load_file()
    app.testing = True