Merge remote-tracking branch 'origin/master' into ldapper
Conflicts: app.py
This commit is contained in:
commit
11c6c5fa52
10 changed files with 75 additions and 23 deletions
|
@ -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)
|
Reference in a new issue