-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinitializer.py
More file actions
60 lines (44 loc) · 1.38 KB
/
initializer.py
File metadata and controls
60 lines (44 loc) · 1.38 KB
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
import sqlite3, sys, inspect, os, const, manager
from objects.user import User
from objects.location import Location
def init():
print "creating database with next structure:"
classes = []
print const.DBNAME
conn = sqlite3.connect(const.DBNAME)
c = conn.cursor()
for name, obj in inspect.getmembers(sys.modules[__name__]):
if inspect.isclass(obj):
classes.append(obj)
query = ""
print "class: " + str(obj)
print "table: " + str(obj.table)
query += "create table if not exists " + str(obj.table) + "("
fields = manager.getClassFields(obj)
for x in range(0, len(fields)):
field = fields[x]
print " " + field
query += field + " "
f = getattr(obj, field)
if type(f) is str:
query += "VARCHAR"
elif type(f) is int:
query += "INTEGER"
if x == 0:
query += " PRIMARY KEY"
if x != len(fields) - 1:
query += ", "
query += ")"
c.execute(query)
print query
conn.commit()
conn.close()
return
def drop():
if os.path.isfile(const.DBNAME):
os.remove(const.DBNAME)
return
def remake():
drop()
init()
return