Dropped pyPgSQL support. v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Sun, 10 Feb 2013 17:33:38 +0000
branchv0.7.x
changeset 694 b1bfd4d1d9c0
parent 693 2e19ab98118a
child 695 42addf4f2434
Dropped pyPgSQL support.
VirtualMailManager/account.py
VirtualMailManager/aliasdomain.py
VirtualMailManager/cli/main.py
VirtualMailManager/config.py
VirtualMailManager/domain.py
VirtualMailManager/emailaddress.py
VirtualMailManager/handler.py
VirtualMailManager/maillocation.py
VirtualMailManager/quotalimit.py
VirtualMailManager/serviceset.py
VirtualMailManager/transport.py
doc/web/source/_static/vmm.cfg
man/man5/vmm.cfg.5
pgsql/set-permissions.py
vmm.cfg
--- a/VirtualMailManager/account.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/account.py	Sun Feb 10 17:33:38 2013 +0000
@@ -43,7 +43,7 @@
 
         Arguments:
 
-        `dbh` : pyPgSQL.PgSQL.Connection
+        `dbh` : psycopg2._psycopg.connection
           A database connection for the database access.
         `address` : VirtualMailManager.EmailAddress.EmailAddress
           The e-mail address of the (new) Account.
@@ -459,7 +459,7 @@
 
     `uid` : int
       The Account unique ID.
-    `dbh` : pyPgSQL.PgSQL.Connection
+    `dbh` : psycopg2._psycopg.connection
       a database connection for the database access.
     """
     try:
--- a/VirtualMailManager/aliasdomain.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/aliasdomain.py	Sun Feb 10 17:33:38 2013 +0000
@@ -27,7 +27,7 @@
 
         Arguments:
 
-        `dbh` : pyPgSQL.PgSQL.Connection
+        `dbh` : psycopg2._psycopg.connection
           a database connection for the database access
         `domainname` : basestring
           the name of the AliasDomain"""
--- a/VirtualMailManager/cli/main.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/cli/main.py	Sun Feb 10 17:33:38 2013 +0000
@@ -14,8 +14,8 @@
 from VirtualMailManager.config import BadOptionError, ConfigValueError
 from VirtualMailManager.cli import w_err
 from VirtualMailManager.cli.handler import CliHandler
-from VirtualMailManager.constants import DATABASE_ERROR, EX_SUCCESS, \
-     EX_USER_INTERRUPT, INVALID_ARGUMENT
+from VirtualMailManager.constants import EX_SUCCESS, EX_USER_INTERRUPT, \
+     INVALID_ARGUMENT
 from VirtualMailManager.cli.subcommands import RunContext, setup_parser
 
 
@@ -46,11 +46,9 @@
         # with Ctrl+C or Ctrl+D.
         w_err(EX_USER_INTERRUPT, '', _('Ouch!'), '')
     except errors.VMMError as err:
-        if err.code != DATABASE_ERROR:
-            if handler.has_warnings():
-                w_err(0, _('Warnings:'), *handler.get_warnings())
-            w_err(err.code, _('Error: %s') % err.msg)
-        w_err(err.code, str(err.msg, ENCODING, 'replace'))
+        if handler.has_warnings():
+            w_err(0, _('Warnings:'), *handler.get_warnings())
+        w_err(err.code, _('Error: %s') % err.msg)
     except (BadOptionError, ConfigValueError) as err:
         w_err(INVALID_ARGUMENT, _('Error: %s') % err)
     except NoSectionError as err:
--- a/VirtualMailManager/config.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/config.py	Sun Feb 10 17:33:38 2013 +0000
@@ -22,7 +22,6 @@
 from VirtualMailManager.maillocation import known_format
 from VirtualMailManager.password import verify_scheme as _verify_scheme
 
-DB_MODULES = ('psycopg2', 'pypgsql')
 DB_SSL_MODES = ('allow', 'disabled', 'prefer', 'require', 'verify-ca',
                 'verify-full')
 
@@ -313,7 +312,6 @@
             },
             'database': {
                 'host': LCO(str, 'localhost', self.get),
-                'module': LCO(str, 'psycopg2', self.get, check_db_module),
                 'name': LCO(str, 'mailsys', self.get),
                 'pass': LCO(str, None, self.get),
                 'port': LCO(int, 5432, self.getint),
@@ -437,15 +435,10 @@
                         _("Not a valid Dovecot version: '%s'") % value]
         # section database
         db_err = []
