1 | import os |
---|
2 | import sys |
---|
3 | |
---|
4 | |
---|
5 | from user_param import * |
---|
6 | |
---|
7 | def main(): |
---|
8 | |
---|
9 | black = lambda text: '\033[0;30m' + text + '\033[0m' |
---|
10 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
11 | green = lambda text: '\033[0;32m' + text + '\033[0m' |
---|
12 | yellow = lambda text: '\033[0;33m' + text + '\033[0m' |
---|
13 | blue = lambda text: '\033[0;34m' + text + '\033[0m' |
---|
14 | magenta = lambda text: '\033[0;35m' + text + '\033[0m' |
---|
15 | cyan = lambda text: '\033[0;36m' + text + '\033[0m' |
---|
16 | lgray = lambda text: '\033[0;37m' + text + '\033[0m' |
---|
17 | dgray = lambda text: '\033[1;30m' + text + '\033[0m' |
---|
18 | lred = lambda text: '\033[1;32m' + text + '\033[0m' |
---|
19 | lgreen = lambda text: '\033[1;32m' + text + '\033[0m' |
---|
20 | lyellow = lambda text: '\033[1;33m' + text + '\033[0m' |
---|
21 | lblue = lambda text: '\033[1;34m' + text + '\033[0m' |
---|
22 | lpurple = lambda text: '\033[1;35m' + text + '\033[0m' |
---|
23 | lcyan = lambda text: '\033[1;36m' + text + '\033[0m' |
---|
24 | white = lambda text: '\033[1;37m' + text + '\033[0m' |
---|
25 | |
---|
26 | configNamePattern=[0]*7 |
---|
27 | |
---|
28 | f=open("user_param.py", "r") |
---|
29 | for line in f: |
---|
30 | line = line.strip() |
---|
31 | if line.startswith("UsingServer2"): |
---|
32 | configNamePattern[0] = '_UsingSrv2=' + UsingServer2 |
---|
33 | elif line.startswith("RatioServer2"): |
---|
34 | configNamePattern[1] = '_RatioSrv2=' + repr(RatioServer2) |
---|
35 | elif line.startswith("NumberPoolsServer2"): |
---|
36 | configNamePattern[2] = '_NbPoolsSrv2=' + repr(NumberPoolsServer2) |
---|
37 | elif line.startswith("NumberClients"): |
---|
38 | configNamePattern[3] = '_NbClients=' + repr(NumberClients) |
---|
39 | elif line.startswith("NumberServers"): |
---|
40 | configNamePattern[4] = '_NbServers=' + repr(NumberServers) |
---|
41 | elif line.startswith("Duration"): |
---|
42 | configNamePattern[5] = '_Duration=' + Duration |
---|
43 | elif line.startswith("ATMdomain"): |
---|
44 | configNamePattern[5] = '_ATMdomain=' + ATMdomain |
---|
45 | f.close() |
---|
46 | |
---|
47 | |
---|
48 | configName = "config" |
---|
49 | defaultConfig = True |
---|
50 | |
---|
51 | for i in range(len(configNamePattern)): |
---|
52 | if configNamePattern[i] != 0: |
---|
53 | configName = configName + configNamePattern[i] |
---|
54 | defaultConfig = False |
---|
55 | |
---|
56 | if defaultConfig: |
---|
57 | configName = "config_default" |
---|
58 | |
---|
59 | |
---|
60 | if not os.path.exists(configName): |
---|
61 | os.mkdir(configName) |
---|
62 | print blue("\n ****************************************************************") |
---|
63 | print blue(" * Directory " + repr(configName) + " Created ") |
---|
64 | print blue(" * Copy results to \'not_validated_reference\' folder") |
---|
65 | print blue(" ****************************************************************\n") |
---|
66 | |
---|
67 | os.mkdir(configName+'/setup') |
---|
68 | os.mkdir(configName+'/tmp_reference') |
---|
69 | os.mkdir(configName+'/xios_output') |
---|
70 | |
---|
71 | os.system('mv param.def '+configName+'/setup/') |
---|
72 | os.system('mv all_param.def '+configName+'/setup/') |
---|
73 | os.system('mv user_param.py '+configName+'/setup/') |
---|
74 | os.system('mv iodef.xml '+configName+'/setup/') |
---|
75 | os.system('cp context_atm.xml '+configName+'/setup/') |
---|
76 | os.system('cp context_grid_dynamico.xml '+configName+'/setup/') |
---|
77 | os.system('cp dynamico_grid.nc '+configName+'/setup/') |
---|
78 | os.system('mv xios_*.out '+configName+'/xios_output/') |
---|
79 | os.system('mv xios_*.err '+configName+'/xios_output/') |
---|
80 | |
---|
81 | |
---|
82 | f=open("checkfile.def", "r") |
---|
83 | h=open("report.txt", "a+") |
---|
84 | l=open("report.html", "a+") |
---|
85 | h.write("Config : "+configName+"\n") |
---|
86 | l.write("<p>Config : "+configName+"</p>") |
---|
87 | for line in f: |
---|
88 | line=line.strip() |
---|
89 | line=line.rstrip() |
---|
90 | if not line.startswith("#") and len(line) != 0: |
---|
91 | cmd = 'mv '+line + ' '+configName+'/tmp_reference/' |
---|
92 | os.system(cmd) |
---|
93 | |
---|
94 | h.write("test for "+lpurple(line)+" \t"+yellow('INITIALIZED')+"\n") |
---|
95 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"darkorange\">INITIALIZED</font></p>") |
---|
96 | print yellow("\n ****************************************") |
---|
97 | print yellow(" ** "+line+" is stored as temporal reference !!! **") |
---|
98 | print yellow("\n ****************************************") |
---|
99 | |
---|
100 | f.close() |
---|
101 | h.write("\n") |
---|
102 | l.write("<br>") |
---|
103 | h.close() |
---|
104 | |
---|
105 | |
---|
106 | else: |
---|
107 | print blue("\n ********************************************************") |
---|
108 | print blue(" * Directory " + repr(configName) + " already exists") |
---|
109 | print blue(" * Start comparing results with (tmp) references") |
---|
110 | print blue(" ********************************************************\n") |
---|
111 | |
---|
112 | tmp_ref = os.path.isdir(configName+'/tmp_reference') |
---|
113 | ref = os.path.isdir(configName+'/reference') |
---|
114 | |
---|
115 | if ref: |
---|
116 | print blue("\n =====================================") |
---|
117 | print blue(" | Comparing results with references |") |
---|
118 | print blue(" =====================================\n") |
---|
119 | os.system('rm -rf '+configName+'/tmp_reference/') |
---|
120 | tmp_ref = False |
---|
121 | path = configName+'/reference/' |
---|
122 | elif tmp_ref: |
---|
123 | print blue("\n ===================================================") |
---|
124 | print blue(" | Comparing results with NON-Validated references |") |
---|
125 | print blue(" ===================================================\n") |
---|
126 | path = ' '+configName+'/tmp_reference/' |
---|
127 | |
---|
128 | f=open("checkfile.def", "r") |
---|
129 | h=open("report.txt", "a+") |
---|
130 | l=open("report.html", "a+") |
---|
131 | |
---|
132 | |
---|
133 | h.write("Config : "+configName+"\n") |
---|
134 | l.write("<p>Config : "+configName+"</p>") |
---|
135 | for line in f: |
---|
136 | |
---|
137 | line=line.strip() |
---|
138 | line=line.rstrip() |
---|
139 | |
---|
140 | if not line.startswith("#") and len(line) != 0: |
---|
141 | cmd = 'cdo diffn '+ line + path + line + ' | tail -1 > diff.txt' |
---|
142 | os.system(cmd) |
---|
143 | |
---|
144 | if os.stat("diff.txt").st_size==0: |
---|
145 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
146 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
147 | print green("\n ****************************************") |
---|
148 | print green(" ** "+line+" is valid !!! **") |
---|
149 | print green("\n ****************************************") |
---|
150 | |
---|
151 | else: |
---|
152 | g=open("diff.txt", "r") |
---|
153 | for gline in g: |
---|
154 | if gline.strip().startswith("0") or ":" in gline : |
---|
155 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
156 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
157 | print green("\n ****************************************") |
---|
158 | print green(" ** "+line+" is valid !!! **") |
---|
159 | print green("\n ****************************************") |
---|
160 | else: |
---|
161 | h.write("test for "+lpurple(line)+" \t"+red('FAILED')+"\n") |
---|
162 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"red\">FAILED</font></p>") |
---|
163 | print red("\n **************************************************") |
---|
164 | print red(" ** "+line+" is NOT valid. Please debugging.. **") |
---|
165 | print red("\n **************************************************") |
---|
166 | g.close() |
---|
167 | f.close() |
---|
168 | h.write("\n") |
---|
169 | l.write("<br>") |
---|
170 | h.close() |
---|
171 | |
---|
172 | if not os.path.exists('current_run'): |
---|
173 | os.mkdir('current_run') |
---|
174 | |
---|
175 | if not os.path.exists('current_run/'+configName): |
---|
176 | os.mkdir('current_run/'+configName) |
---|
177 | os.system('mv -f param.def current_run/'+configName) |
---|
178 | os.system('mv -f all_param.def current_run/'+configName) |
---|
179 | os.system('mv -f user_param.py current_run/'+configName) |
---|
180 | os.system('mv -f iodef.xml current_run/'+configName) |
---|
181 | os.system('rm -f current_run/'+configName+'/context_atm.xml') |
---|
182 | os.system('cp -n context_atm.xml current_run/'+configName) |
---|
183 | os.system('cp -f context_grid_dynamico.xml current_run/'+configName) |
---|
184 | os.system('cp -f dynamico_grid.nc current_run/'+configName) |
---|
185 | os.system('mv -f xios_*.out current_run/'+configName) |
---|
186 | os.system('mv -f xios_*.err current_run/'+configName) |
---|
187 | |
---|
188 | |
---|
189 | if __name__== "__main__": |
---|
190 | main() |
---|