blob: a09a6de8a2734eff10b058462dbf0c72b371b766 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
from . import ModuleBase
import psycopg2
class Module(ModuleBase):
def __init__(self, manager):
ModuleBase.__init__(self, manager)
self.conf = manager.config['pgsql']
self.db = False
self._connect()
def _connect(self):
if self.db:
try:
self.db.close()
except:
pass
self.db = psycopg2.connect(host = self.conf['host'], user = self.conf['user'], password = self.conf['passwd'], database = self.conf['db'])
def cursor(self):
try:
return self.db.cursor()
except psycopg2.OperationalError:
self._connect()
return self.db.cursor()
def commit(self):
self.db.commit()
|