-
Notifications
You must be signed in to change notification settings - Fork 0
/
connector.py
78 lines (56 loc) · 1.93 KB
/
connector.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import psycopg2
import psycopg2.extras
import json
import pyravendb
from pyravendb.store import document_store
class Connector(object):
_data=''
_host =''
_database=''
_user =''
_password=''
_sslmode = ''
def __init__(self):
with open('pgdbconfig.json') as config_file:
Connector._data = json.load(config_file)
def connect(self, arg):
self.switch(arg)
conn = psycopg2.connect(
host=self._host,
dbname=self._database,
user=self._user,
password=self._password,
sslmode=self._sslmode
)
return conn
def r_connect(self):
store = document_store.DocumentStore(urls="http://localhost:13518",database="billing")
store.initialize()
session = store.open_session(database="billing")
return session
def PyTestConnect(self):
pgconfig = Connector._data['local']
Connector._host = pgconfig['host']
Connector._database = pgconfig['database']
Connector._user = pgconfig['user']
Connector._password = pgconfig['password']
Connector._sslmode = 'allow'
def MonitoringConnect(self):
pgconfig = Connector._data['monitor']
Connector._host = pgconfig['host']
Connector._database = pgconfig['database']
Connector._user = pgconfig['user']
Connector._password = pgconfig['password']
Connector._sslmode = pgconfig['sslmode']
switcher = {
1: 'Monitoring',
2: 'PyTest'
}
def switch(self, arg):
self.x = self.switcher[arg]
return getattr(self, self.x +'Connect')()
# print(self.switcher.values())
# print(self.switcher.keys())
# print(self.switcher.values().index(1))
# #return self.switcher.values().index(arg)
# return self.switcher.get(arg)()