-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
39 lines (31 loc) · 1.23 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
# -*- coding: iso-8859-1 -*-
from fabric.api import env, task, run
import sys
import os
import subprocess
# ---------- Remote or local definition ----------
env.local_command = False
@task(alias = "lcmd")
def local_command():
env.local_command = True
# ---------- Start clients ----------
# Default values
workingDirectory = "demo"
clientExecutablePath = "../client.py"
configFilePath = "config.demo.xml"
numClients = 1
@task(alias = "snc")
def start_n_clients(n = numClients, dir = workingDirectory, client = clientExecutablePath, config = configFilePath):
n = int(n)
if (env.local_command):
os.chdir(dir)
for i in range(n):
subprocess.Popen(["python", client, config, "-v", "off"])
else:
# Can't use 'with cd(dir)' here because Fabric hangs. Thus, all necessary procedings
# (directory change, loop and client execution) are done on the remote machine through bash
changeDir = "cd {0}".format(dir)
executeClient = "python {0} {1} -v off".format(client, config)
loop = "for i in {{1..{0}}}; do {1} & done >& /dev/null".format(n, executeClient)
command = "bash -c '{0} && {1}'".format(changeDir, loop)
run(command, pty=False)