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()

[((128, 146), 'fabric.api.task', 'task', ([], {'default': '(True)'}), '(default=True)\n', (132, 146), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((162, 198), 'fabric.api.run', 'run', (['"""mkdir -p /srv/private-tangle/"""'], {}), "('mkdir -p /srv/private-tangle/')\n", (165, 198), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1612, 1625), 'time.sleep', 'time.sleep', (['(1)'], {}), '(1)\n', (1622, 1625), False, 'import time\n'), ((1630, 1675), 'fabric.api.run', 'run', (['"""rm -rf /srv/private-tangle/testnet_db/"""'], {}), "('rm -rf /srv/private-tangle/testnet_db/')\n", (1633, 1675), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1718, 1731), 'time.sleep', 'time.sleep', (['(5)'], {}), '(5)\n', (1728, 1731), False, 'import time\n'), ((208, 233), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (210, 233), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((243, 256), 'fabric.api.put', 'put', (['"""."""', '"""."""'], {}), "('.', '.')\n", (246, 256), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((265, 321), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle pull"""'], {}), "('docker-compose --project-name private-tangle pull')\n", (268, 321), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((330, 408), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle up -d --force-recreate iri"""'], {}), "('docker-compose --project-name private-tangle up -d --force-recreate iri')\n", (333, 408), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((439, 464), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (441, 464), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((474, 487), 'fabric.api.put', 'put', (['"""."""', '"""."""'], {}), "('.', '.')\n", (477, 487), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((496, 552), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle pull"""'], {}), "('docker-compose --project-name private-tangle pull')\n", (499, 552), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((561, 671), 'fabric.api.run', 'run', (['"""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    )\n", (564, 671), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((675, 771), 'fabric.api.run', 'run', (['"""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    )\n", (678, 771), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((796, 821), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (798, 821), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((831, 887), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle stop"""'], {}), "('docker-compose --project-name private-tangle stop')\n", (834, 887), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((922, 947), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (924, 947), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((957, 1025), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle stop coordinator"""'], {}), "('docker-compose --project-name private-tangle stop coordinator')\n", (960, 1025), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1055, 1080), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (1057, 1080), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1090, 1149), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle down -v"""'], {}), "('docker-compose --project-name private-tangle down -v')\n", (1093, 1149), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1179, 1204), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (1181, 1204), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1214, 1284), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle logs -f --tail 100"""'], {}), "('docker-compose --project-name private-tangle logs -f --tail 100')\n", (1217, 1284), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1320, 1345), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (1322, 1345), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1355, 1442), 'fabric.api.run', 'run', (['"""docker-compose --project-name private-tangle logs -f --tail 100 coordinator"""'], {}), "('docker-compose --project-name private-tangle logs -f --tail 100 coordinator'\n    )\n", (1358, 1442), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1471, 1496), 'fabric.api.cd', 'cd', (['"""/srv/private-tangle"""'], {}), "('/srv/private-tangle')\n", (1473, 1496), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n'), ((1506, 1535), 'fabric.api.run', 'run', (['"""docker-compose logs -f"""'], {}), "('docker-compose logs -f')\n", (1509, 1535), False, 'from fabric.api import run, env, task, put, cd, local, sudo\n')]