<commit_before>import logging
import argparse

from sqlalchemy.exc import ProgrammingError
from dataset.util import FreezeException
from dataset.persistence.database import Database
from dataset.freeze.config import Configuration, Export
from dataset.freeze.format import get_serializer


logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)

parser = argparse.ArgumentParser(
    description='Generate static JSON and CSV extracts from a SQL database.',
    epilog='For further information, please check the documentation.')
parser.add_argument('config', metavar='CONFIG', type=str,
                    help='freeze file cofiguration')


def freeze(database, query, format='csv', filename='freeze.csv',
           prefix='.', meta={}, indent=2, mode='list', wrap=True, **kw):
    """
    Perform a data export of a given SQL statement. This is a very
    flexible exporter, allowing for various output formats, metadata
    assignment, and file name templating to dump each record (or a set
    of records) into individual files.
    """
    kw.update({
        'database': database,
        'query': query,
        'format': format,
        'filename': filename,
        'prefix': prefix,
        'meta': meta,
        'indent': indent,
        'mode': mode,
        'wrap': wrap
    })
    return freeze_export(Export({}, kw))


def freeze_export(export):
    try:
        database = Database(export.get('database'))
        query = database.query(export.get('query'))
        serializer_cls = get_serializer(export)
        serializer = serializer_cls(export, query)<commit_msg>freeze() now accepts either db-urls or db instances<commit_after>import logging
import argparse

from sqlalchemy.exc import ProgrammingError
from dataset.util import FreezeException
from dataset.persistence.database import Database
from dataset.freeze.config import Configuration, Export
from dataset.freeze.format import get_serializer


logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)

parser = argparse.ArgumentParser(
    description='Generate static JSON and CSV extracts from a SQL database.',
    epilog='For further information, please check the documentation.')
parser.add_argument('config', metavar='CONFIG', type=str,
                    help='freeze file cofiguration')


def freeze(database, query, format='csv', filename='freeze.csv',
           prefix='.', meta={}, indent=2, mode='list', wrap=True, **kw):
    """
    Perform a data export of a given SQL statement. This is a very
    flexible exporter, allowing for various output formats, metadata
    assignment, and file name templating to dump each record (or a set
    of records) into individual files.
    """
    if isinstance(database, (str, unicode)):
        database = Database(database)
    kw.update({
        'database': database,
        'query': query,
        'format': format,
        'filename': filename,
        'prefix': prefix,
        'meta': meta,
        'indent': indent,
        'mode': mode,
        'wrap': wrap
    })
    return freeze_export(Export({}, kw))


def freeze_export(export):
    try:
        database = export.get('database')
        query = database.query(export.get('query'))
        serializer_cls = get_serializer(export)
        serializer = serializer_cls(export, query)
{'fraction_non_alphanumeric': 0.10635733654715275, 'fraction_numerical': 0.0006025911419102139, 'mean_word_length': 3.4623655913978495, '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': '2718859', 'n_tokens_mistral': 883, 'n_tokens_neox': 873, 'n_words': 284}