-        value = self.dget('database.module').lower()
-        if value not in DB_MODULES:
-            db_err.append('module: ' +
-                          _("Unsupported database module: '%s'") % value)
-        if value == 'psycopg2':
-            value = self.dget('database.sslmode')
-            if value not in DB_SSL_MODES:
-                db_err.append('sslmode: ' +
-                              _("Unknown pgsql SSL mode: '%s'") % value)
+        value = self.dget('database.sslmode')
+        if value not in DB_SSL_MODES:
+            db_err.append('sslmode: ' +
+                          _("Unknown pgsql SSL mode: '%s'") % value)
         if db_err:
             self._missing['database'] = db_err
         # section mailbox
@@ -471,14 +464,6 @@
     raise ConfigValueError(_("No such directory: %s") % get_unicode(path))
 
 
-def check_db_module(module):
-    """Check if the *module* is a supported pgsql module."""
-    if module.lower() in DB_MODULES:
-        return module
-    raise ConfigValueError(_("Unsupported database module: '%s'") %
-                           get_unicode(module))
-
-
 def check_db_ssl_mode(ssl_mode):
     """Check if the *ssl_mode* is one of the SSL modes, known by pgsql."""
     if ssl_mode in DB_SSL_MODES:
--- a/VirtualMailManager/domain.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/domain.py	Sun Feb 10 17:33:38 2013 +0000
@@ -46,7 +46,7 @@
 
         Arguments:
 
-        `dbh` : pyPgSQL.PgSQL.Connection
+        `dbh` : psycopg2._psycopg.connection
           a database connection for the database access
         `domainname` : basestring
           The name of the domain
--- a/VirtualMailManager/emailaddress.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/emailaddress.py	Sun Feb 10 17:33:38 2013 +0000
@@ -97,7 +97,7 @@
 
         `address`: string/unicode
           a e-mail address like user@example.com
-        `dbh`: pyPgSQL.PgSQL.Connection/pyPgSQL.PgSQL.connection
+        `dbh`: psycopg2._psycopg.connection
           a database connection for the database access
         """
         super(DestinationEmailAddress, self).__init__(address, _validate)
--- a/VirtualMailManager/handler.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/handler.py	Sun Feb 10 17:33:38 2013 +0000
@@ -19,6 +19,8 @@
 from stat import S_IRGRP, S_IROTH, S_IWGRP, S_IWOTH
 from subprocess import Popen, PIPE
 
+import psycopg2
+
 from VirtualMailManager.account import Account
 from VirtualMailManager.alias import Alias
 from VirtualMailManager.aliasdomain import AliasDomain
@@ -45,7 +47,6 @@
 
 
 _ = lambda msg: msg
-_db_mod = None
 
 CFG_FILE = 'vmm.cfg'
 CFG_PATH = '/root:/usr/local/etc:/etc'
@@ -60,7 +61,7 @@
 class Handler(object):
     """Wrapper class to simplify the access on all the stuff from
     VirtualMailManager"""
-    __slots__ = ('_cfg', '_cfg_fname', '_db_connect', '_dbh', '_warnings')
+    __slots__ = ('_cfg', '_cfg_fname', '_dbh', '_warnings')
 
     def __init__(self, skip_some_checks=False):
         """Creates a new Handler instance.
@@ -76,7 +77,6 @@
         self._warnings = []
         self._cfg = None
         self._dbh = None
