Exemplo n.º 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
Exemplo n.º 2
0
Arquivo: cli.py Projeto: 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
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'] = ''
Exemplo n.º 4
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'] = ''