[1888] | 1 | import glob |
---|
| 2 | import sys |
---|
| 3 | import subprocess |
---|
| 4 | import os |
---|
| 5 | import json |
---|
| 6 | import itertools |
---|
| 7 | import copy |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | mode=os.getenv("mode") |
---|
| 11 | arch=os.getenv("arch") |
---|
| 12 | svnr=os.getenv("svnR") |
---|
[1890] | 13 | ref_location=os.getenv("ref_location") |
---|
| 14 | ref_file=os.getenv("ref_file") |
---|
[1888] | 15 | |
---|
[1909] | 16 | |
---|
| 17 | |
---|
[1888] | 18 | def OSinfo(runthis): |
---|
| 19 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
[2139] | 20 | osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) |
---|
| 21 | theInfo, theErr = osstdout.communicate() |
---|
| 22 | #print(theInfo) |
---|
| 23 | if theErr: |
---|
[1888] | 24 | print(red(runthis+" FAILED")) |
---|
[2139] | 25 | print(theErr) |
---|
[1888] | 26 | sys.exit() |
---|
| 27 | |
---|
[2139] | 28 | #def OSinfo(runthis): |
---|
| 29 | # red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
| 30 | # osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) |
---|
| 31 | # theInfo = osstdout.communicate()[0].strip() |
---|
| 32 | # if osstdout.returncode!=0: |
---|
| 33 | # print(red(runthis+" FAILED")) |
---|
| 34 | # print(theInfo) |
---|
| 35 | # sys.exit() |
---|
[1888] | 36 | |
---|
| 37 | |
---|
[2139] | 38 | |
---|
[1888] | 39 | def nonblank_lines(f): |
---|
| 40 | for l in f: |
---|
| 41 | line = l.rstrip() |
---|
| 42 | if line and not line.startswith("#"): |
---|
| 43 | yield line |
---|
| 44 | |
---|
| 45 | def main(): |
---|
[1909] | 46 | ref_list = glob.glob(ref_location+"/*") |
---|
| 47 | for i in range(len(ref_list)): |
---|
| 48 | tmp = ref_list[i].split("/") |
---|
| 49 | rev = tmp[len(tmp)-1] |
---|
| 50 | ref_list[i] = int(rev) |
---|
| 51 | ref_list.sort(reverse=True) #ref_list in descending order |
---|
| 52 | |
---|
[1910] | 53 | ref_rev = "" |
---|
[1909] | 54 | for ref in ref_list: |
---|
| 55 | if int(svnr) >= ref : |
---|
[1915] | 56 | ref_rev = str(ref) |
---|
| 57 | print("corresponding reference = ", ref) |
---|
[1909] | 58 | break |
---|
| 59 | |
---|
[1910] | 60 | if not ref_rev: |
---|
[1909] | 61 | print("no available reference found ... exit") |
---|
| 62 | return |
---|
| 63 | |
---|
| 64 | OSinfo("cp "+ref_location+"/"+ref_rev+"/"+ref_file+" ./") |
---|
| 65 | OSinfo("tar -zxvf "+ref_location+"/"+ref_rev+"/"+ref_file) |
---|
[1890] | 66 | OSinfo("rm -f "+ref_file) |
---|
[1909] | 67 | |
---|
| 68 | |
---|
[1888] | 69 | test_folder_list = glob.glob('test_*') |
---|
| 70 | |
---|
| 71 | for test_folder in test_folder_list: |
---|
| 72 | config_list = glob.glob(test_folder+"/CONFIG_*") |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | with open(test_folder+"/checkfile.def", "r") as fh: |
---|
| 76 | checkfiles = list(nonblank_lines(fh)) |
---|
| 77 | |
---|
| 78 | with open("report_"+svnr+"_"+arch+"_"+mode+".txt", "a") as report: |
---|
| 79 | for config in config_list: |
---|
| 80 | folder_name = list(config.split("/"))[0] |
---|
| 81 | config_name = list(config.split("/"))[1] |
---|
| 82 | for checkfile in checkfiles: |
---|
[1890] | 83 | if os.path.exists(config+"/"+checkfile) and os.path.exists("reference/ref_"+config+"/"+checkfile): |
---|
[2173] | 84 | OSinfo("cdo -W diffn "+config+"/"+checkfile+" "+"reference/ref_"+config+"/"+checkfile+" 2>&1 |grep -v 'Found more than one time variable'|grep -v 'cdo diffn: Processed'|grep -v 'Time variable >time_counter< not found!' > diff_"+checkfile+".txt") |
---|
[2139] | 85 | if os.stat("diff_"+checkfile+".txt").st_size==0: # if no diff -> set 0 |
---|
[1888] | 86 | report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(1)+"\n") |
---|
[2139] | 87 | else: # if cdo diffn returns diff -> set -1 |
---|
| 88 | report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(-1)+"\n") |
---|
| 89 | |
---|
| 90 | elif os.path.exists(config+"/"+checkfile): # if no ref file -> set 0 |
---|
[1888] | 91 | report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(0)+"\n") |
---|
[2139] | 92 | elif os.path.exists("reference/ref_"+config+"/"+checkfile): # if no output file -> set -2 |
---|
| 93 | report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(-2)+"\n") |
---|
| 94 | |
---|
[1888] | 95 | |
---|
| 96 | |
---|
| 97 | if __name__== "__main__": |
---|
| 98 | main() |
---|