Changeset: 1dd6543e3d25 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1dd6543e3d25
Added Files:
        clients/python3/MANIFEST.in
        clients/python3/monetdb/control.py
        clients/python3/test/test_control.py
Modified Files:
        clients/python3/Makefile.ag
        clients/python3/README.rst
        clients/python3/examples/mclient.py
        clients/python3/examples/perf.py
        clients/python3/monetdb/__init__.py
        clients/python3/monetdb/exceptions.py
        clients/python3/monetdb/mapi.py
        clients/python3/monetdb/sql/connections.py
        clients/python3/monetdb/sql/converters.py
        clients/python3/monetdb/sql/cursors.py
        clients/python3/monetdb/sql/monetize.py
        clients/python3/monetdb/sql/pythonize.py
        clients/python3/monetdb/sql/types.py
        clients/python3/setup.py
        clients/python3/test/capabilities.py
        clients/python3/test/dbapi20.py
        clients/python3/test/run.sh
        clients/python3/test/runtests.py
Branch: default
Log Message:

sync python3 code with python2 using 2to3


diffs (truncated from 1383 to 300 lines):

diff --git a/clients/python3/MANIFEST.in b/clients/python3/MANIFEST.in
new file mode 100644
--- /dev/null
+++ b/clients/python3/MANIFEST.in
@@ -0,0 +1,13 @@
+include monetdb/exceptions.py
+include monetdb/sql/pythonize.py
+include monetdb/sql/connections.py
+include monetdb/sql/converters.py
+include monetdb/sql/types.py
+include monetdb/sql/monetize.py
+include monetdb/sql/cursors.py
+include monetdb/sql/__init__.py
+include monetdb/mapi.py
+include monetdb/__init__.py
+include README.rst
+include setup.py
+
diff --git a/clients/python3/Makefile.ag b/clients/python3/Makefile.ag
--- a/clients/python3/Makefile.ag
+++ b/clients/python3/Makefile.ag
@@ -15,7 +15,7 @@
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
 
-python3_setup = {
+python_setup = {
        FILES = setup.py
 }
 
diff --git a/clients/python3/README.rst b/clients/python3/README.rst
--- a/clients/python3/README.rst
+++ b/clients/python3/README.rst
@@ -3,16 +3,16 @@
    Use ``rst2html.py`` to convert this file to HTML.
 
 ==========================================
-The MonetDB MAPI and SQL client python3 API
+The MonetDB MAPI and SQL client python API
 ==========================================
 
 
 Introduction
 ============
 
-This is the native python3 client API.  This API is cross-platform,
+This is the new native python client API.  This API is cross-platform,
 and doesn't depend on any monetdb libraries.  It has support for
-python 3.0+ and is Python DBAPI 2.0 compatible.
+python 2.5+ and is Python DBAPI 2.0 compatible.
 
 
 Installation
diff --git a/clients/python3/examples/mclient.py 
b/clients/python3/examples/mclient.py
--- a/clients/python3/examples/mclient.py
+++ b/clients/python3/examples/mclient.py
@@ -17,6 +17,8 @@
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
 
+#
+
 import sys
 import getopt
 
@@ -28,11 +30,12 @@ def main() :
     username = 'monetdb'
     password = 'monetdb'
     language = 'sql'
-    database = 'demo'
+    database = ''
+    encoding = None
 
     opts, args = getopt.getopt(sys.argv[1:], '',
-           ['host=', 'port=', 'user=', 'passwd=', 'language=', 'database='])
-
+                               ['host=', 'port=', 'user=', 'passwd=',
+                                'language=', 'database=', 'encoding='])
     for o, a in opts:
         if o == '--host':
             hostname = a
@@ -46,27 +49,42 @@ def main() :
             language = a
         elif o == '--database':
             database = a
+        elif o == '--encoding':
+            encoding = a
+
+    if encoding is None:
+        import locale
+        encoding = locale.getlocale()[1]
+        if encoding is None:
+            encoding = locale.getdefaultlocale()[1]
 
     s = mapi.Server()
+
     s.connect(hostname = hostname,
               port = int(port),
               username = username,
               password = password,
               language = language,
               database = database)
-    print("#mclient (python) connected to %s:%d as %s" %
-          (hostname, int(port), username))
+    print("#mclient (python) connected to %s:%d as %s" % (hostname, int(port), 
username))
     fi = sys.stdin
     prompt = '%s>' % language
-    sys.stdout.write(prompt)
+
+    sys.stdout.write(prompt.encode('utf-8'))
     line = fi.readline()
+    if encoding != 'utf-8':
+        prompt = str(prompt, 'utf-8').encode(encoding, 'replace')
     while line and line != "\q\n":
+        if encoding != 'utf-8':
+            line = str(line, encoding).encode('utf-8')
         res = s.cmd('s' + line)
+        if encoding != 'utf-8':
+            res = str(res, 'utf-8').encode(encoding, 'replace')
         print(res)
         sys.stdout.write(prompt)
         line = fi.readline()
