| |
@@ -1,37 +1,46 @@
|
| |
- from flask import Flask, render_template
|
| |
- from flask_fas_openid import FAS
|
| |
- from flask_sqlalchemy import SQLAlchemy
|
| |
import logging
|
| |
import logging.handlers
|
| |
import os
|
| |
|
| |
- from . import config
|
| |
+ from flask import Flask, render_template
|
| |
+ from flask_fas_openid import FAS
|
| |
+ from flask_sqlalchemy import SQLAlchemy
|
| |
|
| |
+ from . import config
|
| |
from .util.login import FakeFas
|
| |
|
| |
# the version as used in setup.py and docs
|
| |
__version__ = "1.1.0"
|
| |
|
| |
-
|
| |
# Flask App
|
| |
app = Flask(__name__)
|
| |
-
|
| |
fas = None
|
| |
-
|
| |
# Is this an OpenShift deployment?
|
| |
openshift = os.getenv('OPENSHIFT_PROD')
|
| |
|
| |
+ # set up basic logging so that initial messages are not lost (until we
|
| |
+ # configure logging properly)
|
| |
+ _logging_fmt = '[%(name)-15s] %(asctime)s %(levelname)-7s %(message)s'
|
| |
+ _logging_fmt_debug = '[%(name)-23s:%(lineno)-3d] %(asctime)s %(levelname)-7s %(message)s'
|
| |
+ _logging_datefmt = '%Y-%m-%d %H:%M:%S'
|
| |
+ logging.basicConfig(format=_logging_fmt_debug, datefmt=_logging_datefmt)
|
| |
+ logging.getLogger().setLevel(logging.DEBUG)
|
| |
+
|
| |
# load default configuration
|
| |
if os.getenv('DEV') == 'true':
|
| |
+ app.logger.debug('Using development config')
|
| |
app.config.from_object('blockerbugs.config.DevelopmentConfig')
|
| |
fas = FakeFas(app)
|
| |
elif os.getenv('TEST') == 'true' or openshift == "0":
|
| |
- fas = FAS(app)
|
| |
+ app.logger.debug('Using testing config')
|
| |
app.config.from_object('blockerbugs.config.TestingConfig')
|
| |
- else:
|
| |
fas = FAS(app)
|
| |
+ else:
|
| |
+ app.logger.debug('Using production config')
|
| |
app.config.from_object('blockerbugs.config.ProductionConfig')
|
| |
+ fas = FAS(app)
|
| |
if openshift:
|
| |
+ app.logger.debug('Using openshift config')
|
| |
config.openshift_config(app.config, openshift)
|
| |
|
| |
# load real configuration values to override defaults
|
| |
@@ -54,31 +63,19 @@
|
| |
|
| |
# Make sure config URLs end with a slash, so that we have them all in an
|
| |
# expected format
|
| |
- def end_with_slash(url):
|
| |
- if not url.endswith('/'):
|
| |
- return url + '/'
|
| |
- else:
|
| |
- return url
|
| |
-
|
| |
for key in ['BUGZILLA_URL', 'KOJI_URL', 'BODHI_URL', 'FAS_BASE_URL',
|
| |
- 'PAGURE_URL', 'PAGURE_API']:
|
| |
- app.config[key] = end_with_slash(app.config[key])
|
| |
-
|
| |
- # "Hotfix" for proxy handling on current deployment, my guess is that the proxy
|
| |
- # server is set differently than it was, but what do I know...
|
| |
- if app.config["BEHIND_PROXY"]:
|
| |
- from werkzeug.contrib.fixers import ProxyFix
|
| |
- app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=1)
|
| |
+ 'PAGURE_URL', 'PAGURE_API']:
|
| |
+ if not app.config[key].endswith('/'):
|
| |
+ app.config[key] = app.config[key] + '/'
|
| |
|
| |
|
| |
def setup_logging():
|
| |
- fmt = '[%(filename)s:%(lineno)d] ' if app.debug else '%(module)-12s '
|
| |
- fmt += '%(asctime)s %(levelname)-7s %(message)s'
|
| |
- datefmt = '%Y-%m-%d %H:%M:%S'
|
| |
+ formatter = logging.Formatter(
|
| |
+ fmt=_logging_fmt_debug if app.debug else _logging_fmt,
|
| |
+ datefmt=_logging_datefmt)
|
| |
loglevel = logging.DEBUG if app.debug else logging.INFO
|
| |
- formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)
|
| |
|
| |
- root_logger = logging.getLogger('')
|
| |
+ root_logger = logging.getLogger()
|
| |
root_logger.setLevel(logging.DEBUG)
|
| |
root_logger.handlers.clear()
|
| |
app.logger.handlers.clear()
|
| |
@@ -109,13 +106,19 @@
|
| |
|
| |
setup_logging()
|
| |
|
| |
+ # database
|
| |
if app.config['SHOW_DB_URI']:
|
| |
app.logger.debug('using DBURI: %s' % app.config['SQLALCHEMY_DATABASE_URI'])
|
| |
-
|
| |
- # database
|
| |
db = SQLAlchemy(app)
|
| |
|
| |
+ # "Hotfix" for proxy handling on current deployment, my guess is that the proxy
|
| |
+ # server is set differently than it was, but what do I know...
|
| |
+ if app.config["BEHIND_PROXY"]:
|
| |
+ from werkzeug.contrib.fixers import ProxyFix
|
| |
+ app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=1)
|
| |
+
|
| |
|
| |
+ # === Flask views and stuff ===
|
| |
@app.template_filter('tagify')
|
| |
def tagify(value):
|
| |
return value.replace(' ', '')
|
| |
Please see individual commits for a description.