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