+
     s.disconnect()
 
 if __name__ == "__main__":
     main()
-
diff --git a/clients/python3/examples/perf.py b/clients/python3/examples/perf.py
--- a/clients/python3/examples/perf.py
+++ b/clients/python3/examples/perf.py
@@ -34,11 +34,9 @@ except ImportError:
     sys.path.append(parent)
     import monetdb.sql
 
-for i in (10, 100, 1000, 10000):
-    t = time.time()
-    x = monetdb.sql.connect(database="demo")
-    c = x.cursor()
-    c.arraysize=i
-    c.execute('select * from tables, tables, tables')
-    results = c.fetchall()
-    print i, time.time() - t
+t = time.time()
+x = monetdb.sql.connect(database="demo")
+c = x.cursor()
+c.arraysize=10000
+c.execute('select * from tables, tables')
+results = c.fetchall()
diff --git a/clients/python3/monetdb/__init__.py 
b/clients/python3/monetdb/__init__.py
--- a/clients/python3/monetdb/__init__.py
+++ b/clients/python3/monetdb/__init__.py
@@ -14,7 +14,6 @@
 # Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
-
 """
 This is the MonetDB Python API.
 
@@ -27,7 +26,10 @@ To set up a connection use monetdb.sql.c
 """
 from monetdb import sql
 from monetdb import mapi
+from monetdb import exceptions
 
 __all__ = ["sql", "mapi"]
 
-connect = sql.connect
\ No newline at end of file
+# for backwards compatability
+monetdb_exceptions = exceptions
+
diff --git a/clients/python3/monetdb/control.py 
b/clients/python3/monetdb/control.py
new file mode 100644
--- /dev/null
+++ b/clients/python3/monetdb/control.py
@@ -0,0 +1,144 @@
+
+from monetdb import mapi
+
+def parse_statusline(line):
+    split = line.split(',')
+    info = {}
+    info['path'] = split[0]
+    info['name'] = info['path'].split("/")[-1]
+    info['locked'] = split[1] == ("1")
+    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'] = split[13] == ("1")
+    info['crash_avg10'] = float(split[14])
+    info['crash_avg30'] = float(split[15])
+    return info
+
+class Control:
+    """
+    Use this module to manage your MonetDB databases. You can create, start, 
stop,
+    lock, unlock, destroy your databases and request status information.
+    """
+    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):
+        return self.server.cmd("%s %s\n" % (database_name, command))
+
+    def create(self, database_name):
+        """
+        Initialises a new database or multiplexfunnel in the MonetDB Server.
+        A database created with this command makes it available  for use,
+        however in maintenance mode (see monetdb lock).
+        """
+        return self._send_command(database_name, "create")
+
+    def destroy(self, database_name):
+        """
+        Removes the given database, including all its data and
+        logfiles.  Once destroy has completed, all data is lost.
+        Be careful when using this command.
+        """
+        return self._send_command(database_name, "destroy")
+
+    def lock(self, database_name):
+        """
+        Puts the given database in maintenance mode.  A database
+        under maintenance can only be connected to by the DBA.
+        A database which is under maintenance is not started
+        automatically.  Use the "release" command to bring
+        the database back for normal usage.
+        """
+        return self._send_command(database_name, "lock")
+
+    def release(self, database_name):
+        """
+        Brings back a database from maintenance mode.  A released
+        database is available again for normal use.  Use the
+        "lock" command to take a database under maintenance.
+        """
+        return self._send_command(database_name, "release")
+
+    def status(self, database_name=False):
+        """
+        Shows the state of a given glob-style database match, or
+        all known if none given.  Instead of the normal mode, a
+        long and crash mode control what information is displayed.
+        """
+        if database_name:
+            raw = self._send_command(database_name, "status")
+            return parse_statusline(raw)
+        else:
+            raw = self._send_command("#all", "status")
+            return [parse_statusline(line) for line in raw.split("\n")]
+
+    def start(self, database_name):
+        """
+        Starts the given database, if the MonetDB Database Server
+        is running.
+        """
+        return self._send_command(database_name, "start")
+
+    def stop(self, database_name):
+        """
+        Stops the given database, if the MonetDB Database Server
+        is running.
+        """
+        return self._send_command(database_name, "stop")
+
+    def kill(self, database_name):
+        """
+        Kills the given database, if the MonetDB Database Server
+        is running.  Note: killing a database should only be done
+        as last resort to stop a database.  A database being
+        killed may end up with data loss.
+        """
+        return self._send_command(database_name, "kill")
+
+    def set(self, database_name, property_, value):
+        """
+        sets property to value for the given database
+        for a list of properties, use `monetdb get all`
+        """
+        return self._send_command(database_name, "%s=%s" % (property_, value))
+
+    def get(self, database_name):
+        """
+        gets value for property for the given database, or
+        retrieves all properties for the given database
+        """
+        properties = self._send_command(database_name, "get")
+        values = {}
+        for dirty_line in properties.split("\n"):
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to