1 | import os |
---|
2 | import sys |
---|
3 | import subprocess |
---|
4 | |
---|
5 | |
---|
6 | from user_param import * |
---|
7 | |
---|
8 | |
---|
9 | def OSinfo(runthis): |
---|
10 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
11 | osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) |
---|
12 | theInfo = osstdout.communicate()[0].strip() |
---|
13 | if osstdout.returncode!=0: |
---|
14 | print(red(runthis+" FAILED")) |
---|
15 | print >> sys.stderr, osstdout.returncode |
---|
16 | sys.exit() |
---|
17 | # else: |
---|
18 | # print(runthis+" OK") |
---|
19 | |
---|
20 | |
---|
21 | def main(): |
---|
22 | |
---|
23 | black = lambda text: '\033[0;30m' + text + '\033[0m' |
---|
24 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
25 | green = lambda text: '\033[0;32m' + text + '\033[0m' |
---|
26 | yellow = lambda text: '\033[0;33m' + text + '\033[0m' |
---|
27 | blue = lambda text: '\033[0;34m' + text + '\033[0m' |
---|
28 | magenta = lambda text: '\033[0;35m' + text + '\033[0m' |
---|
29 | cyan = lambda text: '\033[0;36m' + text + '\033[0m' |
---|
30 | lgray = lambda text: '\033[0;37m' + text + '\033[0m' |
---|
31 | dgray = lambda text: '\033[1;30m' + text + '\033[0m' |
---|
32 | lred = lambda text: '\033[1;32m' + text + '\033[0m' |
---|
33 | lgreen = lambda text: '\033[1;32m' + text + '\033[0m' |
---|
34 | lyellow = lambda text: '\033[1;33m' + text + '\033[0m' |
---|
35 | lblue = lambda text: '\033[1;34m' + text + '\033[0m' |
---|
36 | lpurple = lambda text: '\033[1;35m' + text + '\033[0m' |
---|
37 | lcyan = lambda text: '\033[1;36m' + text + '\033[0m' |
---|
38 | white = lambda text: '\033[1;37m' + text + '\033[0m' |
---|
39 | |
---|
40 | configNamePattern=[0]*7 |
---|
41 | |
---|
42 | f=open("user_param.py", "r") |
---|
43 | for line in f: |
---|
44 | line = line.strip() |
---|
45 | if line.startswith("UsingServer2"): |
---|
46 | configNamePattern[0] = '_UsingSrv2=' + UsingServer2 |
---|
47 | elif line.startswith("RatioServer2"): |
---|
48 | configNamePattern[1] = '_RatioSrv2=' + repr(RatioServer2) |
---|
49 | elif line.startswith("NumberPoolsServer2"): |
---|
50 | configNamePattern[2] = '_NbPoolsSrv2=' + repr(NumberPoolsServer2) |
---|
51 | elif line.startswith("NumberClients"): |
---|
52 | configNamePattern[3] = '_NbClients=' + repr(NumberClients) |
---|
53 | elif line.startswith("NumberServers"): |
---|
54 | configNamePattern[4] = '_NbServers=' + repr(NumberServers) |
---|
55 | elif line.startswith("Duration"): |
---|
56 | configNamePattern[5] = '_Duration=' + Duration |
---|
57 | elif line.startswith("ATMdomain"): |
---|
58 | configNamePattern[5] = '_ATMdomain=' + ATMdomain |
---|
59 | f.close() |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | configName = "config" |
---|
64 | defaultConfig = True |
---|
65 | |
---|
66 | for i in range(len(configNamePattern)): |
---|
67 | if configNamePattern[i] != 0: |
---|
68 | configName = configName + configNamePattern[i] |
---|
69 | defaultConfig = False |
---|
70 | |
---|
71 | if defaultConfig: |
---|
72 | configName = "config_default" |
---|
73 | |
---|
74 | check_result=False |
---|
75 | |
---|
76 | |
---|
77 | if not os.path.exists(configName): |
---|
78 | os.mkdir(configName) |
---|
79 | print blue("\n ****************************************************************") |
---|
80 | print blue(" * Directory " + repr(configName) + " Created ") |
---|
81 | print blue(" * Copy results to \'not_validated_reference\' folder") |
---|
82 | print blue(" ****************************************************************\n") |
---|
83 | |
---|
84 | OSinfo("mkdir "+configName+'/setup') |
---|
85 | OSinfo('mkdir '+configName+'/tmp_reference') |
---|
86 | OSinfo('mkdir '+configName+'/xios_output') |
---|
87 | |
---|
88 | OSinfo('mv param.def '+configName+'/setup/') |
---|
89 | OSinfo('mv all_param.def '+configName+'/setup/') |
---|
90 | OSinfo('mv user_param.py '+configName+'/setup/') |
---|
91 | OSinfo('mv iodef.xml '+configName+'/setup/') |
---|
92 | OSinfo('cp context_atm.xml '+configName+'/setup/') |
---|
93 | OSinfo('cp context_grid_dynamico.xml '+configName+'/setup/') |
---|
94 | OSinfo('cp dynamico_grid.nc '+configName+'/setup/') |
---|
95 | OSinfo('mv xios_*.out '+configName+'/xios_output/') |
---|
96 | OSinfo('mv xios_*.err '+configName+'/xios_output/') |
---|
97 | |
---|
98 | |
---|
99 | f=open("checkfile.def", "r") |
---|
100 | h=open("report.txt", "a+") |
---|
101 | l=open("report.html", "a+") |
---|
102 | h.write("Config : "+configName+"\n") |
---|
103 | l.write("<p>Config : "+configName+"</p>") |
---|
104 | endloop=False |
---|
105 | for line in f: |
---|
106 | line=line.strip() |
---|
107 | line=line.rstrip() |
---|
108 | |
---|
109 | if line.startswith("all"): |
---|
110 | allfiles = os.listdir(os.getcwd()) |
---|
111 | for thisfile in allfiles: |
---|
112 | if thisfile.endswith(".nc") and thisfile!="dynamico_grid.nc": |
---|
113 | cmd = 'mv '+thisfile + ' '+configName+'/tmp_reference/' |
---|
114 | OSinfo(cmd) |
---|
115 | |
---|
116 | h.write("test for "+lpurple("all NC files")+" \t"+yellow('INITIALIZED')+"\n") |
---|
117 | l.write("<p>test for <font color=\"purple\">"+"all NC files"+"</font> <font color=\"darkorange\">INITIALIZED</font></p>") |
---|
118 | print yellow("\n ****************************************") |
---|
119 | print yellow(" ** "+"all NC files"+" is stored as temporal reference !!! **") |
---|
120 | print yellow("\n ****************************************") |
---|
121 | |
---|
122 | break |
---|
123 | |
---|
124 | if not line.startswith("#") and len(line) != 0: |
---|
125 | cmd = 'mv '+line + ' '+configName+'/tmp_reference/' |
---|
126 | OSinfo(cmd) |
---|
127 | |
---|
128 | h.write("test for "+lpurple(line)+" \t"+yellow('INITIALIZED')+"\n") |
---|
129 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"darkorange\">INITIALIZED</font></p>") |
---|
130 | print yellow("\n ****************************************") |
---|
131 | print yellow(" ** "+line+" is stored as temporal reference !!! **") |
---|
132 | print yellow("\n ****************************************") |
---|
133 | |
---|
134 | f.close() |
---|
135 | h.write("\n") |
---|
136 | l.write("<br>") |
---|
137 | h.close() |
---|
138 | |
---|
139 | |
---|
140 | else: |
---|
141 | print blue("\n ********************************************************") |
---|
142 | print blue(" * Directory " + repr(configName) + " already exists") |
---|
143 | print blue(" * Start comparing results with references") |
---|
144 | print blue(" ********************************************************\n") |
---|
145 | |
---|
146 | tmp_ref = os.path.isdir(configName+'/tmp_reference') |
---|
147 | ref = os.path.isdir(configName+'/reference') and not tmp_ref |
---|
148 | |
---|
149 | if ref: |
---|
150 | print blue("\n =====================================") |
---|
151 | print blue(" | Comparing results with references |") |
---|
152 | print blue(" =====================================\n") |
---|
153 | path = configName+'/reference/' |
---|
154 | elif tmp_ref: |
---|
155 | print blue("\n ===================================================") |
---|
156 | print blue(" | Comparing results with NON-Validated references |") |
---|
157 | print blue(" ===================================================\n") |
---|
158 | path = configName+'/tmp_reference/' |
---|
159 | |
---|
160 | f=open("checkfile.def", "r") |
---|
161 | h=open("report.txt", "a+") |
---|
162 | l=open("report.html", "a+") |
---|
163 | |
---|
164 | |
---|
165 | h.write("Config : "+configName+"\n") |
---|
166 | l.write("<p>Config : "+configName+"</p>") |
---|
167 | for line in f: |
---|
168 | |
---|
169 | line=line.strip() |
---|
170 | line=line.rstrip() |
---|
171 | |
---|
172 | if line.startswith("all") : |
---|
173 | for thisfile in os.listdir(path): |
---|
174 | if thisfile.endswith(".nc"): |
---|
175 | cmd = 'cdo -W diffn '+ thisfile +' '+ path + thisfile + ' | tail -1 > diff.txt' |
---|
176 | |
---|
177 | OSinfo(cmd) |
---|
178 | |
---|
179 | if os.stat("diff.txt").st_size==0: |
---|
180 | h.write("test for "+lpurple(thisfile)+" \t"+green('PASSED')+"\n") |
---|
181 | l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> <font color=\"green\">PASSED</font></p>") |
---|
182 | print green("\n ****************************************") |
---|
183 | print green(" ** "+thisfile+" is valid !!! **") |
---|
184 | print green("\n ****************************************") |
---|
185 | |
---|
186 | else: |
---|
187 | g=open("diff.txt", "r") |
---|
188 | for gline in g: |
---|
189 | if gline.strip().startswith("0") or ":" in gline : |
---|
190 | h.write("test for "+lpurple(thisfile)+" \t"+green('PASSED')+"\n") |
---|
191 | l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> <font color=\"green\">PASSED</font></p>") |
---|
192 | print green("\n ****************************************") |
---|
193 | print green(" ** "+thisfile+" is valid !!! **") |
---|
194 | print green("\n ****************************************") |
---|
195 | else: |
---|
196 | h.write("test for "+lpurple(thisfile)+" \t"+red('FAILED')+"\n") |
---|
197 | l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> <font color=\"red\">FAILED</font></p>") |
---|
198 | print red("\n **************************************************") |
---|
199 | print red(" ** "+thisfile+" is NOT valid. Please debugging.. **") |
---|
200 | print red("\n **************************************************") |
---|
201 | g.close() |
---|
202 | break |
---|
203 | |
---|
204 | |
---|
205 | elif not line.startswith("#") and len(line) != 0: |
---|
206 | cmd = 'cdo -W diffn '+ line +' '+ path + line + ' | tail -1 > diff.txt' |
---|
207 | |
---|
208 | OSinfo(cmd) |
---|
209 | |
---|
210 | if os.stat("diff.txt").st_size==0: |
---|
211 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
212 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
213 | print green("\n ****************************************") |
---|
214 | print green(" ** "+line+" is valid !!! **") |
---|
215 | print green("\n ****************************************") |
---|
216 | |
---|
217 | else: |
---|
218 | g=open("diff.txt", "r") |
---|
219 | for gline in g: |
---|
220 | if gline.strip().startswith("0") or ":" in gline : |
---|
221 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
222 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
223 | print green("\n ****************************************") |
---|
224 | print green(" ** "+line+" is valid !!! **") |
---|
225 | print green("\n ****************************************") |
---|
226 | else: |
---|
227 | h.write("test for "+lpurple(line)+" \t"+red('FAILED')+"\n") |
---|
228 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"red\">FAILED</font></p>") |
---|
229 | print red("\n **************************************************") |
---|
230 | print red(" ** "+line+" is NOT valid. Please debugging.. **") |
---|
231 | print red("\n **************************************************") |
---|
232 | g.close() |
---|
233 | f.close() |
---|
234 | h.write("\n") |
---|
235 | l.write("<br>") |
---|
236 | h.close() |
---|
237 | |
---|
238 | if not os.path.exists('current_run'): |
---|
239 | OSinfo('mkdir current_run') |
---|
240 | |
---|
241 | if not os.path.exists('current_run/'+configName): |
---|
242 | OSinfo('mkdir current_run/'+configName) |
---|
243 | |
---|
244 | OSinfo('mv -f param.def current_run/'+configName) |
---|
245 | OSinfo('mv -f all_param.def current_run/'+configName) |
---|
246 | OSinfo('mv -f user_param.py current_run/'+configName) |
---|
247 | OSinfo('mv -f iodef.xml current_run/'+configName) |
---|
248 | OSinfo('rm -f current_run/'+configName+'/context_atm.xml') |
---|
249 | OSinfo('cp -n context_atm.xml current_run/'+configName) |
---|
250 | OSinfo('cp -f context_grid_dynamico.xml current_run/'+configName) |
---|
251 | OSinfo('cp -f dynamico_grid.nc current_run/'+configName) |
---|
252 | OSinfo('mv -f xios_*.out current_run/'+configName) |
---|
253 | OSinfo('mv -f xios_*.err current_run/'+configName) |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | |
---|
258 | if __name__== "__main__": |
---|
259 | main() |
---|