[1708] | 1 | import os |
---|
| 2 | import sys |
---|
[1734] | 3 | import subprocess |
---|
[1738] | 4 | import socket |
---|
| 5 | import os.path |
---|
| 6 | from os import path |
---|
[1708] | 7 | |
---|
| 8 | |
---|
[1838] | 9 | # from default_param import * |
---|
| 10 | # from user_param import * |
---|
| 11 | from param_list import * |
---|
[1771] | 12 | |
---|
[1738] | 13 | # load default_param first, variables defines in user_param will overwrite the default value |
---|
[1708] | 14 | |
---|
[1734] | 15 | |
---|
[1738] | 16 | |
---|
[1734] | 17 | def OSinfo(runthis): |
---|
[1737] | 18 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
[1734] | 19 | osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) |
---|
| 20 | theInfo = osstdout.communicate()[0].strip() |
---|
| 21 | if osstdout.returncode!=0: |
---|
[1737] | 22 | print(red(runthis+" FAILED")) |
---|
[1734] | 23 | print >> sys.stderr, osstdout.returncode |
---|
| 24 | sys.exit() |
---|
[1737] | 25 | # else: |
---|
| 26 | # print(runthis+" OK") |
---|
[1734] | 27 | |
---|
| 28 | |
---|
[1738] | 29 | |
---|
[1838] | 30 | blue = lambda text: '\033[0;34m' + text + '\033[0m' |
---|
| 31 | yellow = lambda text: '\033[0;33m' + text + '\033[0m' |
---|
| 32 | green = lambda text: '\033[0;32m' + text + '\033[0m' |
---|
| 33 | # blue = lambda text: text |
---|
| 34 | # yellow = lambda text: text |
---|
| 35 | # green = lambda text: text |
---|
[1738] | 36 | |
---|
[1708] | 37 | def main(): |
---|
[1720] | 38 | |
---|
[1838] | 39 | defaultConfig = True |
---|
| 40 | configNamePattern=[] |
---|
| 41 | for i in range(len(param_list)): |
---|
| 42 | f=open("user_param.py", "r") |
---|
| 43 | for line in f: |
---|
| 44 | line = line.strip().replace(" ","") |
---|
| 45 | if line.startswith(param_list[i]): |
---|
| 46 | configNamePattern.append('_'+param_short_list[i]+"="+line.split("=")[1].replace("'","")) |
---|
| 47 | defaultConfig = False |
---|
[1708] | 48 | |
---|
[1838] | 49 | f.close() |
---|
| 50 | |
---|
| 51 | configName = "config" |
---|
| 52 | |
---|
| 53 | for i in range(len(configNamePattern)): |
---|
| 54 | configName = configName+configNamePattern[i] |
---|
[1708] | 55 | |
---|
[1838] | 56 | checkfile = "checkfile.def" |
---|
| 57 | |
---|
| 58 | f=open(checkfile, "r") |
---|
[1708] | 59 | for line in f: |
---|
| 60 | line = line.strip() |
---|
[1838] | 61 | line = line.rstrip() |
---|
| 62 | if line.startswith("all"): |
---|
| 63 | allfiles = os.listdir(os.getcwd()) |
---|
| 64 | g=open("checkfile_new.def", "w") |
---|
| 65 | for thisfile in allfiles: |
---|
| 66 | if thisfile.endswith(".nc") and thisfile != "dynamico_grid.nc": |
---|
| 67 | g.write(thisfile+"\n") |
---|
| 68 | checkfile = "checkfile_new.def" |
---|
| 69 | g.close() |
---|
| 70 | break |
---|
[1708] | 71 | f.close() |
---|
[1737] | 72 | |
---|
[1838] | 73 | if not os.path.exists(configName): |
---|
| 74 | OSinfo("mkdir -p "+configName) |
---|
[1708] | 75 | |
---|
[1838] | 76 | print(blue("\n ****************************************************************")) |
---|
| 77 | print(blue(" * Directory " + repr(configName) + " Created ")) |
---|
| 78 | print(blue(" * Copy results to \'not_validated_reference\' folder")) |
---|
| 79 | print(blue(" ****************************************************************\n")) |
---|
[1708] | 80 | |
---|
[1838] | 81 | OSinfo("mkdir -p "+configName+"/setup") |
---|
| 82 | OSinfo("mkdir -p "+configName+"/tmp_reference") |
---|
[1708] | 83 | |
---|
[1838] | 84 | OSinfo("cp user_param.py user_param.def") |
---|
| 85 | OSinfo("cp user_param.py "+configName+"/setup") |
---|
| 86 | OSinfo("mv user_param.def "+configName+"/setup") |
---|
[1708] | 87 | |
---|
[1838] | 88 | OSinfo("cp default_param.json "+configName+"/setup") |
---|
[1771] | 89 | |
---|
[1838] | 90 | OSinfo("mv all_param.def "+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/") |
---|
[1771] | 94 | |
---|
[1708] | 95 | |
---|
[1838] | 96 | f=open(checkfile, "r") |
---|
| 97 | reportfile = open("../plain_report.txt", "a+") |
---|
[1714] | 98 | for line in f: |
---|
[1838] | 99 | line = line.strip() |
---|
| 100 | line = line.rstrip() |
---|
[1714] | 101 | if not line.startswith("#") and len(line) != 0: |
---|
[1838] | 102 | OSinfo("cp "+line+" "+configName+"/tmp_reference") |
---|
| 103 | reportfile.write(os.path.basename(os.getcwd())+" "+os.path.basename(os.getcwd())[5:]+"@"+configName+" "+os.path.basename(os.getcwd())[5:]+"@"+configName[7:]+"@"+line+" "+repr(0)+" \n") |
---|
| 104 | print(yellow("\n ****************************************")) |
---|
| 105 | print(yellow(" ** "+line+" is stored as temporal reference !!! **")) |
---|
| 106 | print(yellow("\n ****************************************")) |
---|
[1714] | 107 | f.close() |
---|
[1838] | 108 | reportfile.close() |
---|
[1714] | 109 | |
---|
[1838] | 110 | else: |
---|
| 111 | print(blue("\n ****************************************************************")) |
---|
| 112 | print(blue(" * Directory " + repr(configName) + " already exists ")) |
---|
[1714] | 113 | |
---|
[1708] | 114 | tmp_ref = os.path.isdir(configName+'/tmp_reference') |
---|
[1734] | 115 | ref = os.path.isdir(configName+'/reference') and not tmp_ref |
---|
[1708] | 116 | |
---|
[1838] | 117 | if tmp_ref : |
---|
| 118 | print(blue(" * Start comparing results with NON-validated references")) |
---|
| 119 | path = configName+"/tmp_reference" |
---|
| 120 | if ref : |
---|
| 121 | print(blue(" * Start comparing results with validated references")) |
---|
| 122 | path = configName+"reference" |
---|
| 123 | |
---|
| 124 | OSinfo('cp '+configName+'/setup/user_param.py '+configName+'/setup/user_param.def ') |
---|
| 125 | print(blue(" ****************************************************************\n")) |
---|
[1708] | 126 | |
---|
[1838] | 127 | f=open(checkfile, "r") |
---|
| 128 | reportfile = open("../plain_report.txt", "a+") |
---|
[1708] | 129 | for line in f: |
---|
[1838] | 130 | line = line.strip() |
---|
| 131 | line = line.rstrip() |
---|
| 132 | if not line.startswith("#") and len(line) != 0: |
---|
[1839] | 133 | OSinfo("cdo -W diffn "+line+" "+path+line+" | > diff.txt") |
---|
| 134 | # this command should change according to cdo version |
---|
[1714] | 135 | |
---|
[1719] | 136 | if os.stat("diff.txt").st_size==0: |
---|
[1838] | 137 | reportfile.write(os.path.basename(os.getcwd())+" "+os.path.basename(os.getcwd())[5:]+"@"+configName+" "+os.path.basename(os.getcwd())[5:]+"@"+configName[7:]+"@"+line+" "+repr(1)+" \n") |
---|
| 138 | print(green("\n ****************************************")) |
---|
| 139 | print(green(" ** "+line+" is valid !!! **")) |
---|
| 140 | print(green("\n ****************************************")) |
---|
| 141 | else: |
---|
[1719] | 142 | g=open("diff.txt", "r") |
---|
| 143 | for gline in g: |
---|
[1838] | 144 | if gline.strip().startswith("0") or ":" in gline: |
---|
| 145 | reportfile.write(os.path.basename(os.getcwd())+" "+os.path.basename(os.getcwd())[5:]+"@"+configName+" "+os.path.basename(os.getcwd())[5:]+"@"+configName[7:]+"@"+line+" "+repr(1)+" \n") |
---|
| 146 | print(green("\n ****************************************")) |
---|
| 147 | print(green(" ** "+line+" is valid !!! **")) |
---|
| 148 | print(green("\n ****************************************")) |
---|
[1719] | 149 | else: |
---|
[1838] | 150 | reportfile.write(os.path.basename(os.getcwd())+" "+os.path.basename(os.getcwd())[5:]+"@"+configName+" "+os.path.basename(os.getcwd())[5:]+"@"+configName[7:]+"@"+line+" "+repr(-1)+" \n") |
---|
| 151 | print(green("\n ****************************************")) |
---|
| 152 | print(green(" ** "+line+" is NOT valid. Please debugging.. **")) |
---|
| 153 | print(green("\n ****************************************")) |
---|
[1719] | 154 | g.close() |
---|
[1708] | 155 | f.close() |
---|
[1838] | 156 | reportfile.close() |
---|
[1708] | 157 | |
---|
[1838] | 158 | if os.path.exists("checkfile_new.def"): |
---|
| 159 | OSinfo("rm -f checkfile_new.def") |
---|
[1708] | 160 | |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | if __name__== "__main__": |
---|
[1718] | 164 | main() |
---|