[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' |
---|
| 20 | osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) |
---|
| 21 | theInfo = osstdout.communicate()[0].strip() |
---|
| 22 | if osstdout.returncode!=0: |
---|
| 23 | print(red(runthis+" FAILED")) |
---|
[1891] | 24 | print(theInfo) |
---|
[1888] | 25 | sys.exit() |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | def nonblank_lines(f): |
---|
| 30 | for l in f: |
---|
| 31 | line = l.rstrip() |
---|
| 32 | if line and not line.startswith("#"): |
---|
| 33 | yield line |
---|
| 34 | |
---|
| 35 | def main(): |
---|
[1909] | 36 | ref_list = glob.glob(ref_location+"/*") |
---|
| 37 | for i in range(len(ref_list)): |
---|
| 38 | tmp = ref_list[i].split("/") |
---|
| 39 | rev = tmp[len(tmp)-1] |
---|
| 40 | ref_list[i] = int(rev) |
---|
| 41 | ref_list.sort(reverse=True) #ref_list in descending order |
---|
| 42 | |
---|
[1910] | 43 | ref_rev = "" |
---|
[1909] | 44 | for ref in ref_list: |
---|
| 45 | if int(svnr) >= ref : |
---|
[1915] | 46 | ref_rev = str(ref) |
---|
| 47 | print("corresponding reference = ", ref) |
---|
[1909] | 48 | break |
---|
| 49 | |
---|
[1910] | 50 | if not ref_rev: |
---|
[1909] | 51 | print("no available reference found ... exit") |
---|
| 52 | return |
---|
| 53 | |
---|
| 54 | OSinfo("cp "+ref_location+"/"+ref_rev+"/"+ref_file+" ./") |
---|
| 55 | OSinfo("tar -zxvf "+ref_location+"/"+ref_rev+"/"+ref_file) |
---|
[1890] | 56 | OSinfo("rm -f "+ref_file) |
---|
[1909] | 57 | |
---|
| 58 | |
---|
[1888] | 59 | test_folder_list = glob.glob('test_*') |
---|
| 60 | |
---|
| 61 | for test_folder in test_folder_list: |
---|
| 62 | config_list = glob.glob(test_folder+"/CONFIG_*") |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | with open(test_folder+"/checkfile.def", "r") as fh: |
---|
| 66 | checkfiles = list(nonblank_lines(fh)) |
---|
| 67 | |
---|
| 68 | with open("report_"+svnr+"_"+arch+"_"+mode+".txt", "a") as report: |
---|
| 69 | for config in config_list: |
---|
| 70 | folder_name = list(config.split("/"))[0] |
---|
| 71 | config_name = list(config.split("/"))[1] |
---|
| 72 | for checkfile in checkfiles: |
---|
[1890] | 73 | if os.path.exists(config+"/"+checkfile) and os.path.exists("reference/ref_"+config+"/"+checkfile): |
---|
| 74 | OSinfo("cdo -W diffn "+config+"/"+checkfile+" "+"reference/ref_"+config+"/"+checkfile+" | > diff.txt") |
---|
[1888] | 75 | if os.stat("diff.txt").st_size==0: |
---|
| 76 | report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(1)+"\n") |
---|
| 77 | elif os.path.exists(config+"/"+checkfile): |
---|
| 78 | report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(0)+"\n") |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | if __name__== "__main__": |
---|
| 82 | main() |
---|