You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bazarr/init_db.py

48 lines
1.2 KiB

# coding: utf-8
from __future__ import unicode_literals
import os
7 years ago
import sqlite3
# Check if database exist
7 years ago
if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) == True:
7 years ago
pass
else:
# Create data directory tree
7 years ago
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
7 years ago
# Get SQL script from file
7 years ago
fd = open(os.path.join(os.path.dirname(__file__), 'create_db.sql'), 'r')
7 years ago
script = fd.read()
# Open database connection
7 years ago
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
7 years ago
c = db.cursor()
# Execute script and commit change to database
c.executescript(script)
# Close database connection
db.close()
# Close SQL script file
fd.close()