-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSupervisor.py
53 lines (40 loc) · 1.36 KB
/
Supervisor.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
#Applicaton developed by Andrey Vsyakikh [email protected].
#Read guide in README
import psycopg2
def conndb(dbname):
con = psycopg2.connect(
database="{}".format(dbname),
user="postgres2",
password="PASS",
host="000.000.000.000",
port="5432"
)
print(con)
con.autocommit = True
return (con.cursor())
def changepass(cur, Supervisor_password):
try:
sql = ' UPDATE "SysAdminUnit" SET "UserPassword" = %(pass)s WHERE "Name" = %(name)s;'
data = cur.execute(sql, {'name': 'Supervisor', 'pass': Supervisor_password})
except Exception as e:
print('Got Exception', type(e), e.args, type(e.args))
def checkdb(con):
print("Database opened successfully")
con.execute("select datname from pg_database;")
rows = con.fetchall()
listx = list()
for elem in rows:
listx.append((elem[0]))
print(listx)
return (listx)
def cycledb(dblist, supervisor_password):
for elem in dblist:
if elem != 'postgres' and elem != 'template0' and elem != 'template1':
con = conndb(elem)
changepass(con, supervisor_password)
if __name__ == '__main__':
supervisor_password = 'yKLOufQaK.f3Gwe5D9Fsdfgd3ZeXQOeE7xSXY2Z2ju2bzBIVd/1dHUznMq'
dbname = 'postgres'
con = conndb(dbname)
dblist = checkdb(con)
cycledb(dblist, supervisor_password)