41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import os
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from ffx.model.show import Base, Show
|
|
from ffx.model.pattern import Pattern
|
|
from ffx.model.track import Track
|
|
|
|
from ffx.model.media_tag import MediaTag
|
|
from ffx.model.track_tag import TrackTag
|
|
|
|
|
|
def databaseContext():
|
|
|
|
databaseContext = {}
|
|
|
|
# Initialize DB
|
|
homeDir = os.path.expanduser("~")
|
|
ffxVarDir = os.path.join(homeDir, '.local', 'var', 'ffx')
|
|
if not os.path.exists(ffxVarDir):
|
|
os.makedirs(ffxVarDir)
|
|
|
|
databaseContext['url'] = f"sqlite:///{os.path.join(ffxVarDir, 'ffx.db')}"
|
|
databaseContext['engine'] = create_engine(databaseContext['url'])
|
|
databaseContext['session'] = sessionmaker(bind=databaseContext['engine'])
|
|
|
|
Base.metadata.create_all(databaseContext['engine'])
|
|
|
|
# isSyncronuous = False
|
|
# while not isSyncronuous:
|
|
# while True:
|
|
# try:
|
|
# with databaseContext['database_engine'].connect() as connection:
|
|
# connection.execute(sqlalchemy.text('PRAGMA foreign_keys=ON;'))
|
|
# #isSyncronuous = True
|
|
# break
|
|
# except sqlite3.OperationalError:
|
|
# time.sleep(0.1)
|
|
|
|
return databaseContext |