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('cp param.def '+configName+'/setup/') |
---|
72 | os.system('cp all_param.def '+configName+'/setup/') |
---|
73 | os.system('cp iodef.xml '+configName+'/setup/') |
---|
74 | os.system('cp context_atm.xml '+configName+'/setup/') |
---|
75 | os.system('cp context_grid_dynamico.xml '+configName+'/setup/') |
---|
76 | os.system('cp dynamico_grid.nc '+configName+'/setup/') |
---|
77 | os.system('mv xios_*.out '+configName+'/xios_output/') |
---|
78 | os.system('mv xios_*.err '+configName+'/xios_output/') |
---|
79 | |
---|
80 | |
---|
81 | f=open("checkfile.def", "r") |
---|
82 | h=open("report.txt", "a+") |
---|
83 | for line in f: |
---|
84 | line=line.strip() |
---|
85 | line=line.rstrip() |
---|
86 | if not line.startswith("#") and len(line) != 0: |
---|
87 | cmd = 'cp -n '+line + ' '+configName+'/tmp_reference/' |
---|
88 | os.system(cmd) |
---|
89 | |
---|
90 | h.write("test for "+configName+" for file "+lpurple(line)+" \t"+yellow('INITIALIZED')+"\n") |
---|
91 | print yellow("\n ****************************************") |
---|
92 | print yellow(" ** "+line+" is stored as temporal reference !!! **") |
---|
93 | print yellow("\n ****************************************") |
---|
94 | |
---|
95 | f.close() |
---|
96 | h.close() |
---|
97 | |
---|
98 | |
---|
99 | else: |
---|
100 | print blue("\n ********************************************************") |
---|
101 | print blue(" * Directory " + repr(configName) + " already exists") |
---|
102 | print blue(" * Start comparing results with (tmp) references") |
---|
103 | print blue(" ********************************************************\n") |
---|
104 | |
---|
105 | tmp_ref = os.path.isdir(configName+'/tmp_reference') |
---|
106 | ref = os.path.isdir(configName+'/reference') |
---|
107 | |
---|
108 | if ref: |
---|
109 | print blue("\n =====================================") |
---|
110 | print blue(" | Comparing results with references |") |
---|
111 | print blue(" =====================================\n") |
---|
112 | os.system('rm -rf '+configName+'/tmp_reference/') |
---|
113 | tmp_ref = False |
---|
114 | path = configName+'/reference/' |
---|
115 | elif tmp_ref: |
---|
116 | print blue("\n ===================================================") |
---|
117 | print blue(" | Comparing results with NON-Validated references |") |
---|
118 | print blue(" ===================================================\n") |
---|
119 | path = ' '+configName+'/tmp_reference/' |
---|
120 | |
---|
121 | f=open("checkfile.def", "r") |
---|
122 | h=open("report.txt", "a+") |
---|
123 | |
---|
124 | |
---|
125 | for line in f: |
---|
126 | |
---|
127 | line=line.strip() |
---|
128 | line=line.rstrip() |
---|
129 | |
---|
130 | if not line.startswith("#") and len(line) != 0: |
---|
131 | cmd = 'cdo diffn '+ line + path + line + ' | tail -1 > diff.txt' |
---|
132 | os.system(cmd) |
---|
133 | |
---|
134 | if os.stat("diff.txt").st_size==0: |
---|
135 | h.write("test for "+configName+" for file "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
136 | print green("\n ****************************************") |
---|
137 | print green(" ** "+line+" is valid !!! **") |
---|
138 | print green("\n ****************************************") |
---|
139 | |
---|
140 | else: |
---|
141 | g=open("diff.txt", "r") |
---|
142 | for gline in g: |
---|
143 | if gline.strip().startswith("0") or ":" in gline : |
---|
144 | h.write("test for "+configName+" for file "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
145 | print green("\n ****************************************") |
---|
146 | print green(" ** "+line+" is valid !!! **") |
---|
147 | print green("\n ****************************************") |
---|
148 | else: |
---|
149 | h.write("test for "+configName+" for file "+lpurple(line)+" \t"+red('FAILED')+"\n") |
---|
150 | print red("\n **************************************************") |
---|
151 | print red(" ** "+line+" is NOT valid. Please debugging.. **") |
---|
152 | print red("\n **************************************************") |
---|
153 | g.close() |
---|
154 | f.close() |
---|
155 | h.close() |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | if __name__== "__main__": |
---|
161 | main() |
---|