<commit_before>import asyncio

import asyncio_mongo
from tornado.options import define, options

from wdim import client
from wdim.client.database import MongoLayer


try:
    from IPython import embed
except ImportError:
    raise ImportError('Shell requires IPython >= 0.12.0')

define('port', default=27017, help='TokuMX port')
define('db', default='127.0.0.1', help='TokuMX IP')
define('dbname', default='wdim20150921', help='The Mongo database to use')
define('namespace', default='sys_shell', help='The namespace to use')


async def get_context():
    connection = await MongoLayer.connect(options.db, options.port, options.dbname)

    assert await client.Storable.connect(connection)

    return {
        'client': client,
        # 'database': database,
        # 'mongo_connection': connection,
    }


def main(loop):
    embed(user_ns={
        'loop': loop,
        'run': lambda x: loop.run_until_complete(x),
        **loop.run_until_complete(get_context())
    })

if __name__ == '__main__':
    options.parse_command_line()
    loop = asyncio.get_event_loop()
    main(loop)<commit_msg>Update shell init<commit_after>import asyncio

from tornado.options import define, options

from wdim import client
from wdim.client.database import MongoLayer
from wdim.client.database import ElasticSearchLayer
from wdim.client.database import CompoundWriteLayer


try:
    from IPython import embed
except ImportError:
    raise ImportError('Shell requires IPython >= 0.12.0')

define('port', default=27017, help='TokuMX port')
define('db', default='127.0.0.1', help='TokuMX IP')
define('dbname', default='wdim20150921', help='The Mongo database to use')
define('namespace', default='sys_shell', help='The namespace to use')


async def get_context():
    # connection = await MongoLayer.connect(options.db, options.port, options.dbname)

    mongo_layer = await MongoLayer.connect()
    es_layer = await ElasticSearchLayer.connect()
    connection = CompoundWriteLayer(es_layer, mongo_layer)

    assert await client.Storable.connect(connection)

    namespace = await client.Namespace.get_by_namespace('Shell')
    collection = await namespace.get_collection('first')

    return {
        'client': client,
        'namespace': namespace,
        'collection': collection,
        # 'database': database,
        # 'mongo_connection': connection,
    }


def main(loop):
    embed(user_ns={
        'loop': loop,
        'run': lambda x: loop.run_until_complete(x),
        **loop.run_until_complete(get_context())
    })

if __name__ == '__main__':
    options.parse_command_line()
    loop = asyncio.get_event_loop()
    main(loop)
{'fraction_non_alphanumeric': 0.11956110480514567, 'fraction_numerical': 0.01740446462353386, 'mean_word_length': 4.174168297455969, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6560485', 'n_tokens_mistral': 831, 'n_tokens_neox': 782, 'n_words': 196}