mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
New plugin that allows the handling of an Amavisd-new SQL quarantine. NB: a DB connections manager has been added inside the lib because Django does not support multiple connections at the same time. The main consequence is that we don't use an ORM and that we have to rewrite a small wrapper that supports several DB (mysql, postgresql, etc.). Adding a dependancy to an existing ORM module (like SQLalchemy) is heavy, we don't want that for now.
23 lines
610 B
Python
23 lines
610 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
"""
|
|
connections = {}
|
|
|
|
def mysql_newconnection(host, dbname, login, password):
|
|
import MySQLdb
|
|
return MySQLdb.connect(host=host, db=dbname, user=login, passwd=password)
|
|
|
|
def getconnection(name):
|
|
if not name in connections.keys():
|
|
from django.conf import settings
|
|
|
|
cfg = settings.DB_CONNECTIONS[name]
|
|
if cfg["driver"] == "mysql":
|
|
conn = mysql_newconnection(cfg["host"], cfg["dbname"], cfg["login"],
|
|
cfg["password"])
|
|
connections[name] = conn
|
|
return connections[name]
|
|
|