| Hosted by CoCalc | Download
1
# -*- coding: utf-8 -*-
2
3
r"""
4
Authorization interface to SQL database via Psycopg2.
5
For use with bent_function_cayley_graph_dashboard.py and similar.
6
7
AUTHORS:
8
9
- Paul Leopardi (2018-10-18): initial version
10
11
"""
12
13
#*****************************************************************************
14
# Copyright (C) 2018 Paul Leopardi [email protected]
15
#
16
# Distributed under the terms of the GNU General Public License (GPL)
17
# as published by the Free Software Foundation; either version 2 of
18
# the License, or (at your option) any later version.
19
# http://www.gnu.org/licenses/
20
#*****************************************************************************
21
22
import json
23
import psycopg2
24
25
import boolean_cayley_graphs.classification_database_psycopg2 as cdb
26
27
28
def authorized(db_function):
29
def function_wrapper(function):
30
def db_wrapper(dbname):
31
with open("postgresql-auth.json") as auth_file:
32
auth = json.load(auth_file)
33
return db_function(
34
dbname,
35
user=auth["user"],
36
password=auth["password"],
37
host=auth["host"])
38
return db_wrapper
39
return function_wrapper
40
41
42
@authorized(cdb.create_database)
43
def create_database(dbname):
44
pass
45
46
47
@authorized(cdb.connect_to_database)
48
def connect_to_database(dbname):
49
pass
50
51
52
@authorized(cdb.drop_database)
53
def drop_database(dbname):
54
pass
55
56
57
@authorized(cdb.create_classification_tables)
58
def create_classification_tables(dbname):
59
pass
60
61
62
63