Changeset: ca312fdd89ef for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ca312fdd89ef
Modified Files:
        clients/python/monetdb/control.py
        clients/python/monetdb/mapi.py
Branch: default
Log Message:

added support status command


diffs (83 lines):

diff --git a/clients/python/monetdb/control.py 
b/clients/python/monetdb/control.py
--- a/clients/python/monetdb/control.py
+++ b/clients/python/monetdb/control.py
@@ -1,12 +1,34 @@
 
 from monetdb import mapi
 
+def parse_statusline(line):
+    split = line.split(',')
+    info = {}
+    info['path'] = split[0]
+    info['name'] = info['path'].split("/")[-1]
+    info['locked'] = True if split[1] == ("1") else False
+    info['state'] = int(split[2])
+    info['scenarios'] = split[3].split("'")
+    info['connections'] = split[4].split("'")
+    info['start_counter'] = int(split[5])
+    info['stop_counter'] = int(split[6])
+    info['crash_counter'] = int(split[7])
+    info['avg_uptime'] = int(split[8])
+    info['max_uptime'] = int(split[9])
+    info['min_uptime'] = int(split[10])
+    info['last_crash'] = int(split[11])
+    info['lastStart'] = int(split[12])
+    info['crash_avg1'] = True if split[1] == ("1") else False
+    info['crash_avg10'] = float(split[14])
+    info['crash_avg30'] = float(split[15])
+    return info
+
 class Control:
     def __init__(self, hostname, port, passphrase):
         self.server = mapi.Server()
         self.server.connect(hostname, port, 'monetdb', passphrase, 
'merovingian', 'control')
 
-    def _send_command(self, database_name, command, has_output=False):
+    def _send_command(self, database_name, command):
         return self.server.cmd("%s %s\n" % (database_name, command))
 
     def create(self, database_name):
@@ -22,7 +44,12 @@ class Control:
         return self._send_command(database_name, "release")
 
     def status(self, database_name):
-        return self._send_command(database_name, "status", True)
+        raw = self._send_command(database_name, "status")
+        return parse_statusline(raw)
+
+    def statuses(self):
+        raw = self._send_command("#all", "status")
+        return [parse_statusline(line) for line in raw.split("\n")]
 
     def start(self, database_name):
         return self._send_command(database_name, "start")
@@ -39,7 +66,7 @@ class Control:
     def get(self, database_name):
         properties = self._send_command(database_name, "get")
         values = {}
-        for dirty_line in properties.split("\n")[1:]:
+        for dirty_line in properties.split("\n"):
             line = dirty_line[1:]
             if not line.startswith("#"):
                 if "=" in line:
diff --git a/clients/python/monetdb/mapi.py b/clients/python/monetdb/mapi.py
--- a/clients/python/monetdb/mapi.py
+++ b/clients/python/monetdb/mapi.py
@@ -106,7 +106,6 @@ class Server(object):
             # Empty response, server is happy
             pass
         elif prompt == MSG_OK:
-            # New behaviour, I think it is something good
             pass
         elif prompt.startswith(MSG_INFO):
             logger.info("II %s" % prompt[1:])
@@ -166,8 +165,7 @@ class Server(object):
         if not len(response):
             return True
         elif response.startswith(MSG_OK):
-            # New behaviour, I think it is something good
-            return response.strip()
+            return response[3:].strip() or True
         if response == MSG_MORE:
             # tell server it isn't going to get more
             return self.cmd("")
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to