bazarr/init_db.py

24 lines
510 B
Python
Raw Normal View History

2017-09-16 00:49:46 +00:00
import os.path
import sqlite3
# Check if database exist
2017-10-19 23:50:54 +00:00
if os.path.exists('data/db/bazarr.db') == True:
2017-09-16 00:49:46 +00:00
pass
else:
# Get SQL script from file
fd = open('create_db.sql', 'r')
script = fd.read()
# Open database connection
2017-10-19 23:50:54 +00:00
db = sqlite3.connect('data/db/bazarr.db')
2017-09-16 00:49:46 +00:00
c = db.cursor()
# Execute script and commit change to database
c.executescript(script)
# Close database connection
db.close()
# Close SQL script file
fd.close()