Skip to content

Instantly share code, notes, and snippets.

@iromli
Created January 2, 2014 19:52
Show Gist options
  • Save iromli/8225482 to your computer and use it in GitHub Desktop.
Save iromli/8225482 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import rawes
class Elastic(object):
def __init__(self, app=None):
if app is not None:
self.init_app(app)
else:
self.app = None
def init_app(self, app):
app.config.setdefault('RAWES_URL', 'http://localhost:9200')
app.config.setdefault('RAWES_PATH', '')
app.config.setdefault('RAWES_TIMEOUT', 30)
if not hasattr(app, 'extensions'):
app.extensions = {}
app.extensions['elastic'] = rawes.Elastic(
url=app.config['RAWES_URL'],
path=app.config['RAWES_PATH'],
timeout=app.config['RAWES_TIMEOUT'],
)
self.app = app
def __getattr__(self, name):
if self.app is None:
raise RuntimeError(
'application not registered on elastic instance')
return getattr(self.app.extensions['elastic'], name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment