This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail.git


The following commit(s) were added to refs/heads/master by this push:
     new 98c34fb  Add version info to elastic module
98c34fb is described below

commit 98c34fb2d6b790707fc07f4ce5017f0e2f927df4
Author: Sebb <s...@apache.org>
AuthorDate: Fri May 18 00:20:34 2018 +0100

    Add version info to elastic module
---
 CHANGELOG.md     |  1 +
 tools/elastic.py | 23 ++++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index bab7ec8..30b7d9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
 ## Changes in 0.11-SNAPSHOT
+- Add version info to elastic module
 - Bug: setup.py fails with ES2 - fielddata (#453)
 - Bug: setup.py --default should not prompt for urlPrefix (#452)
 - Bug: copy-list.py does not work (#450)
diff --git a/tools/elastic.py b/tools/elastic.py
index 2a65101..e138a3d 100755
--- a/tools/elastic.py
+++ b/tools/elastic.py
@@ -26,6 +26,7 @@ import logging
 
 try:
     from elasticsearch import Elasticsearch, helpers
+    from elasticsearch import VERSION as ES_VERSION
 except Exception as e:
     sys.exit("Sorry, you need to install the elasticsearch module from pip 
first. (%s)" % str(e))
 
@@ -63,7 +64,20 @@ class Elastic:
             max_retries=5,
             retry_on_timeout=True
             )
-    
+        self.dbVersion = None
+
+    def libraryVersion(self):
+        return ES_VERSION
+    def libraryMajor(self):
+        return ES_VERSION[0]
+
+    def engineVersion(self):
+        if not self.dbVersion:
+            self.dbVersion = self.info()['version']['number']
+        return self.dbVersion
+    def engineMajor(self):
+        return int(self.engineVersion().split('.')[0])
+        
     def search(self, doc_type='mbox', **kwargs):
         return self.es.search(
             index=self.dbname,
@@ -96,6 +110,9 @@ class Elastic:
     def scroll(self, **kwargs):
         return self.es.scroll(**kwargs)
     
+    def info(self, **kwargs):
+        return self.es.info(**kwargs)
+
     def bulk(self, actions, **kwargs):
         return helpers.bulk(self.es, actions, **kwargs)
 
@@ -108,3 +125,7 @@ class Elastic:
     """
     def clear_scroll(self, *args, **kwargs):
         return self.es.clear_scroll(*args, **kwargs)
+
+if __name__ == '__main__':
+    es = Elastic()
+    print("Versions: Library: %d %s Engine: %d (%s)" % (es.libraryMajor(), 
es.libraryVersion(), es.engineMajor(), es.engineVersion()))
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
s...@apache.org.

Reply via email to