Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Commit

Permalink
Fix #11: configure application from outside of source tree
Browse files Browse the repository at this point in the history
  • Loading branch information
zgoda committed Feb 7, 2019
1 parent 16186ff commit af13535
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 30 deletions.
41 changes: 29 additions & 12 deletions brewlog/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from logging.config import dictConfig

from flask import Flask, render_template, request, send_from_directory, session
from flask_babel import gettext as _
Expand All @@ -8,29 +9,31 @@
from .templates import setup_template_extensions


def make_app(env):
def make_app(env=None):
configure_logging()
app = Flask(__name__)
configure_app(app, env)
configure_extensions(app, env)
configure_auth(app, env)
configure_hooks(app, env)
configure_blueprints(app, env)
configure_logging(app, env)
configure_error_handlers(app, env)
setup_template_extensions(app)
return app


def configure_app(app, env):
app.config.from_object('brewlog.config')
env_config = 'brewlog.config_%s' % env
try:
app.config.from_object(env_config)
except ImportStringError:
# no special configuration for this environment
pass
if os.environ.get('BREWLOG_CONFIG', ''):
app.config.from_envvar('BREWLOG_CONFIG')
if env is not None:
try:
app.config.from_object('brewlog.config_%s' % env)
except ImportStringError:
# module is not importable
pass
if os.environ.get('BREWLOG_CONFIG_LOCAL'):
app.config.from_envvar('BREWLOG_CONFIG_LOCAL')
if os.environ.get('BREWLOG_CONFIG_SECRETS'):
app.config.from_envvar('BREWLOG_CONFIG_SECRETS')
if app.config['DEBUG']:
@app.route('/favicon.ico')
def favicon():
Expand Down Expand Up @@ -99,8 +102,22 @@ def configure_auth(app, env):
pass


def configure_logging(app, env):
pass
def configure_logging():
dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default'
}},
'root': {
'level': 'INFO',
'handlers': ['wsgi']
}
})


def configure_error_handlers(app, env):
Expand Down
11 changes: 11 additions & 0 deletions conf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Configuration files

Adapt these to your setup.

## brewlog.2019.conf

Upstart configuration file. On Ubuntu 14.04 it goes to `/etc/init`.

## brewlog.2019.ini

uWSGI configuration file. Place it where it's set in service startup script.
13 changes: 13 additions & 0 deletions conf/brewlog.2019.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
description "uWSGI service for brewlog (2019)"

start on runlevel [2345]
stop on runlevel [!2345]

setuid jarek
setgid www-data

env PATH=/home/jarek/brewlog.2019/_venv/bin
env BREWLOG_CONFIG_LOCAL=/home/jarek/brewlog.2019/config/config_local.py
env BREWLOG_CONFIG_SECRETS=/home/jarek/brewlog.2019/config/secrets.py
chdir /home/jarek/brewlog.2019/brewlog
exec uwsgi --ini brewlog.2019.ini
18 changes: 0 additions & 18 deletions tests/factories.py

This file was deleted.

0 comments on commit af13535

Please sign in to comment.