https://github.com/sisl/MADRL
Raw File
Tip revision: 9ea39a0fe8695b391008a4eb7bda9fe4438a96de authored by Mykel Kochenderfer on 12 April 2023, 16:04:09 UTC
Merge pull request #37 from johnMinelli/patch-1
Tip revision: 9ea39a0
fabfile.py
#!/usr/bin/env python
#
# File: fabfile.py
#
# Created: Wednesday, August 24 2016 by rejuvyesh <mail@rejuvyesh.com>
# License: GNU GPL 3 <http://www.gnu.org/copyleft/gpl.html>
#
from fabric.api import cd, put, path, task, shell_env, run, env, local, settings
from fabric.contrib.project import rsync_project
import os.path
from time import sleep

env.use_ssh_config = True

RLTOOLS_LOC = '/home/{}/src/python/rltools'.format(env.user)
MADRL_LOC = '/home/{}/src/python/MADRL'.format(env.user)


class Tmux(object):

    def __init__(self, name):
        self._name = name
        with settings(warn_only=True):
            test = run('tmux has-session -t {}'.format(self._name))
        if test.failed:
            run('tmux new-session -d -s {}'.format(self._name))

    def run(self, cmd, window=0):
        run('tmux send -t {}.{} "{}" ENTER'.format(self._name, window, cmd))


@task
def githash():
    git_hash = local('git rev-parse HEAD', capture=True)
    return git_hash

@task
def sync():
    rsync_project(remote_dir=os.path.split(MADRL_LOC)[0], exclude=['*.h5'])

@task(alias='pipe')
def runpipeline(script, fname):
    git_hash = githash()
    sync()
    pipetm = Tmux('pipeline')
    pipetm.run('export PYTHONPATH={}:{}'.format(RLTOOLS_LOC, MADRL_LOC))
    pipetm.run('cd {}'.format(MADRL_LOC))
    pipetm.run('python {} {} {}'.format(script, fname, git_hash))
    sleep(0.5)
    pipetm.run('y')
back to top