(root)/
libredwg-0.13/
test/
xmlsuite/
check.py
       1  #!/usr/bin/env python
       2  # -*- indent-tabs-mode:1 tab-width:4 mode:python minor-mode:whitespace -*-
       3  import os
       4  import sys
       5  
       6  # Divide the scripts into two files
       7  srcdir = os.path.dirname(__file__)
       8  sys.path.append(os.getcwd())
       9  # sys.path.append(srcdir)
      10  from helper import *
      11  
      12  # path where DWG files are present
      13  path_to_dwg = srcdir + "/../test-data"
      14  # The name of the output files folder
      15  outdir = "test_output"
      16  
      17  # Get all the directories
      18  dirs = [d for d in os.listdir(path_to_dwg)
      19  	if os.path.isdir(os.path.join(path_to_dwg, d)) and
      20  		(d[0] == 'r' or (d.isdigit and int(d) >= 2000 and int(d) <= 2021))]
      21  
      22  for dir in dirs:
      23  	for file in os.listdir(os.path.join(path_to_dwg, dir)):
      24  		if file.endswith(".dwg"):
      25  			# First thing will be to make duplicate directory structure
      26  			if not os.path.exists(outdir + "/" + dir):
      27  				os.makedirs(outdir + "/" + dir)
      28  			pass
      29  
      30  # generate xml from txt files
      31  generatexml(path_to_dwg)
      32  
      33  # Now execute testsuite.c on all the DWG files found and create a separate directory structure
      34  for dir in dirs:
      35  	for file in os.listdir(os.path.join(path_to_dwg, dir)):
      36  		if file.endswith(".dwg"):
      37  			# filename of the XML File
      38  			dwg_xmlfile = file.rsplit(".", 1)[0] + ".xml"
      39  			if os.path.exists(path_to_dwg + "/" + dir + "/" + dwg_xmlfile):
      40  				# Start running testsuite on every DWG file
      41  				os.system("./testsuite " + path_to_dwg + "/"
      42  						  + dir + "/" + file + " " + outdir
      43  						  + "/" + dir + "/" + dwg_xmlfile + " 2> /dev/null")
      44  		pass
      45  
      46  # Now we have XML file. Next Up is Comparison
      47  final_output = []
      48  for dir in dirs:
      49  	for file in os.listdir(os.path.join(path_to_dwg, dir)):
      50  		if file.endswith(".xml"):
      51  
      52  			# Duplicate file has same directory structure
      53  			if os.path.exists(outdir + "/" + dir + "/" + file):
      54  				result = xmlprocess(path_to_dwg+ "/" + dir + "/" + file,
      55  									outdir + "/" + dir + "/" + file)
      56  			else:
      57  				result = [0, []]
      58  
      59  			final_output.insert(len(final_output),
      60  								[dir, file,result[0], result[1]])
      61  
      62  
      63  # Now Generate a pretty report for it
      64  
      65  #read the header
      66  header = open(srcdir + "/header.htm","r")
      67  reporthtm = open("result.htm", "w")
      68  reporthtm.write(header.read())
      69  current_format = ""
      70  for report in final_output:
      71  	if current_format != report[0]:
      72  		# Print the header of the File Format
      73  		reporthtm.write(
      74  			"\n<div class='heading'>\n<h3>Output for %s File Format</h3>\n</div>"
      75  			% report[0])
      76  		print (bcolors.HEADER + "\n\n****Output for %s File Format****"
      77  			   % report[0] + bcolors.ENDC)
      78  
      79  	if report[2] < 100 and report[2] != 0:
      80  		print (bcolors.OKGREEN + "%s: [%d]"
      81  			   % (report[1], report[2]) + bcolors.ENDC)
      82  		reporthtm.write("\n<div class='result_middle'><b>%s</b> matched <b>%d</b>%%</div>\n"
      83  						% (report[1], report[2]))
      84  	elif report[2] == 0:
      85  		print (bcolors.WARNING + "%s: [%d]"
      86  			   % (report[1], report[2]) + bcolors.ENDC)
      87  		reporthtm.write("\n<div class='result_bad'>%s was not read at all</div>\n"
      88  						% report[1])
      89  	reporthtm.write("\n<div class='attributedetail'><h3>Attribute Details</h3>\n")
      90  	for unmatched in report[3]:
      91  		if unmatched['duplicate'] == "":
      92  			reporthtm.write("\n<p><b>%s</b> wasn't found at all. Its value should be <b>%s</b></p>\n"
      93  							% (unmatched['attrname'], unmatched['original']))
      94  		else:
      95  			reporthtm.write("\n<p><b>%s</b> didn't match. Its value should be <b>%s</b>, and it is <b>%s</b></p>\n"
      96  							%(unmatched['attrname'],
      97  							  unmatched["original"], unmatched['duplicate']))
      98  	reporthtm.write("</div>")
      99  	current_format = report[0]
     100  
     101  # All information has been printed. Print the footer
     102  print (bcolors.HEADER + "****End of Report****" + bcolors.ENDC)
     103  reporthtm.write("<div><h1>End of Report</h1></div></body></html>");
     104  reporthtm.close()