import time
from fabric.api import run, env, task, put, cd, local, sudo

env.use_ssh_config = True
env.hosts = ['iota_node']


@task(default=True)
def iri():
    run('mkdir -p /srv/private-tangle/')
    with cd('/srv/private-tangle'):
        put('.', '.')
        run('docker-compose --project-name private-tangle pull')
        run('docker-compose --project-name private-tangle up -d --force-recreate iri')


@task
def tools():
    with cd('/srv/private-tangle'):
        put('.', '.')
        run('docker-compose --project-name private-tangle pull')
        run('docker-compose --project-name private-tangle up -d --no-deps --force-recreate coordinator explorer')
        run('docker-compose --project-name private-tangle logs -f --tail 100 coordinator explorer')


@task
def stop():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle stop')

@task
def stop_coord():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle stop coordinator')


@task
def down():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle down -v')


@task
def logs():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle logs -f --tail 100')


@task
def logs_coord():
    with cd('/srv/private-tangle'):
        run('docker-compose --project-name private-tangle logs -f --tail 100 coordinator')


@task
def logs_all():
    with cd('/srv/private-tangle'):
        run('docker-compose logs -f')


@task
def reset():
    # stop services and delete database
    down()
    time.sleep(1)
    run('rm -rf /srv/private-tangle/testnet_db/')

    # restart all services
    iri()
    time.sleep(5)
    tools()

[((8, 1, 8, 19), 'fabric.api.task', 'task', (), '', False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((10, 4, 10, 40), 'fabric.api.run', 'run', ({(10, 8, 10, 39): '"""mkdir -p /srv/private-tangle/"""'}, {}), "('mkdir -p /srv/private-tangle/')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((65, 4, 65, 17), 'time.sleep', 'time.sleep', ({(65, 15, 65, 16): '(1)'}, {}), '(1)', False, 'import time\n'), ((66, 4, 66, 49), 'fabric.api.run', 'run', ({(66, 8, 66, 48): '"""rm -rf /srv/private-tangle/testnet_db/"""'}, {}), "('rm -rf /srv/private-tangle/testnet_db/')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((70, 4, 70, 17), 'time.sleep', 'time.sleep', ({(70, 15, 70, 16): '(5)'}, {}), '(5)', False, 'import time\n'), ((11, 9, 11, 34), 'fabric.api.cd', 'cd', ({(11, 12, 11, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((12, 8, 12, 21), 'fabric.api.put', 'put', ({(12, 12, 12, 15): '"""."""', (12, 17, 12, 20): '"""."""'}, {}), "('.', '.')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((13, 8, 13, 64), 'fabric.api.run', 'run', ({(13, 12, 13, 63): '"""docker-compose --project-name private-tangle pull"""'}, {}), "('docker-compose --project-name private-tangle pull')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((14, 8, 14, 86), 'fabric.api.run', 'run', ({(14, 12, 14, 85): '"""docker-compose --project-name private-tangle up -d --force-recreate iri"""'}, {}), "('docker-compose --project-name private-tangle up -d --force-recreate iri')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((19, 9, 19, 34), 'fabric.api.cd', 'cd', ({(19, 12, 19, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((20, 8, 20, 21), 'fabric.api.put', 'put', ({(20, 12, 20, 15): '"""."""', (20, 17, 20, 20): '"""."""'}, {}), "('.', '.')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((21, 8, 21, 64), 'fabric.api.run', 'run', ({(21, 12, 21, 63): '"""docker-compose --project-name private-tangle pull"""'}, {}), "('docker-compose --project-name private-tangle pull')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((22, 8, 22, 113), 'fabric.api.run', 'run', ({(22, 12, 22, 112): '"""docker-compose --project-name private-tangle up -d --no-deps --force-recreate coordinator explorer"""'}, {}), "('docker-compose --project-name private-tangle up -d --no-deps --force-recreate coordinator explorer'\n    )", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((23, 8, 23, 99), 'fabric.api.run', 'run', ({(23, 12, 23, 98): '"""docker-compose --project-name private-tangle logs -f --tail 100 coordinator explorer"""'}, {}), "('docker-compose --project-name private-tangle logs -f --tail 100 coordinator explorer'\n    )", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((28, 9, 28, 34), 'fabric.api.cd', 'cd', ({(28, 12, 28, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((29, 8, 29, 64), 'fabric.api.run', 'run', ({(29, 12, 29, 63): '"""docker-compose --project-name private-tangle stop"""'}, {}), "('docker-compose --project-name private-tangle stop')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((33, 9, 33, 34), 'fabric.api.cd', 'cd', ({(33, 12, 33, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((34, 8, 34, 76), 'fabric.api.run', 'run', ({(34, 12, 34, 75): '"""docker-compose --project-name private-tangle stop coordinator"""'}, {}), "('docker-compose --project-name private-tangle stop coordinator')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((39, 9, 39, 34), 'fabric.api.cd', 'cd', ({(39, 12, 39, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((40, 8, 40, 67), 'fabric.api.run', 'run', ({(40, 12, 40, 66): '"""docker-compose --project-name private-tangle down -v"""'}, {}), "('docker-compose --project-name private-tangle down -v')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((45, 9, 45, 34), 'fabric.api.cd', 'cd', ({(45, 12, 45, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((46, 8, 46, 78), 'fabric.api.run', 'run', ({(46, 12, 46, 77): '"""docker-compose --project-name private-tangle logs -f --tail 100"""'}, {}), "('docker-compose --project-name private-tangle logs -f --tail 100')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((51, 9, 51, 34), 'fabric.api.cd', 'cd', ({(51, 12, 51, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((52, 8, 52, 90), 'fabric.api.run', 'run', ({(52, 12, 52, 89): '"""docker-compose --project-name private-tangle logs -f --tail 100 coordinator"""'}, {}), "('docker-compose --project-name private-tangle logs -f --tail 100 coordinator'\n    )", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((57, 9, 57, 34), 'fabric.api.cd', 'cd', ({(57, 12, 57, 33): '"""/srv/private-tangle"""'}, {}), "('/srv/private-tangle')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((58, 8, 58, 37), 'fabric.api.run', 'run', ({(58, 12, 58, 36): '"""docker-compose logs -f"""'}, {}), "('docker-compose logs -f')", False, 'from fabric.api import run, env, task, put, cd, local, sudo\n')]