Set up the build logs to use our fake build logs on test and local.

This commit is contained in:
Jake Moshenko 2014-05-09 18:45:11 -04:00
parent 580bb152fe
commit bcb993a914
8 changed files with 47 additions and 11 deletions

View file

@ -1,10 +1,12 @@
import redis
import json
from util.dynamic import import_class
class BuildStatusRetrievalError(Exception):
pass
class BuildLogs(object):
class RedisBuildLogs(object):
ERROR = 'error'
COMMAND = 'command'
PHASE = 'phase'
@ -70,3 +72,30 @@ class BuildLogs(object):
raise BuildStatusRetrievalError('Cannot retrieve build status')
return json.loads(fetched) if fetched else None
class BuildLogs(object):
def __init__(self, app=None):
self.app = app
if app is not None:
self.state = self.init_app(app)
else:
self.state = None
def init_app(self, app):
buildlogs_options = app.config.get('BUILDLOGS_OPTIONS', [])
buildlogs_import = app.config.get('BUILDLOGS_MODULE_AND_CLASS', None)
if buildlogs_import is None:
klass = RedisBuildLogs
else:
klass = import_class(buildlogs_import[0], buildlogs_import[1])
buildlogs = klass(*buildlogs_options)
# register extension with app
app.extensions = getattr(app, 'extensions', {})
app.extensions['buildlogs'] = buildlogs
return buildlogs
def __getattr__(self, name):
return getattr(self.state, name, None)