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
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
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
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
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
def app(): fava_app.config['BEANCOUNT_FILES'] = [EXAMPLE_FILE] load_file() fava_app.testing = True return fava_app
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'] = ''
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'] = ''
def setup_app(): app.config['BEANCOUNT_FILES'] = [EXAMPLE_FILE] load_file() app.testing = True
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)