<commit_before>from fabric.api import env, execute, get, put, task, run, local, roles


env.roledefs = {
    'local': ['127.0.0.1'],
}

@task
def run_cassandra():
    cassandra_image = "spotify/cassandra"
    cassandra_params = "cassandra -p 7199:7199 -p 9160:9160 "
    docker_run("-dti --name " + cassandra_params + cassandra_image, True)


# Docker Commands
def docker(cmd, is_local=False):
    if is_local:
        return local("docker %s" % cmd)
    return run("docker %s" % cmd)


def docker_start(container, local=None):
    return docker("start %s" % container, local)


def docker_stop(container, local=None):
    return docker("kill %s" % container, local)


def docker_clean(container, local=None):
    docker_stop(container)
    return docker("rm %s" % container, local)


def docker_restart(container, local=None):
    docker_stop(container, local)
    return docker_start(container, local)


def docker_pull(image, local=None):
    return docker("pull %s" % image, local)


def docker_run(command, local=None):
    return docker("run %s" % command, local)


def docker_build(container, name, local=None):
    return docker("build -t %s %s " % (name, container), local)<commit_msg>Fix fabfile to try start and create if not exist container<commit_after>from fabric.api import env, execute, get, put, task, run, local, roles


env.roledefs = {
    'local': ['127.0.0.1'],
}

@task
def run_cassandra():
    cassandra_image = "spotify/cassandra"
    cassandra_params = "cassandra -p 7199:7199 -p 9160:9160 -p 9042:9042 "

    try:
        docker_restart('cassandra', True)
    except:
        docker_run("-dti --name " + cassandra_params + cassandra_image, True)

@task
def init_cassandra():
    with docker_exec('cassandra', True):
        run('cqlsh')
        local("create keyspace example with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };")
        local('create table example.tweet(timeline text, id UUID, text text, PRIMARY KEY(id));')
        local('create index on example.tweet(timeline);')
        local('exit')

# Docker Commands
def docker(cmd, is_local=False):
    if is_local:
        return local("docker %s" % cmd)
    return run("docker %s" % cmd)


def docker_start(container, local=None):
    return docker("start %s" % container, local)


def docker_stop(container, local=None):
    return docker("kill %s" % container, local)


def docker_clean(container, local=None):
    docker_stop(container)
    return docker("rm %s" % container, local)


def docker_restart(container, local=None):
    docker_stop(container, local)
    docker_start(container, local)


def docker_pull(image, local=None):
    return docker("pull %s" % image, local)


def docker_run(command, local=None):
    return docker("run %s" % command, local)


def docker_build(container, name, local=None):
    return docker("build -t %s %s " % (name, container), local)


def docker_exec(container, local=None):
    docker('exec -ti %s bash' % container, local)
{'fraction_non_alphanumeric': 0.13404825737265416, 'fraction_numerical': 0.017761394101876677, 'mean_word_length': 4.1200686106346485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7602800', 'n_tokens_mistral': 1076, 'n_tokens_neox': 972, 'n_words': 266}