summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleonoverweel <l.overweel@gmail.com>2017-02-27 00:08:58 +0100
committerleonoverweel <l.overweel@gmail.com>2017-02-27 00:08:58 +0100
commit5990c005edb42a5e064224a03fed32522a66047e (patch)
tree93f69baed30795bb4fe0f6bbb17adee4d551e45a
parent5d17b7c01ea31fd845019cb411336b9b722184e8 (diff)
Add Python database rebuilder
This one allows you to specify the location of the database.
-rw-r--r--database/rebuild-database.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/database/rebuild-database.py b/database/rebuild-database.py
new file mode 100644
index 00000000..6e10b646
--- /dev/null
+++ b/database/rebuild-database.py
@@ -0,0 +1,31 @@
+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')
+
+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."