2017-11-21 20:42:18 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-10-20 12:59:21 +00:00
|
|
|
import os
|
2017-09-16 00:49:46 +00:00
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
# Check if database exist
|
2017-10-22 00:02:25 +00:00
|
|
|
if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) == True:
|
2017-09-16 00:49:46 +00:00
|
|
|
pass
|
|
|
|
else:
|
2017-10-22 02:51:15 +00:00
|
|
|
# Create data directory tree
|
2017-10-22 03:01:24 +00:00
|
|
|
try:
|
|
|
|
os.mkdir(os.path.join(os.path.dirname(__file__), 'data'))
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(os.path.join(os.path.dirname(__file__), 'data/cache'))
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(os.path.join(os.path.dirname(__file__), 'data/db'))
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(os.path.join(os.path.dirname(__file__), 'data/log'))
|
|
|
|
except OSError:
|
|
|
|
pass
|
2017-10-22 02:51:15 +00:00
|
|
|
|
2017-09-16 00:49:46 +00:00
|
|
|
# Get SQL script from file
|
2017-10-22 00:02:25 +00:00
|
|
|
fd = open(os.path.join(os.path.dirname(__file__), 'create_db.sql'), 'r')
|
2017-09-16 00:49:46 +00:00
|
|
|
script = fd.read()
|
|
|
|
|
|
|
|
# Open database connection
|
2017-10-22 00:02:25 +00:00
|
|
|
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), '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()
|