mobicen / mobiExp.py @ dfc44250
History | View | Annotate | Download (1.69 KB)
1 |
import getopt |
---|---|
2 |
import code # code.interact(local=dict(globals(), **locals())) |
3 |
from pprint import pprint |
4 |
import sys |
5 |
import os |
6 |
import shutil |
7 |
import datetime |
8 |
from simulator import Simulator |
9 |
|
10 |
if __name__ == '__main__': |
11 |
|
12 |
settingsFile = ''
|
13 |
sectionExp = ''
|
14 |
outPath = ''
|
15 |
cdir = ''
|
16 |
num_workers = 1
|
17 |
gui = False
|
18 |
options, remainder = getopt.getopt( |
19 |
sys.argv[1:], '', ['sf=', 'en=', 'out=', 'thr=', 'gui']) |
20 |
mand = set(['--sf', '--en', '--out']) |
21 |
opts = [x[0] for x in options] |
22 |
# print 'OPTIONS :', opts
|
23 |
if (not mand.issubset(opts)): |
24 |
print 'Mandatory args are: --sf (settings file) --en (experiment name)'\ |
25 |
' --out (Output path, overwrite or create folder)'
|
26 |
sys.exit(1)
|
27 |
for opt, arg in options: |
28 |
if opt in ('--sf'): |
29 |
settingsFile = arg |
30 |
if opt in ('--en'): |
31 |
sectionExp = arg |
32 |
if opt in ('--thr'): |
33 |
num_workers = int(arg)
|
34 |
if opt in ('--out'): |
35 |
outPath = arg |
36 |
outPath.rstrip("/")
|
37 |
if not os.path.exists(outPath): |
38 |
sys.stderr.write("Cannot find the outpath you provided!")
|
39 |
sys.exit(1)
|
40 |
else:
|
41 |
start = datetime.datetime.now().strftime("%Hh%Mm%Ss_%d-%m-%Y")
|
42 |
cdir = outPath + '/' + sectionExp + '_'+ start |
43 |
if os.path.exists(cdir):
|
44 |
shutil.rmtree(cdir) |
45 |
os.makedirs(cdir) |
46 |
if opt in ('--gui'): |
47 |
gui = True
|
48 |
|
49 |
sim = Simulator(settingsFile, sectionExp, cdir, num_workers=num_workers, gui=gui) |
50 |
print "Simulation Parameters\n" |
51 |
pprint(sim.params) |
52 |
#code.interact(local=dict(globals(), **locals()))
|
53 |
sim.runSimulation() |