imip-agent

imiptools/stores/database/postgresql.py

1309:644b7e259059
2017-10-14 Paul Boddie Support BCC sending suppression so that routines requesting it can still be used with senders that will not support it, usually because there are no outgoing routing destinations for those senders.
     1 #!/usr/bin/env python     2      3 """     4 A PostgreSQL database store of calendar data.     5      6 Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>     7      8 This program is free software; you can redistribute it and/or modify it under     9 the terms of the GNU General Public License as published by the Free Software    10 Foundation; either version 3 of the License, or (at your option) any later    11 version.    12     13 This program is distributed in the hope that it will be useful, but WITHOUT    14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    15 FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more    16 details.    17     18 You should have received a copy of the GNU General Public License along with    19 this program.  If not, see <http://www.gnu.org/licenses/>.    20 """    21     22 from imiptools.config import settings    23 from imiptools.stores.database.common import DatabaseStore, DatabaseJournal    24 import psycopg2    25     26 STORE_DIR = settings["STORE_DIR"]    27 JOURNAL_DIR = settings["JOURNAL_DIR"]    28     29 class Store(DatabaseStore):    30     31     "A PostgreSQL database store of calendar objects and free/busy data."    32     33     def __init__(self, store_dir=None):    34     35         "Interpret 'store_dir' as a connection string."    36     37         connection = psycopg2.connect(store_dir or STORE_DIR)    38         connection.autocommit = True    39         DatabaseStore.__init__(self, connection, psycopg2.paramstyle)    40     41     def acquire_lock(self, user, timeout=None):    42         query = "select pg_advisory_lock(20160311)"    43         self.cursor.execute(query)    44     45     def release_lock(self, user):    46         query = "select pg_advisory_unlock(20160311)"    47         self.cursor.execute(query)    48     49 class Journal(DatabaseJournal):    50     51     "A PostgreSQL journal system supporting quotas."    52     53     def __init__(self, store_dir=None):    54     55         "Interpret 'store_dir' as a connection string."    56     57         connection = psycopg2.connect(store_dir or JOURNAL_DIR)    58         connection.autocommit = True    59         DatabaseJournal.__init__(self, connection, psycopg2.paramstyle)    60     61     def acquire_lock(self, user, timeout=None):    62         query = "select pg_advisory_lock(20160312)"    63         self.cursor.execute(query)    64     65     def release_lock(self, user):    66         query = "select pg_advisory_unlock(20160312)"    67         self.cursor.execute(query)    68     69 # vim: tabstop=4 expandtab shiftwidth=4