<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function

import os

import omlite
from .translations import Peer, Translation
from .repos import Repository


MEMORY = ':memory:'


def connect(db_path):
    existing = db_path != MEMORY and os.path.exists(db_path)
    omlite.db.connect(db_path)

    try:
        if not existing:
            initialize_new_db()
    except:
        omlite.db.connect(MEMORY)
        # remove newly created, but partially initialized database
        os.remove(db_path)
        raise


def initialize_new_db():
    '''
    Initialize a new empty database, that is already connected to by omlite.
    '''
    # peers and their naming
    omlite.create_table(Peer)
    omlite.create_table(Translation)

    _create_self()<commit_msg>remove handler for hard to produce error, which is supposed to remove the offending database<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function

import os

import omlite
from .translations import Peer, Translation
from .repos import Repository


MEMORY = ':memory:'


def connect(db_path):
    existing = db_path != MEMORY and os.path.exists(db_path)
    omlite.db.connect(db_path)

    if not existing:
        initialize_new_db()


def initialize_new_db():
    '''
    Initialize a new empty database, that is already connected to by omlite.
    '''
    # peers and their naming
    omlite.create_table(Peer)
    omlite.create_table(Translation)

    _create_self()
{'fraction_non_alphanumeric': 0.06553398058252427, 'fraction_numerical': 0.0, 'mean_word_length': 3.698005698005698, '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': '4504415', 'n_tokens_mistral': 496, 'n_tokens_neox': 465, 'n_words': 153}