-
Notifications
You must be signed in to change notification settings - Fork 123
/
fabfile.py
executable file
·50 lines (40 loc) · 1.38 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
#
# File: fabfile.py
#
# Created: Wednesday, August 24 2016 by rejuvyesh <[email protected]>
# 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')