<commit_before>"""gludb.backends.dynamodb - backend dynamodb database module
"""

import os

from uuid import uuid4

import boto.exception
import boto.dynamodb2  # NOQA

from boto.dynamodb2.layer1 import DynamoDBConnection
from boto.dynamodb2.table import Table
from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.items import Item
from boto.dynamodb2.exceptions import ResourceNotFoundException, ItemNotFound
from boto.exception import JSONResponseError


def uuid():
    return uuid4().hex


def get_conn():
    """Return a connection to DynamoDB (and handle local/debug possibilities)
    """
    if os.environ.get('DEBUG', None):
        # In DEBUG mode - use the local DynamoDB
        conn = DynamoDBConnection(
            host='localhost',
            port=8000,
            aws_access_key_id='TEST',
            aws_secret_access_key='TEST',
            is_secure=False
        )
    elif os.environ.get('travis', None):
        # TODO: we need a mocking library for DynamoDB that we can use
        #       on Travis CI. (ddbmock is Python 2.7 only)
        conn = None
    else:
        # Regular old production
        conn = DynamoDBConnection()

    return conn


def delete_table(table_name):
    """Mainly for testing"""
    Table(table_name, connection=get_conn(), schema=[HashKey('id')]).delete()


class Backend(object):
    def __init__(self, **kwrds):
        pass  # No current keywords needed/used

    def ensure_table(self, cls):
        exists = True
        conn = get_conn()
        table_name = cls.get_table_name()
        try:
            descrip = conn.describe_table(table_name)<commit_msg>todo update [no ci]<commit_after>"""gludb.backends.dynamodb - backend dynamodb database module
"""

import os

from uuid import uuid4

import boto.exception
import boto.dynamodb2  # NOQA

from boto.dynamodb2.layer1 import DynamoDBConnection
from boto.dynamodb2.table import Table
from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.items import Item
from boto.dynamodb2.exceptions import ResourceNotFoundException, ItemNotFound
from boto.exception import JSONResponseError


def uuid():
    return uuid4().hex


def get_conn():
    """Return a connection to DynamoDB (and handle local/debug possibilities)
    """
    if os.environ.get('DEBUG', None):
        # In DEBUG mode - use the local DynamoDB
        conn = DynamoDBConnection(
            host='localhost',
            port=8000,
            aws_access_key_id='TEST',
            aws_secret_access_key='TEST',
            is_secure=False
        )
    elif os.environ.get('travis', None):
        # TODO: we will need some customization for testing on Travis - see
        #       https://github.com/nabeken/goamz-dynamodb
        conn = None
    else:
        # Regular old production
        conn = DynamoDBConnection()

    return conn


def delete_table(table_name):
    """Mainly for testing"""
    Table(table_name, connection=get_conn(), schema=[HashKey('id')]).delete()


class Backend(object):
    def __init__(self, **kwrds):
        pass  # No current keywords needed/used

    def ensure_table(self, cls):
        exists = True
        conn = get_conn()
        table_name = cls.get_table_name()
        try:
            descrip = conn.describe_table(table_name)
{'fraction_non_alphanumeric': 0.09218559218559219, 'fraction_numerical': 0.008547008547008548, 'mean_word_length': 2.855294117647059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '5186097', 'n_tokens_mistral': 1017, 'n_tokens_neox': 978, 'n_words': 266}