<commit_before>from osfoffline.models import Base
from appdirs import user_data_dir
from osfoffline.settings import PROJECT_NAME,PROJECT_AUTHOR
import shutil
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.pool import SingletonThreadPool


DB_DIR = user_data_dir(PROJECT_NAME, PROJECT_AUTHOR)
DB_FILE_PATH = os.path.join(DB_DIR, 'osf.db')
URL = 'sqlite:///{}'.format(DB_FILE_PATH)

Session = None


def setup_db(dir=None):
    if dir:
        global DB_DIR
        global DB_FILE_PATH
        global URL
        # todo: determine if we change db_dir, then do the other constants already get updated as we need them???
        DB_DIR = dir
        DB_FILE_PATH = os.path.join(DB_DIR, 'osf.db')
        # # sqlite+pysqlcipher://:passphrase/file_path
        #
        # #Unix/Mac - 4 initial slashes in total
        # engine = create_engine('sqlite:////absolute/path/to/foo.db')
        # #Windows
        # engine = create_engine('sqlite:///C:\\path\\to\\foo.db')
        # #Windows alternative using raw string
        # engine = create_engine(r'sqlite:///C:\path\to\foo.db')
        URL = 'sqlite+pysqlcipher://:PASSWORD/{DB_FILE_PATH}'.format(DB_FILE_PATH=DB_FILE_PATH)
        # URL = 'sqlite:///{}'.format(DB_FILE_PATH)

    create_models()
    create_session()


def remove_db():
    shutil.rmtree(DB_DIR)

def get_session():
    if Session:
        return Session()
    else:
        raise ValueError

def create_models():
    """ Create sql alchemy engine and models for all file systems.
    """
    if not os.path.isdir(DB_DIR):
        os.makedirs(DB_DIR)
    engine = create_engine(
        URL,
        poolclass=SingletonThreadPool,
        connect_args={'check_same_thread':False},
    )
    Base.metadata.create_all(engine)<commit_msg>sqlite3 cipher<commit_after>from osfoffline.models import Base
from appdirs import user_data_dir
from osfoffline.settings import PROJECT_NAME,PROJECT_AUTHOR
import shutil
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.pool import SingletonThreadPool


DB_DIR = user_data_dir(PROJECT_NAME, PROJECT_AUTHOR)
DB_FILE_PATH = os.path.join(DB_DIR, 'osf.db')
URL = 'sqlite:///{}'.format(DB_FILE_PATH)

Session = None


def setup_db(dir=None):
    if dir:
        global DB_DIR
        global DB_FILE_PATH
        global URL
        # todo: determine if we change db_dir, then do the other constants already get updated as we need them???
        DB_DIR = dir
        DB_FILE_PATH = os.path.join(DB_DIR, 'osf.db')
        # sqlite+pysqlcipher://:passphrase/file_path
        # URL = 'sqlite+pysqlcipher://:PASSWORD/{DB_FILE_PATH}'.format(DB_FILE_PATH=DB_FILE_PATH)
        URL = 'sqlite:///{}'.format(DB_FILE_PATH)

    create_models()
    create_session()


def remove_db():
    shutil.rmtree(DB_DIR)

def get_session():
    if Session:
        return Session()
    else:
        raise ValueError

def create_models():
    """ Create sql alchemy engine and models for all file systems.
    """
    if not os.path.isdir(DB_DIR):
        os.makedirs(DB_DIR)
    engine = create_engine(
        URL,
        poolclass=SingletonThreadPool,
        connect_args={'check_same_thread':False},
    )
    Base.metadata.create_all(engine)
{'fraction_non_alphanumeric': 0.10380205190102595, 'fraction_numerical': 0.0006035003017501509, 'mean_word_length': 3.2015209125475286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2591853', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1079, 'n_words': 244}