Trisurf Monte Carlo simulator
Samo Penic
2016-05-15 3b83db7eaf329b61ffd66576fb7a8221311952a5
commit | author | age
9f5ff5 1 import sys, getopt
SP 2 import tabulate
3
5f4aea 4 def printHelp():
SP 5     print('Python module tsmgr accept following switches:\n')
6     print('tsmgr [-n process number] [-R] [-h] [-r] [-s] [-c comment text] [-a comment text]\n')
7     print('[-n process number]: number of process for which -s -r -c or -a switch apply. Should be placed before any other switch');
8     print('[-R]               : raw output for -s switch');
9     print('[-r]               : run process');
10     print('[-s]               : process status');
11     print('[-c comment text]  : write new comment for process');
12     print('[-a comment text]  : append additional comment for process');
13     print('[-h]               : print help');
14
15
9f5ff5 16 def start(Runs):
SP 17     argv=sys.argv[1:]
18     processno=0
5f4aea 19     raw=False
9f5ff5 20     try:
5f4aea 21         opts, args = getopt.getopt(argv,"Ra:n:hrsc:")
9f5ff5 22     except getopt.GetoptError:
5f4aea 23         printHelp()
9f5ff5 24         sys.exit(2)
SP 25     for opt, arg in opts:
5f4aea 26         if opt == '-R':
SP 27             raw=True
28         elif opt == '-h':
29             printHelp()
9f5ff5 30             sys.exit()
SP 31         elif opt == '-r':
32             if processno:
33                 localRuns=[Runs[processno-1]]
34             else:
35                 localRuns=Runs
36             for run in localRuns:
37                 run.start()
38         elif opt == '-s':
39             report=[]
40             i=1
41             if processno:
42                 localRuns=[Runs[processno-1]]
43             else:
44                 localRuns=Runs
45             for run in localRuns:
46                 line=run.getStatistics()
47                 line.insert(0,i)
48                 report.append(line)
49                 i=i+1
5f4aea 50             if(raw):
SP 51                 print(report)
52             else:
53                 print ("\n\nTrisurf running processes report\n")
54                 print (tabulate.tabulate(report,headers=["Run no.", "Run start time", "ETA", "Status", "PID", "Path", "Comment"], tablefmt='fancy_grid'))
9f5ff5 55         elif opt == '-n':
SP 56             processno=int(arg)
57             if processno<1 or processno>len(Runs) :
58                 processno=0
59         elif opt == '-c':
60             comment = arg
61             if processno:
62                 Runs[processno-1].writeComment(arg)
63         elif opt == '-a':
64             comment = arg
65             if processno:
66                 Runs[processno-1].writeComment("\n"+arg, 'a')
67
68             
69         else:
5f4aea 70             printHelp()
9f5ff5 71             sys.exit(2)
SP 72
73
74
75
76
77