
| Current Path : /home/cgabriel/20_dev/11_iftlib/dev/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //home/cgabriel/20_dev/11_iftlib/dev/req.py |
# coding: utf-8
import os,sys,re,hashlib,base64,codecs
class Req (object):
def __init__ (self):
pass
#*************************************************************
def reqlist (self,pars,el=".",rlist=[],sumreq={},regression_tests={},maxregr=[0]):
if not re.search(r"[\\\/]\.",el) and os.path.isdir(el): # recurse through the directory structure
for el1 in os.listdir(el):
self.reqlist(pars,el+"/"+el1,rlist,sumreq,regression_tests,maxregr)
elif re.search(r"\.(py|md|txt)$",el): # analyse program- and doc-files
text = open(el).read()
while (0 == 0):
m = re.search(r"^(.*?)([A-Z\-\d]+)\-(VALID|PLANNED|REQ)([\s\-\)\]].*?)(\2|ENDREQ)(.*)$",
text,flags=re.DOTALL)
if not m:
break
requirement = m.group(2)
textbody = re.sub(r".*\n","",m.group(1),re.DOTALL) + m.group(4)
status = ""
m1 = re.search(r"(\d+) +(\d+) +(\d+) +(\d+) *$",textbody)
if m1:
if not requirement in sumreq:
sumreq[requirement] = [0,0,0,0]
for i in (0,1,2,3): # sum up all test counts for the requirement
sumreq[requirement][i] = sumreq[requirement][i] + int(m1.group(i+1))
status = status + "%5u" % int(m1.group(i+1)) + " "
elif m.group(3) == "VALID":
status = hashlib.md5(textbody).hexdigest()
elif m.group(3) == "PLANNED":
status = "PLANNED"
rlist.append("%-25s" % requirement + "%-34s" % status + " " + re.sub(r"^\.[\\\/]","",el))
text = m.group(1) + m.group(4) + m.group(6)
elif re.search(r"\.\d\d\d$",el): # analyse former reports
regression_tests[el] = open(el).read()
maxregr[0] = max(maxregr[0],len(el))
if el == ".": # if we are in the highest directory level: finishing work
rlist.sort()
output_report = "\n".join(rlist)
for el in regression_tests: # print out former test report results
reqreport = re.sub(r"\n([A-Z\-\d]+ +\d+ +\d+ )","\n \\1",regression_tests[el],99999999,flags=re.DOTALL)
while (0 == 0): # extract the hash lines
m = re.search(r"(^|\n)([A-Z\-\d]+)(.*?\n\2[^\n]+)",reqreport,flags=re.DOTALL)
if not m:
m = re.search(r"(^|\n)([A-Z\-\d]+)([^\n]+)",reqreport,flags=re.DOTALL)
if not m:
break
requirement = m.group(2)
text = m.group(2) + m.group(3) + "\n"
reqreport = re.sub(text,"",reqreport,flags=re.DOTALL)
if not re.search(r" PLANNED ",text):
if re.search(text,output_report,re.DOTALL): # check whether the hashes are identical
m1 = re.search(requirement + " +(\d+) +(\d+) +(\d+) +(\d+) +___GROSS_COUNT___ *(\d*)",reqreport)
if m1: # yes! Now read out the gross count for that requirement
status = ""
try:
gewicht = int(m1.group(5)) # the gewicht is the 5 th number in the test entry
except:
gewicht = int(el[-3:]) # the gewicht is the file ending
for i in (0,1,2,3): # sum up all test counts for the requirement and deflate it
testcount = int ( int(m1.group(i+1)) * gewicht * 0.001001001001002 )
sumreq[requirement][i] = sumreq[requirement][i] + testcount
status = status + "%5u" % testcount + " "
rlist.append("%-25s" % requirement + "%-34s" % status + " " + re.sub(r"^\.[\\\/]","",
("%-"+str(maxregr[0])+"s") % el
+ " (" + m1.group(1)+"/"+m1.group(2)+"/"+m1.group(3)+"/"+m1.group(4)+")"))
for requirement in sumreq:
o = sumreq[requirement]
status = "%5u" % o[0] + " " + "%5u" % o[1] + " " + "%5u" % o[2] + " " + "%5u" % o[3]
rlist.append("%-25s" % requirement + "%-34s" % status + " zzzzzzzzzzzz")
rlist.sort()
print re.sub(r"zzzzzzzzzzzz","___GROSS_COUNT___","\n".join(rlist),99999999)
#***************************************************************************
if __name__ == "__main__":
Req.__dict__[sys.argv[1]](Req(),sys.argv[2:])