summaryrefslogtreecommitdiff
path: root/core/database/rebuild-database.py
blob: 0cbeb27af9264ca5ff6bbb2c254dd72e736ae6b8 (plain)
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
import os
import sqlite3
import sys

sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

try:
    BASE_DIR = directory_name=sys.argv[1]
except:
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_location = os.path.join(BASE_DIR, 'opendc.db')

if os.path.exists(db_location):
    print "Removing old database..."
    os.remove(db_location)

print "Connecting to new database..."
conn = sqlite3.connect(db_location)
c = conn.cursor()

print "Importing schema..."
with open('schema.sql') as schema:
    c.executescript(schema.read())

print "Importing test data..."
with open('test.sql') as test:
    c.executescript(test.read())

conn.commit()
conn.close()

print "Done."