[1708] | 1 | import os |
---|
| 2 | import sys |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | from user_param import * |
---|
| 6 | |
---|
| 7 | def main(): |
---|
[1720] | 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' |
---|
[1721] | 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' |
---|
[1708] | 25 | |
---|
[1712] | 26 | configNamePattern=[0]*7 |
---|
[1708] | 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 |
---|
[1712] | 43 | elif line.startswith("ATMdomain"): |
---|
| 44 | configNamePattern[5] = '_ATMdomain=' + ATMdomain |
---|
[1708] | 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) |
---|
[1720] | 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") |
---|
[1708] | 66 | |
---|
| 67 | os.mkdir(configName+'/setup') |
---|
| 68 | os.mkdir(configName+'/tmp_reference') |
---|
[1721] | 69 | os.mkdir(configName+'/xios_output') |
---|
[1708] | 70 | |
---|
| 71 | os.system('cp param.def '+configName+'/setup/') |
---|
[1713] | 72 | os.system('cp all_param.def '+configName+'/setup/') |
---|
[1708] | 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/') |
---|
[1721] | 77 | os.system('mv xios_*.out '+configName+'/xios_output/') |
---|
| 78 | os.system('mv xios_*.err '+configName+'/xios_output/') |
---|
[1708] | 79 | |
---|
| 80 | |
---|
[1714] | 81 | f=open("checkfile.def", "r") |
---|
| 82 | h=open("report.txt", "a+") |
---|
[1725] | 83 | l=open("report.html", "a+") |
---|
| 84 | h.write("Config : "+configName+"\n") |
---|
| 85 | l.write("<p>Config : "+configName+"</p>") |
---|
[1714] | 86 | for line in f: |
---|
| 87 | line=line.strip() |
---|
| 88 | line=line.rstrip() |
---|
| 89 | if not line.startswith("#") and len(line) != 0: |
---|
| 90 | cmd = 'cp -n '+line + ' '+configName+'/tmp_reference/' |
---|
| 91 | os.system(cmd) |
---|
| 92 | |
---|
[1725] | 93 | h.write("test for "+lpurple(line)+" \t"+yellow('INITIALIZED')+"\n") |
---|
| 94 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"darkorange\">INITIALIZED</font></p>") |
---|
[1720] | 95 | print yellow("\n ****************************************") |
---|
| 96 | print yellow(" ** "+line+" is stored as temporal reference !!! **") |
---|
| 97 | print yellow("\n ****************************************") |
---|
[1714] | 98 | |
---|
| 99 | f.close() |
---|
[1725] | 100 | h.write("\n") |
---|
| 101 | l.write("<br>") |
---|
[1714] | 102 | h.close() |
---|
| 103 | |
---|
| 104 | |
---|
[1708] | 105 | else: |
---|
[1720] | 106 | print blue("\n ********************************************************") |
---|
| 107 | print blue(" * Directory " + repr(configName) + " already exists") |
---|
| 108 | print blue(" * Start comparing results with (tmp) references") |
---|
| 109 | print blue(" ********************************************************\n") |
---|
[1708] | 110 | |
---|
| 111 | tmp_ref = os.path.isdir(configName+'/tmp_reference') |
---|
| 112 | ref = os.path.isdir(configName+'/reference') |
---|
| 113 | |
---|
| 114 | if ref: |
---|
[1720] | 115 | print blue("\n =====================================") |
---|
| 116 | print blue(" | Comparing results with references |") |
---|
| 117 | print blue(" =====================================\n") |
---|
[1708] | 118 | os.system('rm -rf '+configName+'/tmp_reference/') |
---|
| 119 | tmp_ref = False |
---|
| 120 | path = configName+'/reference/' |
---|
| 121 | elif tmp_ref: |
---|
[1720] | 122 | print blue("\n ===================================================") |
---|
| 123 | print blue(" | Comparing results with NON-Validated references |") |
---|
| 124 | print blue(" ===================================================\n") |
---|
[1708] | 125 | path = ' '+configName+'/tmp_reference/' |
---|
| 126 | |
---|
| 127 | f=open("checkfile.def", "r") |
---|
| 128 | h=open("report.txt", "a+") |
---|
[1723] | 129 | l=open("report.html", "a+") |
---|
[1708] | 130 | |
---|
[1714] | 131 | |
---|
[1725] | 132 | h.write("Config : "+configName+"\n") |
---|
| 133 | l.write("<p>Config : "+configName+"</p>") |
---|
[1708] | 134 | for line in f: |
---|
[1714] | 135 | |
---|
[1708] | 136 | line=line.strip() |
---|
| 137 | line=line.rstrip() |
---|
[1714] | 138 | |
---|
[1708] | 139 | if not line.startswith("#") and len(line) != 0: |
---|
| 140 | cmd = 'cdo diffn '+ line + path + line + ' | tail -1 > diff.txt' |
---|
| 141 | os.system(cmd) |
---|
| 142 | |
---|
[1719] | 143 | if os.stat("diff.txt").st_size==0: |
---|
[1725] | 144 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
| 145 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
[1720] | 146 | print green("\n ****************************************") |
---|
| 147 | print green(" ** "+line+" is valid !!! **") |
---|
| 148 | print green("\n ****************************************") |
---|
[1719] | 149 | |
---|
| 150 | else: |
---|
| 151 | g=open("diff.txt", "r") |
---|
| 152 | for gline in g: |
---|
| 153 | if gline.strip().startswith("0") or ":" in gline : |
---|
[1725] | 154 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
| 155 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
[1720] | 156 | print green("\n ****************************************") |
---|
| 157 | print green(" ** "+line+" is valid !!! **") |
---|
| 158 | print green("\n ****************************************") |
---|
[1719] | 159 | else: |
---|
[1725] | 160 | h.write("test for "+lpurple(line)+" \t"+red('FAILED')+"\n") |
---|
| 161 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"red\">FAILED</font></p>") |
---|
[1720] | 162 | print red("\n **************************************************") |
---|
| 163 | print red(" ** "+line+" is NOT valid. Please debugging.. **") |
---|
| 164 | print red("\n **************************************************") |
---|
[1719] | 165 | g.close() |
---|
[1708] | 166 | f.close() |
---|
[1725] | 167 | h.write("\n") |
---|
| 168 | l.write("<br>") |
---|
[1714] | 169 | h.close() |
---|
[1708] | 170 | |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | if __name__== "__main__": |
---|
[1718] | 175 | main() |
---|