Skip to content

Commit

Permalink
We hate subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
ael-code authored and boyska committed Dec 10, 2017
1 parent 2a3299a commit d86395b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions utils/es.py
Expand Up @@ -2,22 +2,21 @@
from elasticsearch import __version__ as es_pylib_version


class Elasticsearch(Elasticsearch_official):
"""Elasticsearch wrapper class
def Elasticsearch(*args, **kwargs):
"""Elasticsearch wrapper function
Wrapper class around the official Elasticsearch class that adds
Wrapper function around the official Elasticsearch class that adds
a simple version check upon initialization.
In particular it checks if the major version of the library in use
match the one of the cluster that we are tring to interact with.
The check can be skipped by setting to false the check_version parameter.
"""

def __init__(self, check_version=True, *args, **kargs):
super(Elasticsearch, self).__init__(*args, **kargs)
if check_version:
es_version = self.get_version()
if(int(es_version[0]) != int(es_pylib_version[0])):
raise RuntimeError("The Elasticsearch python library version does not match the one of the running cluster: {} != {}. Please install the correct elasticsearch-py version".format(es_pylib_version[0], es_version[0]))
def get_version(self):
return self.info()['version']['number'].split('.')
#note: Boyska didn't like subclassing :)
"""
check_version = kwargs.pop('check_version', True)
es = Elasticsearch_official(*args, **kwargs)
if check_version:
es_version = es.info()['version']['number'].split('.')
if(int(es_version[0]) != int(es_pylib_version[0])):
raise RuntimeError("The Elasticsearch python library version does not match the one of the running cluster: {} != {}. Please install the correct elasticsearch-py version".format(es_pylib_version[0], es_version[0]))
return es

0 comments on commit d86395b

Please sign in to comment.