-        self._db_connect = None
 
         if os.geteuid():
             raise NotRootError(_("You are not root.\n\tGood bye!\n"),
@@ -87,7 +87,6 @@
         if not skip_some_checks:
             self._cfg.check()
             self._chkenv()
-            self._set_db_connect()
 
     def _find_cfg_file(self):
         """Search the CFG_FILE in CFG_PATH.
@@ -149,50 +148,13 @@
                 else:
                     raise
 
-    def _set_db_connect(self):
-        """check which module to use and set self._db_connect"""
-        global _db_mod
-        if self._cfg.dget('database.module').lower() == 'psycopg2':
-            try:
-                _db_mod = __import__('psycopg2')
-            except ImportError:
-                raise VMMError(_("Unable to import database module '%s'.") %
-                               'psycopg2', VMM_ERROR)
-            self._db_connect = self._psycopg2_connect
-        else:
-            try:
-                tmp = __import__('pyPgSQL', globals(), locals(), ['PgSQL'])
-            except ImportError:
-                raise VMMError(_("Unable to import database module '%s'.") %
-                               'pyPgSQL', VMM_ERROR)
-            _db_mod = tmp.PgSQL
-            self._db_connect = self._pypgsql_connect
-
-    def _pypgsql_connect(self):
-        """Creates a pyPgSQL.PgSQL.connection instance."""
-        if self._dbh is None or (isinstance(self._dbh, _db_mod.Connection) and
-                                  not self._dbh._isOpen):
-            try:
-                self._dbh = _db_mod.connect(
-                        database=self._cfg.dget('database.name'),
-                        user=self._cfg.pget('database.user'),
-                        host=self._cfg.dget('database.host'),
-                        port=self._cfg.dget('database.port'),
-                        password=self._cfg.pget('database.pass'),
-                        client_encoding='utf8', unicode_results=True)
-                dbc = self._dbh.cursor()
-                dbc.execute("SET NAMES 'UTF8'")
-                dbc.close()
-            except _db_mod.libpq.DatabaseError as err:
-                raise VMMError(str(err), DATABASE_ERROR)
-
-    def _psycopg2_connect(self):
+    def _db_connect(self):
         """Return a new psycopg2 connection object."""
         if self._dbh is None or \
-          (isinstance(self._dbh, _db_mod.extensions.connection) and
+          (isinstance(self._dbh, psycopg2.extensions.connection) and
            self._dbh.closed):
             try:
-                self._dbh = _db_mod.connect(
+                self._dbh = psycopg2.connect(
                         host=self._cfg.dget('database.host'),
                         sslmode=self._cfg.dget('database.sslmode'),
                         port=self._cfg.dget('database.port'),
@@ -203,7 +165,7 @@
                 dbc = self._dbh.cursor()
                 dbc.execute("SET NAMES 'UTF8'")
                 dbc.close()
-            except _db_mod.DatabaseError as err:
+            except psycopg2.DatabaseError as err:
                 raise VMMError(str(err), DATABASE_ERROR)
 
     def _chk_other_address_types(self, address, exclude):
--- a/VirtualMailManager/maillocation.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/maillocation.py	Sun Feb 10 17:33:38 2013 +0000
@@ -37,7 +37,7 @@
 
         Arguments:
 
-        `dbh` : pyPgSQL.PgSQL.Connection
+        `dbh` : psycopg2._psycopg.connection
           A database connection for the database access.
 
         Keyword arguments:
--- a/VirtualMailManager/quotalimit.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/quotalimit.py	Sun Feb 10 17:33:38 2013 +0000
@@ -25,7 +25,7 @@
 
         Arguments:
 
-        `dbh` : pyPgSQL.PgSQL.Connection || psycopg2._psycopg.connection
+        `dbh` : psycopg2._psycopg.connection
           A database connection for the database access.
 
         Keyword arguments:
--- a/VirtualMailManager/serviceset.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/serviceset.py	Sun Feb 10 17:33:38 2013 +0000
@@ -42,7 +42,7 @@
         arguments ('smtp', 'pop3',  'imap', 'sieve') must be provided.
 
         Arguments:
-        `dbh` : pyPgSQL.PgSQL.Connection or psycopg2.extensions.connection
+        `dbh` : psycopg2.extensions.connection
           A database connection for the database access.
 
         Keyword arguments:
@@ -123,9 +123,7 @@
         if not result:
             raise ValueError('Unknown service_set id specified: %r' % ssid)
         self._ssid = result[0]
-        #self._services.update(zip(SERVICES, result[1:]))
-        for key, value in zip(SERVICES, result[1:]):  # pyPgSQL compatible
-            self._services[key] = True if value else False
+        self._services.update(list(zip(SERVICES, result[1:])))
 
     def _save(self):
         """Store a new service_set in the database."""
--- a/VirtualMailManager/transport.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/VirtualMailManager/transport.py	Sun Feb 10 17:33:38 2013 +0000
@@ -23,7 +23,7 @@
         are given, tid will be used.
 
         Keyword arguments:
-        dbh -- a pyPgSQL.PgSQL.connection
+        dbh -- a psycopg2._psycopg.connection
         tid -- the id of a transport (int)
         transport -- the value of the transport (str)
 
--- a/doc/web/source/_static/vmm.cfg	Sat Feb 09 17:24:12 2013 +0000
+++ b/doc/web/source/_static/vmm.cfg	Sun Feb 10 17:33:38 2013 +0000
@@ -6,11 +6,6 @@
 # Database settings
 #
 [database]
-; The Python PostgreSQL database adapter module to be used (String)
-; Supported modules are:
-;    * psycopg2
-;    * pyPgSQL
-module = psycopg2
 ; Hostname or IP address of the database server (String)
 host = localhost
 ; The TCP port, on which the database server is listening for connections (Int)
--- a/man/man5/vmm.cfg.5	Sat Feb 09 17:24:12 2013 +0000
+++ b/man/man5/vmm.cfg.5	Sun Feb 10 17:33:38 2013 +0000
@@ -1,4 +1,4 @@
-.TH "VMM.CFG" "5" "2012-08-12" "vmm 0.6" "vmm"
+.TH "VMM.CFG" "5" "2013-02-10" "vmm 0.7" "vmm"
 .SH NAME
 vmm.cfg \- configuration file for vmm
 .\" -----------------------------------------------------------------------
@@ -231,14 +231,6 @@
 .PP
 Hostname or IP address of the database server.
 .\" ------------------------------------
-.SS database.module
-.BR module " (default: psycopg2) :"
-.I String
-.PP
-The Python PostgreSQL database adapter module to be used.
-Supported modules are
-.BR psycopg2 " and " pyPgSQL .
-.\" ------------------------------------
 .SS database.name
 .BR name " (default: mailsys) :"
 .I String
@@ -269,11 +261,6 @@
 The modes
 .BR verify\-ca " and " verify\-full
 are available since PostgreSQL 8.4
-.PP
-This setting will be ignored when the
-.I database.module
-is set to
-.BR pyPgSQL .
 .\" ------------------------------------
 .SS database.user
 .BR user " (default: " None ") :"
--- a/pgsql/set-permissions.py	Sat Feb 09 17:24:12 2013 +0000
+++ b/pgsql/set-permissions.py	Sun Feb 10 17:33:38 2013 +0000
@@ -15,21 +15,7 @@
 
 from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
 
-has_psycopg2 = False
-try:
-    import psycopg2
-    has_psycopg2 = True
-except ImportError:
-    try:
-        from pyPgSQL import PgSQL
-    except ImportError:
-        sys.stderr.write('error: no suitable database module found\n')
-        raise SystemExit(1)
-
-if has_psycopg2:
-    DBErr = psycopg2.DatabaseError
-else:
-    DBErr = PgSQL.libpq.DatabaseError
+import psycopg2
 
 
 def check_args(args, err_hdlr):
@@ -42,11 +28,8 @@
 
 
 def get_dbh(database, user, password, host, port):
-    if has_psycopg2:
-        return psycopg2.connect(database=database, user=user,
-                                password=password, host=host, port=port)
-    return PgSQL.connect(user=user, password=password, host=host,
-                         database=database, port=port)
+    return psycopg2.connect(database=database, user=user,
+                            password=password, host=host, port=port)
 
 
 def get_argparser():
@@ -131,7 +114,7 @@
         try:
             dbc.execute("SELECT current_setting('server_version_num')")
             versions['pgsql'] = int(dbc.fetchone()[0])
-        except DBErr:
+        except psycopg2.DatabaseError:
             versions['pgsql'] = 80199
     dbc.execute("SELECT relname FROM pg_stat_user_tables WHERE relname LIKE "
                 "'userquota%'")
--- a/vmm.cfg	Sat Feb 09 17:24:12 2013 +0000
+++ b/vmm.cfg	Sun Feb 10 17:33:38 2013 +0000
@@ -6,11 +6,6 @@
 # Database settings
 #
 [database]
-; The Python PostgreSQL database adapter module to be used (String)
-; Supported modules are:
-;    * psycopg2
-;    * pyPgSQL
-module = psycopg2
 ; Hostname or IP address of the database server (String)
 host = localhost
 ; The TCP port, on which the database server is listening for connections (Int)