-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_management.py
executable file
·197 lines (177 loc) · 8.08 KB
/
database_management.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from tkinter import *
from functions import *
import functions
from generate_data import *
#import psycopg2
#import sqlite3
class Config:
def __init__(self, parent):
top = self.top = Toplevel(parent)
Label(top, text="Database config").grid(row=0, columnspan=2)
self.label_user = Label(top, text="user:")
self.user = Entry(top)
self.label_user.grid(row=1, column=0)
self.user.grid(row=1, column=1)
self.label_password = Label(top, text="password:")
self.password = Entry(top)
self.label_password.grid(row=2, column=0)
self.password.grid(row=2, column=1)
self.label_host = Label(top, text="host:")
self.host = Entry(top)
self.host.insert(0, "127.0.0.1")
self.label_host.grid(row=3, column=0)
self.host.grid(row=3, column=1)
self.label_database = Label(top, text="database:")
self.database = Entry(top)
self.label_database.grid(row=4, column=0)
self.database.grid(row=4, column=1)
b = Button(top, text="OK", command=self.ok)
b.grid(row=5, columnspan=2)
parent.lift()
def ok(self):
download_dir = "config.csv"
config_file = open(download_dir, "w")
columnTitleRow = "user, password, host, database\n"
config_file.write(columnTitleRow)
row = (self.user.get() + ',' + self.password.get() + ',' + self.host.get() + ',' + self.database.get())
config_file.write(row)
self.top.destroy()
class Manager(Frame):
def delete_all_tables(self):
table_deleted = False
self.text_select.delete('1.0', END)
if (check_table_exists('requirements') == True):
drop_table('requirements')
self.text_select.insert(INSERT, "Table requirements dropped\n")
table_deleted = True
if (check_table_exists('reviews') == True):
drop_table('reviews')
self.text_select.insert(INSERT, "Table reviews dropped\n")
table_deleted = True
if (check_table_exists('friends') == True):
drop_table('friends')
self.text_select.insert(INSERT, "Table friends dropped\n")
table_deleted = True
if (check_table_exists('poster') == True):
drop_table('poster')
self.text_select.insert(INSERT, "Table poster dropped\n")
table_deleted = True
if (check_table_exists('admin') == True):
drop_table('admin')
self.text_select.insert(INSERT, "Table admin dropped\n")
table_deleted = True
if (check_table_exists('shopping_cart') == True):
drop_table('shopping_cart')
self.text_select.insert(INSERT, "Table shopping_cart dropped\n")
table_deleted = True
if (check_table_exists('member') == True):
drop_table('member')
self.text_select.insert(INSERT, "Table member dropped\n")
table_deleted = True
if (check_table_exists('game') == True):
drop_table('game')
self.text_select.insert(INSERT, "Table game dropped\n")
table_deleted = True
if (table_deleted == False):
self.text_select.insert(INSERT, "No Tables dropped\n")
def generate_all_data(self):
generate_game_data()
generate_member_data()
generate_req_data()
self.text_select.delete('1.0', END)
self.text_select.insert(INSERT, "Data files generated\n")
def create_all_teble(self):
table_created = False
self.text_select.delete('1.0', END)
if (check_table_exists('game') == False):
create_game_table()
self.text_select.insert(INSERT, "Table game created\n")
table_created = True
if (check_table_exists('member') == False):
create_member_table()
self.text_select.insert(INSERT, "Table member created\n")
table_created = True
if (check_table_exists('shopping_cart') == False):
create_shopping_cart_table()
self.text_select.insert(INSERT, "Table shopping_cart created\n")
table_created = True
if (check_table_exists('admin') == False):
create_admin_table()
self.text_select.insert(INSERT, "Table admin created\n")
table_created = True
if (check_table_exists('poster') == False):
create_poster_table()
self.text_select.insert(INSERT, "Table poster created\n")
table_created = True
if (check_table_exists('friends') == False):
create_friends_table()
self.text_select.insert(INSERT, "Table friends created\n")
table_created = True
if (check_table_exists('reviews') == False):
create_reviews_table()
self.text_select.insert(INSERT, "Table reviews created\n")
table_created = True
if (check_table_exists('requirements') == False):
create_requirements_table()
self.text_select.insert(INSERT, "Table requirements created\n")
table_created = True
if (table_created == False):
self.text_select.insert(INSERT, "No Tables created\n")
def fill_tables(self):
self.text_select.delete('1.0', END)
if (check_table_exists('game') == True):
try:
fill_games()
except:
functions.conn.rollback()
self.text_select.insert(INSERT, "Table game could not be filled (duplicate key or no data file)\n")
else:
self.text_select.insert(INSERT, "Table game does not exist\n")
if (check_table_exists('member') == True):
try:
fill_members()
except:
functions.conn.rollback()
self.text_select.insert(INSERT, "Table member could not be filled (duplicate key or no data file)\n")
else:
self.text_select.insert(INSERT, "Table member does not exist\n")
if (check_table_exists('requirements') == True):
try:
fill_requirements()
except:
functions.conn.rollback()
self.text_select.insert(INSERT, "Table requirements could not be filled (duplicate key or no data file)\n")
else:
self.text_select.insert(INSERT, "Table requirements does not exist\n")
if (check_table_exists('poster') == True):
try:
fill_posters()
except:
functions.conn.rollback()
self.text_select.insert(INSERT, "Table poster could not be filled (duplicate key or no data file)\n")
else:
self.text_select.insert(INSERT, "Table poster does not exist\n")
self.text_select.insert(INSERT, "Tables filling ended\n")
def __init__(self, master = None):
width = root.winfo_screenwidth() / 2
height = root.winfo_screenheight() / 2
root.title("PIPE database manager")
root.geometry("%dx%d" % (width, height))
top_frame = Frame(root)
top_frame.grid()
button_delete_tables = Button(top_frame, text="Delete Tables", command=self.delete_all_tables)
button_delete_tables.grid(row=0, column=0)
button_generate_data = Button(top_frame, text="Generate Data", command=self.generate_all_data)
button_generate_data.grid(row=0, column=1)
button_generate_data = Button(top_frame, text="Create Tables", command=self.create_all_teble)
button_generate_data.grid(row=0, column=2)
button_generate_data = Button(top_frame, text="Fill Tables", command=self.fill_tables)
button_generate_data.grid(row=0, column=3)
self.text_select = Text(root, width=80, height=10)
self.text_select.grid(pady=(10, 100))
#d = Config(root)
#root.wait_window(d.top)
connect()
root = Tk()
app = Manager(master=root)
root.mainloop()