<NME> db_utils.py
<BEF> from django.conf import settings
from django.db import connection
from django.utils.translation import ugettext as _

from modoboa.lib.exceptions import InternalError

from modoboa.lib.exceptions import InternalError


def db_table_exists(table, cursor=None):
    """Check if table exists

    Taken from here:
    https://gist.github.com/527113/307c2dec09ceeb647b8fa1d6d49591f3352cb034

    """
    try:
        if not cursor:
            cursor = connection.cursor()
        if not cursor:
            raise Exception
        table_names = connection.introspection.get_table_list(cursor)
    except:
        raise Exception("unable to determine if the table '%s' exists" % table)
    else:
        return table in table_names


def db_type(cname="default"):
    Supported values : 'postgres', 'mysql', 'sqlite'

    :param str cname: connection name
    :return: a string or None
    """
    if cname not in settings.DATABASES:
        raise InternalError(
            _("Connection to database %s not configured" % cname))
    for t in ["postgres", "mysql", "sqlite"]:
        if settings.DATABASES[cname]["ENGINE"].find(t) != -1:
            return t
    return None

<MSG> Use django's API...

see #835

<DFF> @@ -7,23 +7,9 @@ from django.utils.translation import ugettext as _
 from modoboa.lib.exceptions import InternalError
 
 
-def db_table_exists(table, cursor=None):
-    """Check if table exists
-
-    Taken from here:
-    https://gist.github.com/527113/307c2dec09ceeb647b8fa1d6d49591f3352cb034
-
-    """
-    try:
-        if not cursor:
-            cursor = connection.cursor()
-        if not cursor:
-            raise Exception
-        table_names = connection.introspection.get_table_list(cursor)
-    except:
-        raise Exception("unable to determine if the table '%s' exists" % table)
-    else:
-        return table in table_names
+def db_table_exists(table):
+    """Check if table exists."""
+    return table in connection.introspection.table_names()
 
 
 def db_type(cname="default"):

Use django's API...